你的代码是正确的,应当放在<代码>Application_Start方法上Global.asax
。 例如:
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new Route(
"sitemap.xml", new PageRouteHandler("~/sitemap.aspx")));
}
However, you also need to make sure that *.xml files are handled by ASP.NET. By default, *.xml files will just be served up by IIS and not processed by ASP.NET. To make sure they are processed by ASP.NET, you can either:
(1) 具体说明run AllManaged ModulesFor AllRequests=“true”
on the system.webServer
elements in the You web.config
:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
</modules>
</system.webServer>
or 2) add a "Handler Mapping" for .xml files:
<system.webServer>
<handlers>
<add name="xml-file-handler" path="*.xml" type="System.Web.UI.PageHandlerFactory"
verb="*" />
</handlers>
</system.webServer>
我在一份样本中测试了这一情况。 NET(N-MVC)项目,能够按照你的具体要求开展工作。