指定确切路径为我的ASP.NET HTTP处理程序 [英] Specifying exact path for my ASP.NET Http Handler

查看:159
本文介绍了指定确切路径为我的ASP.NET HTTP处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成使用HTTP处理程序动态的XML /谷歌地图,这样我就不需要手工维护一个XML文件。

I generate an XML/Google sitemap on the fly using an Http Handler, so that I don't need to maintain an XML file manually.

我已经映射到我的HTTP处理程序为sitemap.xml的在我的web.config是这样的:

I have mapped my Http Handler to "sitemap.xml" in my web.config like this:

<httpHandlers>
  <add verb="*" path="sitemap.xml" type="My.Name.Space, MyAssembly" />
</httpHandlers>

它工作得很好。现在,www.mywebsite.com/sitemap.xml设置我的HTTP处理程序转化为行动,不正是我想要的东西。然而,这个网址将这样做。www.mywebsite.com/some/folder/sitemap.xml,我真的不希望出现这种情况,即我只想我的处理程序映射到我的应用程序的根目录

It works nicely. Now, www.mywebsite.com/sitemap.xml sets my Http Handler into action and does exactly what I want. However, this url will do the same: www.mywebsite.com/some/folder/sitemap.xml and I don't really want that i.e. I just want to map my handler to the root of my application.

我曾试图改变我的处理程序的路径,在我的web.config中/sitemap.xml和〜/ sitemap.xml的但既不工作。

I have tried changing the "path" of my handler in my web.config to "/sitemap.xml" and "~/sitemap.xml" but neither works.

我失去了一些东西在这里?

Am I missing something here?

推荐答案

尝试添加以下到你的web.config

Try adding the following to your web.config

<urlMappings enabled="true">
    <add url="~/SiteMap.xml" mappedUrl="~/MyHandler.ashx"/>
</urlMappings>

本使用ASP.NET 2.0的一个鲜为人知的功能叫做URL映射

This uses a little known feature of ASP.NET 2.0 called 'Url Mapping'

这篇关于指定确切路径为我的ASP.NET HTTP处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆