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");
}
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