开发者

Use routing in HTTPHandler

I want to use HTTP Handler in order to create a RSS feeds.

Fo开发者_如何学JAVAr the purpose, I want to put my logic for creating the rss XML in C# class, which implement IHttpHandler, then to "map" this handler into the web.config file and to register the "mapped name" in my routing rules. I am doing something like this:

My HTTPHanlder:

public class RSSFeedHandler:IHttpHandler  
{   
    public void ProcessRequest( HttpContext context )  
    {   
        //logic for building the XML   
        context.Response.ContentType = "text/xml";   
        context.Response.Write( XMLContent);   
        .....................................  

My Web.Config:

<httpHandlers>
  <add path="Rss" verb="*" type="RSSFeedHandler" validate="false" />
.......   
<handlers> 
  <add name="RSSFeedHandler" path="Rss" verb="*" type="RSSFeedHandler" />
   ........  

My Routing rulse in global.asax:

RoutingHandler rssHandler = new RoutingHandler( "~/rss" );   
 .........   
 routes.Add( new Route( "rss/{type}/{id}", rssHandler ) );  

My Routing Hanlder:

public class RoutingHandler : IRouteHandler    
{  
    ............................   
    public IHttpHandler GetHttpHandler( RequestContext requestContext )   
    {   

So, I want when in the address bar, the user types something like: www.mysite.com/rss/news/25 for example, the server to execute the logic from the HTTP Handler and to show the rss feed for type 'news' with id '25'. (these routing parameters should be parsed into my RSS HTTPHanlder)

The problem is, that, when I am calling an URL similar to the one above, there is an ERROR in GetHttpHandler method, which says: "The file '/Rss' does not exist."

I think, that this is because, this method has been invoked before the 'mapping' in web.config, but I am not sure.

Do you know how can I achieve the funcionality that I want?


I solved my problem.

All I needed is to return a RSSFeedHandler in the GetHttpHandler method instead a page.

You can preview http://forums.asp.net/p/1533299/3717070.aspx for more information about the solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜