473,499 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!

Nov 19 '05 #1
0 1934

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3243
by: Bartosz Krzywicki | last post by:
I have the problem with Session object witch is null, when I implement IHttpHandlerFactory. Implementing IRequiresSessionState interface doesn't help. My code is like this: class MyController :...
3
1666
by: Bartosz Krzywicki | last post by:
I have the problem with Session object witch is null, when I implement IHttpHandlerFactory. Implementing IRequiresSessionState interface doesn't help. My code is like this: class MyController :...
2
2572
by: Jon Maz | last post by:
Hi All, I've been looking into options for URL Rewriting in .net, and to be honest, I haven't seen anything that's easier than the old Classic Asp solution with an ISAPI filter redirecting to an...
3
2708
by: Michael Appelmans | last post by:
I'm trying to use a rule based URL rewrite application which uses HttpApplication.RewritePath. I keep getting "rsource not found" error in application when running on shared web host although the...
0
2078
by: Lee | last post by:
Hi all ;) Preamble -------- I'm using URL rewriting to enforce a frames policy (yeah, I know frames are 'bad' :) - i.e. if a request comes in for a page which should be nested within a...
0
1031
by: djmc | last post by:
Hi, I am trying to use a URL Rewriting technique outlined here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp Basically I create a HTTPHandlerFactory...
3
4710
by: Greg Collins [Microsoft MVP] | last post by:
I have done a bit of research of Url Rewriting, but as yet have been unsuccessful at getting it to work well, and there are issues around what file types are supported and how much code you want to...
0
1060
by: Steve B. | last post by:
Hi, We have build a custom class that implement IHttpHandlerFactory in order to handle all request to a IIS web site. In IIS 6, we just added the aspnet_isapi.dll to the list of generic...
1
7872
Shinobi
by: Shinobi | last post by:
I am using ASP.net(c#) for my project. In my my project 2 pages are using URL rewriting method by referring this article URL Rewriting using Intelligencia UrlRewriter Example 1 - Blog Day...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.