我有我的本地IIS中的网站。 该网站的应用程序池处于Clasic模式。ASP.NET MVC路由,TransferRequestHandler不与ClassicMode与IIS工作
我正在将文件的路径映射到MVC上的路径。
我有路径登记这样
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.RouteExistingFiles = true;
routes.MapRoute(
name: "XMLPath",
url: "sitemapindex.xml",
defaults: new { controller = "Home", action = "Html", page = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
在我的控制器我有这样的方法
public FileResult Html()
{
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
stringBuilder.AppendLine("<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
stringBuilder.AppendLine("<sitemap>");
stringBuilder.AppendLine("<loc>http://[site]/sitemaps/sitemap_01.xml</loc>");
stringBuilder.AppendLine("<lastmod>" + DateTime.Now.ToString("MMMM-dd-yyyy HH:mm:ss tt") + "</lastmod>");
stringBuilder.AppendLine("</sitemap>");
stringBuilder.AppendLine("<sitemap>");
stringBuilder.AppendLine("<loc>http://[site]/sitemaps/sitemap_02.xml</loc>");
stringBuilder.AppendLine("<lastmod>" + DateTime.Now.ToString("MMMM-dd-yyyy HH:mm:ss tt") + "</lastmod>");
stringBuilder.AppendLine("</sitemap>");
stringBuilder.AppendLine("</sitemapindex>");
var ms = new MemoryStream(Encoding.ASCII.GetBytes(stringBuilder.ToString()));
Response.AppendHeader("Content-Disposition", "inline;filename=sitemapindex.xml");
return new FileStreamResult(ms, "text/xml");
}
在我web.cong我添加
<handlers>
<add name="HtmlFileHandler" path="*.xml" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="classicMode,runtimeVersionv4.0" />
</handlers></system.webServer>
<runtime>
唯一的区别是使用preCondition =“classicMode,runtimeVersionv4.0”not preCondition =“integratedMode,runtimeVersionv4.0”。
如果我在Visual Studio 2013中运行项目工作完美,但是当我在IIS中运行它时不起作用。如果我更改我的IIS的AppPool以集成模式工作。 但我需要在经典模式下拥有AppPool。
当我运行路线(URL)[现场] /sitemapindex.xml在经典模式我得到这个错误:
HTTP错误500.21 - 内部服务器错误 处理程序“HtmlFileHandler”有一个坏模块“ManagedPipelineHandler”在其模块列表中
这是我使用的Example Project。 如何在IIS网站的classicMode中使用System.Web.Handlers.TransferRequestHandler?