2012-02-11 51 views
0

我有地區,並在該地區我有Home/Index,其中包含Authorize屬性。
什麼是使這個動作默認爲我的應用程序的正確方法。
因此,當用戶類型:
mysite.com在areaRegistration.cs打開Home/Index
代碼默認操作,如果用戶通過身份驗證 - asp mvc

context.MapRoute(
       "CityPage_default", 
       "CityPage/{controller}/{action}/{id}", 
       new { controller="Home", action = "Index", id = UrlParameter.Optional } 
      ); 

回答

1

你不能用領域做到這一點,因爲只有這樣,ASP.NET MVC會知道的請求屬於到給定的區域是通過在URL中使用前綴。所以最接近你可以得到的是http://mysite.com/myarea。就HomeIndex而言,只需在路由註冊中使用默認值即可。這樣你就不需要在你的url中指定它們。

+0

此路由設置應該在global.asax中嗎? – 1110 2012-02-11 14:18:06

+0

@ 1110,在你的'〜/ Areas/AreaName/AreaNameAreaRegistration.cs'中。 – 2012-02-11 14:20:12

+0

我在我的areaRegistration.cs中添加了代碼,但這不起作用 – 1110 2012-02-11 14:22:32

相關問題