2017-03-03 9 views
1

私はwidth asp.net coreを暴行しており、ユーザの場合は '/ account/login'、管理者の場合は '/ Admin/Account/Login' 'Admin'はエリア名ですが、何が間違っているのか分かりません。ここ はstartup.csで私のコードです:asp.netcoreは2つのログインパスを設定します

public void ConfigureServices(IServiceCollection services) 
    { 
     services.AddAuthorization(); 
     ... 
    } 

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 
{ 
    ... 
    app.UseCookieAuthentication(new CookieAuthenticationOptions() 
    { 
     AuthenticationScheme = "UserAuthScheme", 
     AutomaticAuthenticate = true, 
     AutomaticChallenge = true, 
     CookieName = ".AUTOUSERAUTHCOOKIE", 
     LoginPath = "/Account/Login", 
     CookieHttpOnly = true 
    }); 
    app.UseCookieAuthentication(new CookieAuthenticationOptions() 
    { 
     AuthenticationScheme = "AdministratorAuthScheme", 
     AutomaticAuthenticate = true, 
     AutomaticChallenge = true, 
     CookieName = ".AUTOADMINAUTHCOOKIE", 
     LoginPath = "/Admin/Account/Login", 
     CookieHttpOnly = true 
    }); 
    ... 
} 

AdministratorController.cs:

[Authorize(Roles ="Super",ActiveAuthenticationSchemes ="AdministratorAuthScheme")] 
public async Task<IActionResult> Edit(string id) 
{ 
    if (string.IsNullOrEmpty(id)) 
    { 
     return new EmptyResult(); 
    } 
    ..... 
} 

ユーザーは "スーパー" ロールを持っていないとき、それは単に「/アカウント/アクセス拒否にreturnurlにジャンプ? =%2FAdmin%2FAdministrator%2FEdit "となります。

役割:ユーザーは一般ユーザー用、管理者は管理者用、スーパーは管理者を変更または作成できるスーパー管理者用です。 誰かが私を助けたり、参考リンクを与えることはできますか? と私の貧しい私の英語のために申し訳ありません:)

+0

私は検索して検索して検索しています...だから、まだ検索しています... :( – gsias

答えて

0

使用OnApplyRedirectロジックをカスタマイズするアクション。

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
    LoginPath = new PathString("/account/login"), 
    Provider = new CookieAuthenticationProvider 
    { 
     OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
      validateInterval: TimeSpan.FromMinutes(30), 
      regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)), 
     OnApplyRedirect = ctx => 
     { 
      if (ctx.Request.Path.StartsWithSegments(new PathString("/admin"))) 
       ctx.Response.Redirect("/admin/account/login?ReturnUrl=" + HttpUtility.UrlEncode(ctx.Request.Path.ToString())); 
      else 
       ctx.Response.Redirect(ctx.RedirectUri); 
     } 
    }, 
}); 
関連する問題