C# Change my sitemap from ashx to xml

时光怂恿深爱的人放手 提交于 2019-12-13 19:30:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!