MVC5 Web アプリケーションを開発しています。このアプリケーションには、「SU」と「App」の 2 つの領域があります。各領域は個別に認証する必要があります。各エリアには、独自のログイン ページもあります。ユーザーの認証にOWIN
を
使用しています。問題は、ユーザーが要求している領域に基づいて
owin を設定できないことです。
たとえば、ユーザー リクエストの場合、それらをリダイレクトできるはずです。
同様に、「アプリ」領域については、ユーザー リクエストの場合、リダイレクトできるはずですCookieAuthenticationOptions
LoginPath
http://example.com/su/reports/dashboard
http://example.com/su/auth/login
http://example.com/app/history/dashboard
http://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)
});
}
}
私は正しいアプローチに従っていますか、それとも同じことを達成する他の方法はありますか? ありがとう!