開源 ASP.NET MVC 專案中只有 Global.asax,無傳統 Default.aspx,IIS 設置默認文檔失效,目錄瀏覽也被禁用。
ASP.NET MVC 基於路由機制,不依賴物理文件作為入口。入口由路由表決定,默認路由:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
直接訪問:https://localhost:port/ 或 https://localhost:port/Home/Index
Views/
└── Home/
└── Index.cshtml (或 Index.aspx)
確保 Views/Home/Index.cshtml 存在且內容正確。
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0"
path="*." verb="*"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Global.asax.cs 中 Application_Start 是否註冊路由RouteConfig.cs 被正確調用<customErrors mode="Off" />