问题
My sitemap is at: http://localhost/scirranew/sitemap.ashx
<%@ WebHandler Language="C#" Class="SiteMap" %>
using System;
using System.Web;
public class SiteMap : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/xml";
}
public bool IsReusable {
get {
return false;
}
}
}
As far as I know, google will be OK with this. But I would like it to be a .xml filetype for consistency throughout my site.
I've tried rewriting the URL:
<rewrite url="^~/Sitemap.xml" to="~/SiteMap.ashx" processing="stop"/>
But this doesn't work with the .xml extension.
回答1:
Instead of using an ashx
file, just put the code in an assembly and register the handler in web.config with any extension you like:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="Sitemap.xml"
type="SiteMap, AssemblyContainingClass" />
</httpHandlers>
</system.web>
</configuration>
来源:https://stackoverflow.com/questions/5223520/c-sharp-change-my-sitemap-from-ashx-to-xml