asp.net – 没有配置验证处理程序来处理方案:自动
发布时间:2020-05-23 15:35:01 所属栏目:asp.Net 来源:互联网
导读:我更新了ASP.NET 5框架beta-8包与RC在以前工作的应用程序。在我运行下一个错误发生在启动过程中: InvalidOperationException: No authentication handler is configured to handle the scheme: Automatic Microsoft.AspNet.Http.Authentication.Internal.
|
我更新了ASP.NET 5框架beta-8包与RC在以前工作的应用程序。在我运行下一个错误发生在启动过程中:
var defaultPolicy =
new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
services.AddMvc(setup =>
{
setup.Filters.Add(new AuthorizeFilter(defaultPolicy)); // Error occurs here
});
如果有人遇到类似的问题,我会感谢您的想法或解决方案可能出错了。此异常的解释也是值得赞赏的。 Startup.cs using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.PlatformAbstractions;
using SuperUserMVC.Configuration;
using SuperUserMVC.Extensions;
using SuperUserMVC.GlobalModules;
using System;
namespace SuperUserMVC
{
public class Startup
{
public IConfigurationRoot Configuration { get; set; }
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
public Startup(IHostingEnvironment env,IApplicationEnvironment appEnv)
{
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettingsBase>(Configuration.GetSection("AppSettingsBase"));
services.Configure<ConnectionString>(Configuration.GetSection("ConnectionString"));
services.AddSqlServerCache(cache =>
{
cache.ConnectionString = Configuration.Get<string>("ASPState:ConnectionString");
cache.SchemaName = Configuration.Get<string>("ASPState:Schema");
cache.TableName = Configuration.Get<string>("ASPState:Table");
});
services.AddSession(session =>
{
session.IdleTimeout = TimeSpan.FromMinutes(120);
});
// Only allow authenticated users.
var defaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
// Add MVC services to the services container.
services.AddMvc(setup =>
{
setup.Filters.Add(new AuthorizeFilter(defaultPolicy));
});
var builder = new ContainerBuilder();
builder.RegisterModule(new AutofacModule());
builder.Populate(services);
var container = builder.Build();
return container.Resolve<IServiceProvider>();
}
public void Configure(IApplicationBuilder app,IHttpContextAccessor httpContextAccessor)
{
// Catch unhandled exception in pipeline.
bool isProductionEnvironment = Configuration.Get<bool>("environmentVariables:isProductionEnvironment");
app.UseCustomUnhandledException(isProductionEnvironment,Configuration.Get<string>("defaultErrorPagePath"));
// Log requests.
app.UseVisitLogger(isProductionEnvironment);
// Session must be used before MVC routes.
app.UseSession();
// Configure the HTTP request pipeline.
app.UseCookieAuthentication(options =>
{
options.AuthenticationScheme = "Cookies";
options.LoginPath = new PathString("/Account/Login/");
options.AccessDeniedPath = new PathString("/Account/Forbidden/");
options.CookieName = "MyCookie";
options.AutomaticAuthenticate = true;
options.SessionStore = new MemoryCacheSessionStore();
});
AutoMapperInitializer.Init();
app.UseStaticFiles();
// Route configuration.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "AreaDefault",template: "{area:exists=Demo}/{controller=Home}/{action=Index}/{id?}"
);
routes.MapRoute(
name: "Default",template: "{controller=Home}/{action=Index}/{id?}"
);
});
}
}
}
解决方法尝试设置选项.AutomaticChallenge = true;在你的cookies选项,它应该工作。options.AutomaticAuthentication被分为options.AutomaticAuthenticate和options.AutomaticChallenge。如果最后一个值为false,则抛出异常,因为没有验证中间件处理授权过滤器应用的挑战。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 获取Web层之外的当前Principal
- asp.net – 如何在生产.NET网站中更改Web引用?
- ASP.NET/IIS中使用的非标准HTTP动词“DEBUG”是什么?
- asp.net – 如何尊重“从无Cookie域中提供静态内容”IIS6中
- ASP.Net在页面中的页面/控件上调用Dispose,还是必须这样做?
- asp.net – 在日期字段中插入空值?
- asp.net-mvc-3 – 在“@”字符后面出现意外的“foreach”关
- .net – 传递的主键值的数量必须与实体上定义的主键值的数量
- asp.net-mvc – ASP.Net MVC 5 w /身份2.2.0注销不工作
- asp.net – Service Fabric中的.NET Core RC2
推荐文章
站长推荐
热点阅读
