English 中文(简体)
• 说明如何将我的NON-MVC网站从地图xml转至另一个网页
原标题:Cant figure out how to route my NON-MVC site from sitemap.xml to another .aspx page

When searching google the only solutions for this come up for MVC websites. My asp.net 4.0 site is not MVC. I want requests for sitemap.xml to load another dynamic .aspx page so I can generate links for google on the fly.

我花了几个小时的搜索,如果你知道我能找到答案,请让我知道。

I have tried using

RouteTable.Routes.Add("SitemapRoute", new Route("sitemap.xml", new PageRouteHandler("~/sitemap.aspx")))
最佳回答

你的代码是正确的,应当放在<代码>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)项目,能够按照你的具体要求开展工作。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签