我想更改我的网站在未登录时重定向用户的位置。
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="30" />
</authentication>
它使用默认Controllers文件夹中的AccountController,操作方法LogOn和附加到它的视图。
我在此文件夹中放置了另一个AccountController:Areas / SmallSurvey / Controllers / Account 动作方法的名称是相同的。我无法弄清楚要使用的语法。
我尝试了不同的名字,但没有一个可以使用。我该如何改变呢?
Global.asax.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new[] { "MvcApplication3.Controllers" }
);
}
这就是SmallSurveyAreaRegistration.cs的样子:
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"SmallSurvey_default",
"SmallSurvey/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
context.MapRoute("Login", "SmallSurvey/Account/LogOn",
new { controller = "Account", action = "LogOn" },
new[] { "MvcApplication3.Areas.SmallSurvey.Controllers" });
}
尝试访问“SmallSurvey / Account / LogOn”时出现以下错误:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /SmallSurvey/Account/LogOn
答案 0 :(得分:2)
Try this ~/SmallSurvey/Account/logon
[编辑]根据您的回复..以下应该是您所在地区的路线注册...注意路线中的 地区名称
context.MapRoute(
"SmallSurvey_default",
"SmallSurvey/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
....
);
答案 1 :(得分:1)
<authentication mode="Forms">
<forms loginUrl="~/SmallSurvey/Account/LogOn" timeout="30" />
</authentication>