我在asp.net MVC中的初学者 我有一个问题
在我的项目中,我有两个区域:Admin&用户
并且在项目根控制器中我有帐户控制器,我的问题是
帐户控制器中的应该更改密码
// GET: /Account/Manage
public ActionResult Manage(ManageMessageId? message)
但在我的更改密码区域,我称之为网址
/User/Profile
我想知道,对于这种情况,我该怎么办?
必须为每个区域创建帐户控制器?
或者我可以从/User/Profile/ to /Account/Manage
访问?
答案 0 :(得分:0)
不,您应该只有一个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
属性装饰您所在区域的控制器。