2015-10-13 275 views
0

我在dotVVM框架中遇到了Owin身份验证问题。授权页面上出现401错误需要进行身份验证。DotVVM身份验证

这是我目前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 { } 

我创建的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"); 
} 
+0

DotVVM并没有做任何特殊的魔术,这个问题可能会在使用Asp.Net Identity。尝试检查'context.OwinContext.Request.User!= null && context.OwinContext.Request.User.Identity.IsAuthenticated'是否为true。 DotVVM没有做更多 - https://github.com/riganti/dotvvm/blob/master/src/DotVVM.Framework/Runtime/Filters/AuthorizeAttribute.cs#L54 – exyi

回答

3

在OWIN的登记的顺序很重要。 app.UseCookieAuthentication应该是第一个注册的中间件。

+0

谢谢,这有助于 –