0

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

1 に答える 1

3

OWIN での登録の順序は重要です。はapp.UseCookieAuthentication、最初に登録されたミドルウェアである必要があります。

于 2015-10-15T16:48:54.633 に答える