开发者

Trouble using areas, not sure if something wrong with routing or web.config settings

Question is described by the steps below.

  1. Create a new ASP.NET MVC3 Web Application using Internet Application Template.
  2. Decorate HomeController class with Authorize.
  3. Run the application, It basically takes you http://localhost: 51578/Account/LogOn?ReturnUrl=%2F Everything good so far.

Let’s customize a couple of things in this project.

  1. Add an area named “Login” in this solution and move AccountController.cs, AccountModel.cs and whole Account folder under Viewer into开发者_StackOverflow中文版 appropriate folder under this Area named Login.
  2. Run the application now and you will get following error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The view 'LogOn' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Account/LogOn.aspx

~/Views/Account/LogOn.ascx

~/Views/Shared/LogOn.aspx

~/Views/Shared/LogOn.ascx

~/Views/Account/LogOn.cshtml

~/Views/Account/LogOn.vbhtml

~/Views/Shared/LogOn.cshtml

~/Views/Shared/LogOn.vbhtml

Do I need to modify anything in the web.config or in routing to make this work?


The authorize attribute is redirecting you to the LogOn page which can't be found in the View folder that is outside the Login area. If you move the HomeController in the Login area and in LoginRegisterArea you add a valid route to the home controller it will work.

I tried to do what you wanted, but the only solution I found was to have the controllers you want to authorize and the LogOn view in the same place. The solution I previously mentioned about keeping the controller and the LogOn view separate deosn't work.

Maybe someone can find a solution that accomplishes what you really want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜