Blogger Widgets
  • Sharing Photos using SignalR
  • TFS Extenstion - allows copy work items between projects
  • Displaying jquery progressbar with ajax call on a modal dialog
  • Managing windows services of a server via a website
  • Exploring technologies available to date. TechCipher is one place that any professional would like to visit, either to get an overview or to have better understanding.

Search This Blog

Thursday 3 May 2012

ASP.NET MVC login page throwing error "The resource cannot be found"


As per ASP.NET MVC getting the error message "The resource cannot be found" is as simple as verifying if the view/user control does actually exist or name of the view/user control is misspelled.

But in this case that is not the issue because the controller "AccountController" does exist and the view "Login.aspx" also does exist. So have started using google search and tried various suggestions but nothing did work.

Also I have created another sample ASP.NET MVC standard project and have modified web.config to use forms authentication and that works, so the issue is not the environment.

Actually I have missed out a point about some configuration changes I have made to project. The requirement was actually to support "IIS 7" & "IIS 6" as well. The changes I have actually made are

1. Added extra routing in global.asax.cs
public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default.aspx", // Route name
                "{controller}.aspx/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Default", id = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "Root",
                "",
                new { controller = "Home", action = "Default", id = UrlParameter.Optional });
        }
2. Added "default.aspx" to project at the root
3. Now add "Page_Load" event to code behind
public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext.Current.RewritePath(Request.ApplicationPath);
            IHttpHandler httpHandler = new MvcHttpHandler();
            httpHandler.ProcessRequest(HttpContext.Current); 
        }
    }

All these changes allows running ASP.NET MVC application on IIS6. All this said I am still unable to find out the fix for this issue. Started looking at the error message again to see if I have missed out any thing, Aha.... I found it. Look at the url on the address bar
http://localhost:49668/Account/Logon?ReturnUrl=%2fdefault.aspx

Lets look at first route map
 routes.MapRoute(
                "Default.aspx", // Route name
                "{controller}.aspx/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Default", id = UrlParameter.Optional } // Parameter defaults
            );

ie.. request for "default.aspx" will use "Home" controller with action as "Default"

Second route map
 routes.MapRoute(
                "Root",
                "",
                new { controller = "Home", action = "Default", id = UrlParameter.Optional });

ie.. request to root of the website to be redirected to "default.aspx", use "Home" controller with action as "Default"

Both are fine but I have missed out default ASP.NET MVC routing which is (ie.. "{controller}.aspx" modified to "{controller}"
 routes.MapRoute(
                "Default", // Route name
               "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Default", id = UrlParameter.Optional } // Parameter defaults
            );

After adding this application started working and I have got the login page.

Treat your password like your toothbrush. Don't let anybody else use it, and get a new one every six months.
~Clifford Stoll

1 comments:

Copyright © 2013 Template Doctor . Designed by Malith Madushanka - Cool Blogger Tutorials | Code by CBT | Images by by HQ Wallpapers