6

MVC5 Web アプリケーションを開発しています。このアプリケーションには、「SU」と「App」の 2 つの領域があります。各領域は個別に認証する必要があります。各エリアには、独自のログイン ページもあります。ユーザーの認証にOWIN
を 使用しています。問題は、ユーザーが要求している領域に基づいて owin を設定できないことです。 たとえば、ユーザー リクエストの場合、それらをリダイレクトできるはずです。 同様に、「アプリ」領域については、ユーザー リクエストの場合、リダイレクトできるはずです
CookieAuthenticationOptions LoginPath
http://example.com/su/reports/dashboardhttp://example.com/su/auth/login
http://example.com/app/history/dashboardhttp://example.com/app/auth/login

カスタム属性を避けたいので、次のコードを試してみましたが、常にルート ログイン パスにリダイレクトされます。http://example.com/auth/login

public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var url = HttpContext.Current.Request.Url.AbsoluteUri;
            string loginPath = "/auth/login";
            string areaName = string.Empty;
            if (url.ToLower().Contains("/su/"))
            {
                areaName = "SU";
                loginPath = "/su/auth/login"; 
            }
            if (url.ToLower().Contains("/app/"))
            {
                areaName = "APP";
                loginPath = "/app/auth/login";
            }
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicationCookie" + areaName,
                LoginPath = new PathString(loginPath)
            });
        }
}  

私は正しいアプローチに従っていますか、それとも同じことを達成する他の方法はありますか? ありがとう!

4

1 に答える 1