メンバーシップがコードでチェックする ApplicationName を設定できます。
一連の他のアプリのすべてを制御する管理アプリケーションがあります。そのアプリケーションのユーザーが他のすべてのアプリにログインできるようにしたかったので、デフォルトのアプリケーションでユーザーのログインが失敗した場合は、「管理」アプリケーションを確認します。これは、ログイン部分のために私が持っているものです。「Membership.ApplicationName = "Administration";」という行に注意してください。
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
Membership.ApplicationName = "Administration";
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && retu rnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}