ASP.NET routing in WebForms does not handle non-ASP extensions when running under ASP.NET Development Server

本秂侑毒 提交于 2019-12-02 07:04:27

This shows 404 when I start ASP.NET Development Server and browse to "http://localhost:6521/WebSite1/about"

I prepared a sample Web Application, which gave me About us and Default.aspx pages. In default.aspx page, I wrote the following code....

Default.aspx.cs Code

protected void Page_Load(object sender, EventArgs e)
{
    Response.Redirect(Page.GetRouteUrl("AboutRoute", 
                        new { ID = "Evgenyt" }));
}

Global.asax.cs Code

public class Global : System.Web.HttpApplication
{
    private void RegisterRoute(RouteCollection Routes)
    {
        Routes.MapPageRoute("AboutRoute", "about/{ID}", "~/About.aspx");

    }

    void Application_Start(object sender, EventArgs e)
    {
        RegisterRoute(RouteTable.Routes);
        // Code that runs on application startup

    }
}

Then I published the code and configured it on IIS. Now When the Request Reaches IIS, It routed the message to the aspnet_isapi.dll ISAPI extension. ISAPI extension then loaded the default.aspx page, execute it, and return its rendered HTML to IIS, and finally IIS then sends it back to the client.

Resultant URL

http://localhost/Demo/about/Evgenyt

Actual URL

http://localhost/Demo/AboutUs.aspx


What do I need to change in web.config to make Development Server work as IIS does (correctly handles extension-less URLs)?

Reference - Unlike URLMapping, URLRouting does not take place in Web.config. It can be implemented using code. You can use Application_Start Event as mentioned in your code in Glogal.asax.cs file to register all routes for your application. To register a route you can use RouteTable class in System.Web.Routing namespace.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!