473,748 Members | 6,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

URL Rewriting using IHttpHandlerFac tory

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 IHttpHandlerFac tory
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.Rewrite Path()

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.v b
Public Class CustomHandler
Implements IHttpHandler

Public ReadOnly Property IsReusable() As Boolean Implements
System.Web.IHtt pHandler.IsReus able
Get
Return False
End Get
End Property

Public Sub ProcessRequest( ByVal context As System.Web.Http Context)
Implements System.Web.IHtt pHandler.Proces sRequest

Dim TargetPage As String = _
Regex.Match(con text.Request.Ur l.AbsolutePath, "[0-9]+\.aspx",
RegexOptions.Ig noreCase).Value

If (Not TargetPage Is Nothing) Then
Select Case TargetPage
Case "1.aspx"
context.Rewrite Path("~/test/one.aspx")
Case "2.aspx"
context.Rewrite Path("~/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 IHttpHandlerFac tory

Public Function GetHandler(ByVa l context As System.Web.Http Context,
ByVal requestType As String, ByVal url As String, ByVal pathTranslated As
String) As System.Web.IHtt pHandler Implements
System.Web.IHtt pHandlerFactory .GetHandler

Dim TargetPage As String = _
Regex.Match(con text.Request.Ur l.AbsolutePath, "[0-9]+\.aspx",
RegexOptions.Ig noreCase).Value

If (TargetPage.Len gth = 0) Then
Return PageParser.GetC ompiledPageInst ance(url, pathTranslated,
context)
End If

Return New CustomHandler

End Function

Public Sub ReleaseHandler( ByVal handler As System.Web.IHtt pHandler)
Implements System.Web.IHtt pHandlerFactory .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.Rewrite Path("~/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
GetCompiledPage Instance .. 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 1951

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

Similar topics

1
3275
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 : IHttpHandlerFactory, System.Web.SessionState.IRequiresSessionState { public virtual IHttpHandler GetHandler (HttpContext context, string requestType, string url, string path) { //some stuff here context.Session = "aaa"; // here Session object is...
3
1676
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 : IHttpHandlerFactory, System.Web.SessionState.IRequiresSessionState { public virtual IHttpHandler GetHandler (HttpContext context, string requestType, string url, string path) { //some stuff here context.Session = "aaa"; // here Session object is...
2
2596
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 .asp page with responsibility for handling the redirect. I'm now planning to use this solution with my next .net project, and was wondering if anyone else out there has done this already, and what problems (if any) arise. Hopefully the news...
3
2749
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 software runs fine on my localhost. Is it possible that the web hosting service has configured something in the machine.config file to disable URL rewriting? I have been communicating with them but they seem clueless as to the cause. Thanks for...
0
2127
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 frameset, the url is rewritten to something of the form 'http://www.blah.com/framesdoc.aspx?lowerFrame=/page.aspx', the 'framesdoc' page then dynamically generates the src attribute for the
0
1044
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 that scans whether the URL needs to be rewritten, and if so, it passes back the Page built from the rewritten url. I am trying to combine this with OutputCache or some kind of caching. Could someone recommend me the best way to do this or...
3
4743
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 write. While working on a similar, though partially unrelated, issue, I came across a possible alternate method. Before I pursue this method in full, I wanted to get opinions of others as to any unforseen issues I might encounter. The method is...
0
1072
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 mapping (properties -Wildcards application maps). We also added a line in the web.config in <handlerssection. This is working as expected, all incoming http request are handled by our factory (in which we choose between a custom handler and standard...
1
7889
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 Afternoon from my form i used this code. Response.Redirect("showdetails/" + a); in my Web.config <system.webServer>
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8243
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.