gpt4 book ai didi

asp.net - 将MVC和路由添加到WebForms项目后,IIS中的默认文档(default.aspx)不起作用

转载 作者:行者123 更新时间:2023-12-04 14:04:56 25 4
gpt4 key购买 nike

我有一个现有的 ASP.NET 3.5 WebForms 项目,并将 ASP.NET MVC 添加到该项目中。现有页面运行良好,新 Controller 和 View 也运行良好。但是,当我部署到 IIS 7 时,默认文档 (default.aspx) 不再工作。如果我明确输入,我可以得到它,但是 'xyz.com' 不起作用 - 我得到 404。相比之下,它在 Cassini 中运行良好。

如何在保留新的 MVC 内容的同时让默认文档再次工作。

最佳答案

我在 Global.asx.cs 中添加了以下内容文件,默认文档再次工作。

    public static void RegisterRoutes(RouteCollection routes)
{
// *** This Line ***
routes.IgnoreRoute(""); // Required for the default document in IIS to work
// *****************
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");

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

protected void Application_Start(Object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}

关于asp.net - 将MVC和路由添加到WebForms项目后,IIS中的默认文档(default.aspx)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7577504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com