在dotVVM框架中,我遇到了一个关于Owin身份验证的问题。我得到401错误授权后,在页面上,需要认证。
这是我现在的startup.cs
var applicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
// use DotVVM
DotvvmConfiguration dotvvmConfiguration = app.UseDotVVM(applicationPhysicalPath);
dotvvmConfiguration.RouteTable.Add("Login", "", "Views/login.dothtml", null);
dotvvmConfiguration.RouteTable.Add("Home", "Home", "Views/home.dothtml", null);
dotvvmConfiguration.RouteTable.Add("Register", "Register", "Views/register.dothtml", null);
// use static files
app.UseStaticFiles(new StaticFileOptions()
{
FileSystem = new PhysicalFileSystem(applicationPhysicalPath)
});
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
});HomeViewModel.cs
[Authorize]
public class HomeViewModel : DotvvmViewModelBase { }我用这种方式创造了Auth Cookie
public void Login()
{
var identity = LoginHelper.GetIdentity(Email, DataAccess.DbAccess.CreateHash(Password));
if (identity == null)
return;
Context.OwinContext.Authentication.SignIn(new ClaimsIdentity(identity));
Context.Redirect("Home");
}发布于 2015-10-15 16:48:54
登记的顺序是很重要的。app.UseCookieAuthentication应该是第一个注册的中间件。
https://stackoverflow.com/questions/33108305
复制相似问题