2012-01-28 90 views
0

我想改变的时候还没有登录他们自己的网站重定向用户的地方。如何更改表单身份验证loginurl?

<authentication mode="Forms"> 
    <forms loginUrl="~/Account/LogOn" timeout="30" /> 
</authentication> 

它使用的AccountController默认Controllers文件夹,操作方法登录和查看连接到这一点。

我有另一个AccountController放置在这个文件夹:Areas/SmallSurvey/Controllers/Account action方法的名字是一样的。我无法弄清楚使用的语法。

我尝试过不同的名字,但都没有工作。我如何改变它?

的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 /帐号/登录” 我得到以下错误:

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 

回答

1
<authentication mode="Forms"> 
    <forms loginUrl="~/SmallSurvey/Account/LogOn" timeout="30" /> 
</authentication> 
+0

它不工作。我是否需要在路线中设置某些东西? – Kenci 2012-01-28 21:14:11

+0

@Kenci,“不起作用”不是一个非常精确的问题描述。你能更具体一点吗? – 2012-01-28 21:15:41

+0

这是错误: 说明:HTTP 404.您正在查找的资源(或其某个依赖项)可能已被删除,名称已更改或暂时不可用。请检查以下网址并确保它拼写正确。 请求的网址:/ SmallSurvey /帐户/登录 – Kenci 2012-01-28 21:22:54

2
Try this ~/SmallSurvey/Account/logon 

[编辑根据您回应] ..以下应该在您所在地区的路线registration..notice的区域名称

context.MapRoute(

     "SmallSurvey_default", 
     "SmallSurvey/{controller}/{action}/{id}", 
     new { action = "Index", id = UrlParameter.Optional }, 
.... 
     ); 
+0

它不工作的路线。我是否需要在路线中设置某些东西? – Kenci 2012-01-28 21:15:03