logo       

SV: [DOTNET-WEB] Url rewriting using IHttpHandlerFactory: msg#00067

windows.devel.dotnet.web

Subject: SV: [DOTNET-WEB] Url rewriting using IHttpHandlerFactory

Hi,

Wouldn't 'url rewriting' be a job for a IHttpModule implementation instead?
It's my undestanding
that these will get invoked prior to any IHttpHandler...

Antways, that's how i would approach it, but I could be wrong of course ;)

Frederic

________________________________

Fra: Discussion of building .NET applications targeted for the Web på vegne af
Andreas Håkansson
Sendt: to 09-06-2005 10:53
Til: DOTNET-WEB@xxxxxxxxxxxxxxxxxxx
Emne: Re: [DOTNET-WEB] Url rewriting using IHttpHandlerFactory



Chris,

So.. would this by any chance mean that it's not possible, ie. perhaps to
late in the request life-cycle, to rewrite the path from inside a custom
HttpHandler returned by a HttpHandlerFactory?

This wouldn't actually be a problem - I'd just write my own interface for
interpreting variosu requests, so I can extend with additional formats
later on - however I would like my above "theory" confirmed or corrected
so I know what is going on.

Then again, your solution doesn't use the rewritepath at all.. how is it
to be used in such a scenario then?

Thanks,

.andreas

On Wed, 8 Jun 2005 16:46:01 -0700, Chris Martin <ghettoblaster@xxxxxxx>
wrote:

> If (TargetPage.Length = 0) Then
> Return PageParser.GetCompiledPageInstance(url, pathTranslated,
>context)
> Else
> Return PageParser.GetCompiledPageInstance(url,
>Server.MapPath(GetCorrectPage(url)),
>context)
> End If
>
>-----Original Message-----
>From: Discussion of building .NET applications targeted for the Web
>[mailto:DOTNET-WEB@xxxxxxxxxxxxxxxxxxx] On Behalf Of Andreas H åkansson
>Sent: Wednesday, June 08, 2005 11:29 AM
>To: DOTNET-WEB@xxxxxxxxxxxxxxxxxxx
>Subject: [DOTNET-WEB] Url rewriting using IHttpHandlerFactory
>
>Hi,
>
>I'm playing around with url rewriting and I have come across a problem
>which
>I
>can't seem to get past. The general ide is to have a IHttpHandlerFactory
>class
>which checks the incoming request url against a set of predefined rules
and
>creates and return the appropriate IHttpHandler implementation.
>
>Inside the IHttpHandler implementations, the request is examined and
>interpreted
>in the correct way. In short they parse a request into a new url (for
>example, could
>also be a handler to generate an rss-feed or whatever, hence the need for
>the
>factory and set of rules) and rewrites it using context.RewritePath()
>
>My problem is (verified by stepping the debugger) is that the factory
>creates the
>correct Handler.. and the andler interprets the request and calls
>RewritePath()
>but the page is not displayed in my browser, instead a blank page is
shown.
>
>Basicly this is the setup of the testsite (used to reproduce the problem)
>is
>as
>follows
>
> Root
> Test
> one.aspx
> two.aspx
> Webform.aspx
>
>The URL Rewriting should be able to take Root/Test/1.aspx and rewrite it
>into
>Root/Test/one.aspx and the same for 2/two.aspx - so it's a very basic test
>setup.
>
>The handler which is created it setup as following
>
>// CustomHandler.vb
>Public Class CustomHandler
> Implements IHttpHandler
>
> Public ReadOnly Property IsReusable() As Boolean Implements
>System.Web.IHttpHandler.IsReusable
> Get
> Return False
> End Get
> End Property
>
> Public Sub ProcessRequest(ByVal context As System.Web.HttpContext)
>Implements System.Web.IHttpHandler.ProcessRequest
>
> Dim TargetPage As String = _
> Regex.Match(context.Request.Url.AbsolutePath, "[0-9]+\.aspx",
>RegexOptions.IgnoreCase).Value
>
> If (Not TargetPage Is Nothing) Then
> Select Case TargetPage
> Case "1.aspx"
> context.RewritePath("~/test/one.aspx")
> Case "2.aspx"
> context.RewritePath("~/test/two.aspx")
> End Select
> End If
>
> End Sub
>
>End Class
>
>The factory implementation (remember it's not bulletproof, it's a test app
>to reproduce the issue at hand)
>
>Public Class HttpRewriter
> Implements IHttpHandlerFactory
>
> Public Function GetHandler(ByVal context As System.Web.HttpContext,
>ByVal requestType As String, ByVal url As String, ByVal pathTranslated As
>String) As System.Web.IHttpHandler Implements
>System.Web.IHttpHandlerFactory.GetHandler
>
> Dim TargetPage As String = _
> Regex.Match(context.Request.Url.AbsolutePath, "[0-9]+\.aspx",
>RegexOptions.IgnoreCase).Value
>
> If (TargetPage.Length = 0) Then
> Return PageParser.GetCompiledPageInstance(url, pathTranslated,
>context)
> End If
>
> Return New CustomHandler
>
> End Function
>
> Public Sub ReleaseHandler(ByVal handler As System.Web.IHttpHandler)
>Implements System.Web.IHttpHandlerFactory.ReleaseHandler
>
> End Sub
>
>End Class
>
>the factory has been added to web.config and all is fine.. When debugging
>I
>can see that when I enter
>http://localhost/myapp/test/1.aspx the factory reaches the "Return New
>CustomHandler" line and execution
>is shifted over to the new objects ProcessRequest method. Continuing to
>step
>the code and I see it hits the
>Case "1.aspx" in the select block, as expected and calls
>context.RewritePath("~/test/one.aspx")
>
>This is when I'm left with a blank page. I have my sucpicions, i.e there
>is
>no compiled instance of the real
>page (one.aspx) returned from my handler (and I can't since it's a sub) ..
>how would .NET know how to
>render my page then? I've seen this design before in the .Text blog engine
>source code, but I've been
>unable to get it to work.
>
>Please remember that this is a basic test setup used to reproduce the
>problem, in hope that someone can
>point how the (obvious?) misstake I'm making. I need for a factory to
>create
>different handlers based on
>the requested path, so I can't do it like in a few articles I've seen
>where
>they rewrite the path and call
>GetCompiledPageInstance .. both done in the factory ..
>
>I figure my handler is correct, but the problem is in my factory.. perhaps
>I
>need to do something to my
>handler object before I return it in the factory?
>
>Any advice, suggestions, pointers, help etc is apprechiated! Don't worry
>about the VB.NET part i code
>C# as well so don't feel hindred by the code :P
>
>Thanks!
>
>===================================
>This list is hosted by DevelopMentor® http://www.develop.com
>
>View archives and manage your subscription(s) at
http://discuss.develop.com
>
>===================================
>This list is hosted by DevelopMentor® http://www.develop.com
>
>View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise