【发布时间】:2016-08-16 06:57:56
【问题描述】:
这是一个非常烦人的问题,我在我的asp.net核心项目上设置cookies认证,有时会出现这个错误,有时不会!
没有模式!它只是开始抛出错误并突然停止,然后重新开始......
例外是:
InvalidOperationException:未配置身份验证处理程序 处理方案:MyAuthScheme
这真的很烦人! 这是我的 Startup.cs
public class Startup
{
public const string AuthenticationSchemeName = "MyAuthScheme";
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor httpContextAccessor)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = AuthenticationSchemeName,
LoginPath = new PathString("/login"),
AutomaticAuthenticate = true,
AutomaticChallenge = true,
SlidingExpiration = true,
});
app.UseStaticFiles();
app.UseMvc();
}
}
这是我的验证码:
await HttpContext.Authentication.SignInAsync(Startup.AuthenticationSchemeName, new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookie")));
有什么帮助吗?
【问题讨论】:
-
您能简单地将常量 AuthenticationSchemeName 更改为字符串文字吗?所以: AuthenticationScheme = "CookieAuth" (并在您的身份验证代码中执行相同操作)。告诉我它是否再次发生。
-
有你使用的地方
MyAuthScheme吗? -
丹尼也一样...
-
抱歉,我在更新 AuthenticationSchemeName 的值之前复制了错误消息...我编辑了问题以反映我当前的代码。
标签: c# asp.net asp.net-core