开发者

Not found error in asp.net-mvc

开发者 https://www.devze.com 2023-01-31 21:42 出处:网络
Every time I run a certain application it is showing a Not Found error Does anyone know how to resolve this?

Every time I run a certain application it is showing a Not Found error

Not found error in asp.net-mvc

Does anyone know how to resolve this?

I placed a debugger on the page_load event in the default.aspx.cs file but it 开发者_如何学编程is not getting called.

Below is the routing configuration:

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // parameters
            new { controller = "Home", action = "Index", id = "" }  // Parametedefaults
        );

I tried everything I can think of, but it is not working.


What web server are you running this on VS Dev/Cassini? IIS? See if you have a default.aspx in the root folder. You need a dummy root default.aspx for MVC to work properly with some webservers.


If you are using IIS 6 you will need a wild card mapping to the aspnet isapi filter if you are using urls without an extension. There are other options such as using a fake extension e.g. mvc and mapping through to that. By default IIS 6 doesn't know to treat pages without extensions as asp.net

Steve Sanderson gives an excellent article about deploying to IIS 6 (http://blog.stevensanderson.com/2008/07/04/options-for-deploying-aspnet-mvc-to-iis-6/).

Of course if you are using IIS7 then it should just work out of the box. In that case I don't know.


If you have all the things in their places then it seems like either:

  • The routes are configured incorrectly. Most likely you don't have proper default values for your Controller/Action.
  • You are using older IIS versions and they're not configured properly. See this for instructions.


Try to check your Default.aspx code as below:

using System.Web;
using System.Web.Mvc;
using System.Web.UI;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, System.EventArgs e)
    {
        HttpContext.Current.RewritePath(Request.ApplicationPath, false);
        IHttpHandler httpHandler = new MvcHttpHandler();
        httpHandler.ProcessRequest(HttpContext.Current);
    }
}

and you need to configure your iis's wildcard mapping, see below: http://weblogs.asp.net/scottgu/archive/2007/03/04/tip-trick-integrating-asp-net-security-with-classic-asp-and-non-asp-net-urls.aspx


From the looks of it you don't have a default route set up. Try this:

Routes.MapRoute("Site (*)", "{action}", new {
    controller = "Site",
    action = "Default"
});

This basically sets up a root route which defaults the action to "Default" if nothing is passed in. This also maps to all root routes such as /Home, /Contact, /{Whatever}.


as per comments in question I placed debugger on page_load event in default.aspx.cs file but it is not getting called. Below is the routing configuration:

  • have you tried to set your default.aspx as StartUp Page for your project.

and same in IIS virtual directory.

0

精彩评论

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

关注公众号