Why ASP.NET MVC bothers to have a Default.aspx file?

久未见 提交于 2019-12-23 07:47:57

问题


When create a new ASP.NET MVC project in Visual Studio 2008, there is a Default.aspx page by default. It has one line

In its Page_Load function, it just redirects to "/" to go through the routing procedure.

    public void Page_Load(object sender, System.EventArgs e)
    {
        HttpContext.Current.RewritePath(Request.ApplicationPath);
        IHttpHandler httpHandler = new MvcHttpHandler();
        httpHandler.ProcessRequest(HttpContext.Current);
    }

I tried to remove Default.aspx and it turns out that the default URI "http://localhost:2574/" is still accessible. So, why bother to have such Default.aspx?


回答1:


Older versions of IIS need a startup document and it also gives you something to right-click on to get the "View in Browser" option.




回答2:


What's happening here, is that the Url requested (which was Default.aspx) is being re-written to the application root "/" and then transferred off of the Webform HTTP handler and onto the MvcHttpHandler. A request for "/" will match the Default route entry (show further down)... eventually sending us onto one of the route controllers.

useful link here



来源:https://stackoverflow.com/questions/333596/why-asp-net-mvc-bothers-to-have-a-default-aspx-file

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