[英]Asp.net MVC Identity In Area
我在asp.net MVC中开始,我有一个问题
在我的项目中,我有两个区域:管理员和用户
在项目根控制器中,我有帐户控制器,我的问题是
在帐户控制器中更改密码应调用
// GET: /Account/Manage
public ActionResult Manage(ManageMessageId? message)
但在我要更改密码的区域,我将此网址称为
/User/Profile
我想知道,对于这种情况,我该怎么办? 必须为每个领域创建帐户控制者吗? 或者我可以从/User/Profile/ to /Account/Manage
?
不,您应该只有一个Account
控制器,默认情况下,每个未授权的请求都将重定向到/Account/Login
:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
您唯一要做的就是使用Authorize
属性装饰区域中的控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.