私はMVC5 Webアプリケーションを開発しています。このアプリケーションには2つの領域、 'SU'と '' App 'があります。各領域は個別に認証する必要があります。各エリアには独自のログインページもあります。
私は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
OWINを使用したエリアベースの認証
にリダイレクトすることができるはずですがカスタム属性を避け、したがって、次のコードを試してみましたが、それは常にrootログインパスにすなわち、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)
});
}
}
をリダイレクトしているために、私は正しいアプローチを以下のか、同じことを達成するための他の方法はありますかな?ありがとう!