advertisement

Search | Recent | Register

Forum => Article discussions => Rewriting the URL using IHttpHandlerFactory

Jump to:

Next Oldest | Next Newest

More: 1  2  3  4  >>  >|
4/3/2005 9:51:37 PM Link | Reply | Edit | Quote

uber:ASP.Net

Location: | Joined: 1/1/2000 | Posts: 12 | Online

Article discussion for:
Rewriting the URL using IHttpHandlerFactory

4/4/2005 11:56:14 AM Link | Reply | Edit | Quote

daberelay

Profile Send Private Message
Location: | Joined: 4/4/2005 | Posts: 2 | Offline

Hi,
First, thanks for this nice article.

A few quesition arise from your article, i would be greatfull if you can answer them...

1. How about cross application files? will i be able to serve a page which belongs to a different application / virtual directory than the one i put my factory in? unfortunatly i wasn't able so far to do so using HttpHandlers and HttpModules, only using ISAPI filters.

2. Will this work for html pages, say i need to be able to parse the request and serve html files as the result, how can i return it within an HttpHandler object?

thanks again!

DaberElay.


4/4/2005 9:21:06 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

1. As best I can tell, and I could be wrong, PageParser.GetCompiledPageInstance() should be able to get any page anywhere on the drive that ASP.NET is allowed to look.

2. A static HTML page won't work, because it's returning an instance, an actual object. Honestly an .aspx page with no code and no controls won't create any significant overhead.


Jeff 'Jones' Putz
POP World Media, LLC

4/6/2005 10:15:00 AM Link | Reply | Edit | Quote

Paul Wilson

Profile Send Private Message
Location: | Joined: 4/6/2005 | Posts: 2 | Offline

I've currently got a url rewriting system using just an HttpModule that works great -- but it is slightly (not much) more complex since it requires 2 RewritePaths. The first RewritePath is of course the one everyone uses, and the second RewritePath is used to reset the form action back to the original path since the first RewritePath messes that up. It all works great, but still I was intrigued by your solution since it would of course be simpler -- except one thing doesn't work for me in your technique that does work in mine. The problem is that I want to catch requests like http://server/app (no page specified), without assuming IIS 6.0, so I have 403, 404, and 405 redirects setup to my default.aspx page -- and your technique doesn't seem to have a way to fix the form action in this case. Any idea how to solve this one?

Thanks, Paul Wilson

4/6/2005 10:22:40 AM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

Yeah, I've discovered that as well. I'm somewhere other than where my test code is, but I think that if you alter the url parameter in .GetCompiledPageInstance() it should render the right thing. I seem to recall from experimentation that's what did it. In that case you could look at the string, strip out the application root, and if it ends without something in .aspx, you could add in default.aspx.

That's talking out of my ass... I'd have to try it later.


Jeff 'Jones' Putz
POP World Media, LLC

4/6/2005 11:02:25 AM Link | Reply | Edit | Quote

Paul Wilson

Profile Send Private Message
Location: | Joined: 4/6/2005 | Posts: 2 | Offline

Yea, I tried that -- its the same parsing I already do in my other solution so it was easy to do -- but it didn't work for me here.

4/6/2005 1:06:27 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

Well, there's always the Render() override to replace action="" with action="default.aspx", but that's no fun.


Jeff 'Jones' Putz
POP World Media, LLC

4/8/2005 5:39:58 PM Link | Reply | Edit | Quote

daberelay

Profile Send Private Message
Location: | Joined: 4/4/2005 | Posts: 2 | Offline

the destined system, is a publishing system - it generates html pages once a day for all her dynamic content files, so if i understand your suggestion correctly, we have to save all generated files with .aspx instead of .html ( along with the necessary minimal content amandments ) and it should work?

4/9/2005 12:12:07 PM Link | Reply | Edit | Quote

PeterNash

Profile Send Private Message
Location: | Joined: 4/9/2005 | Posts: 1 | Offline

Thanks for your article but I faces a little problem although I understand your article well.

I have a GetHandler function like:
Public Overridable Function GetHandler(ByVal context As HttpContext, ByVal requestType As String, ByVal url As String, ByVal pathTranslated As String) As IHttpHandler Implements IHttpHandlerFactory.GetHandler
context.Items("fileName") = Path.GetFileNameWithoutExtension(url).ToLower()
Return PageParser.GetCompiledPageInstance(url, context.Server.MapPath("WebForm1.aspx"), context)
End Function

In my Web.Config file, I have something like:


However, it displays a 404 error when I access http://localhost/WebApplication2/content/1.aspx

I'd expect WebForm1.aspx to be loaded.. Should I create a HttpHandler/HttpModule even I implemented IHttpHandlerFactory interface?

Thanks!

4/11/2005 9:18:24 AM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

Your MapPath to WebForm1.aspx is a little ambiguous. Notice in my code sample I put "~/Content.aspx" (note the tilde-slash) to indicate that my page was in the root of the app.

Also are you absolutely positive that /WebApplication2 is marked as an application in IIS? That's the only other thing off the top of my head that I can think of that would cause the handler to not catch it.


Jeff 'Jones' Putz
POP World Media, LLC

5/12/2005 12:31:25 PM Link | Reply | Edit | Quote

du8die

Profile Send Private Message
Location: Southeast Wisconsin | Joined: 1/16/2004 | Posts: 126 | Offline

Jeff,

I'm getting a web.config error that says "Could not load type MyPageFactory from assembly System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

I've tried building the MyPageFactory class as it's own DLL, I've put it in its own class inside this app. The app doesn't want to locate the type.

Here's my web.config section.

httpHandlers>

add verb="*" path="~/article/*.aspx" type="MyPageFactory" />

httpHandlers>

Thanks,

d8


The cause of the problem is:
The POP server is out of Coke .

5/12/2005 6:29:11 PM Link | Reply | Edit | Quote

du8die

Profile Send Private Message
Location: Southeast Wisconsin | Joined: 1/16/2004 | Posts: 126 | Offline

Figured it out.

type="MyPageFactory, MyPageFactory"

Seems the namespace of the assembly is needed.

d8


The cause of the problem is:
The POP server is out of Coke .

5/17/2005 12:39:00 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

Yeah... I seem to recall that you can only leave out the assembly name if you have the code in a cs/vb file in /App_code.


Jeff 'Jones' Putz
POP World Media, LLC

5/24/2005 11:23:12 AM Link | Reply | Edit | Quote

norgie

Profile Send Private Message
Location: | Joined: 5/24/2005 | Posts: 1 | Offline

So what could be wrong when it seems like the class (MyPageFactory) implementing the IHttpHandlerFactory doesn't get called at all. For testing I typed the following url http://localhost/RewritingTheUrl/content/yalla.aspx where /content/ and yalla.aspx were non-existent. That gave me a 404 error. Then I created a directory called content and added the yalla.aspx page to that directory. Accessing the same url as above I was served yalla.aspx and not content.aspx as expected. Here's my web.config entry

add verb="*" path="~/content/*.aspx" type="RewritingTheUrl.MyPageFactory, RewritingTheUrl" /

And the code in the handler is exactly like in the article except that I used VB.Net and not C#. *** *** Edited 5/24/2005 3:31:29 PM UTC by norgie***

5/24/2005 12:19:19 PM Link | Reply | Edit | Quote

du8die

Profile Send Private Message
Location: Southeast Wisconsin | Joined: 1/16/2004 | Posts: 126 | Offline

Just a shot in the dark, but try taking the "RewritingTheURL." out of the type declaration in the web.config...

d8


The cause of the problem is:
The POP server is out of Coke .

5/24/2005 4:00:33 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

You might need to be referencing the root of the application in your web.config for the handler, like "~/content/*.aspx" (and of course the RewritingTheURL folder has to be marked as an application in IIIS).


Jeff 'Jones' Putz
POP World Media, LLC

5/28/2005 10:43:19 PM Link | Reply | Edit | Quote

Scott W

Profile Send Private Message
Location: | Joined: 5/29/2005 | Posts: 1 | Offline

I must be an idiot, but I can't get this to work in an asp.net 2.0 web application. I'm putting the IHttpHandlerFactory code in a class in my App_Code folder and setting up the page and web.config similarly to your article, but I keep getting 404's.

I tried compiling it into a separate dll and referencing that dll so I could put an assembly name in the handler entry in the web.config, but that didn't help either.

Jeff, have you used this in an asp.net 2.0 app? I'm sure I'm just doing something wrong but I don't know what.

In the process I discovered another irritation, no matter how I set the properties of my class project in vs.net 2005 to compile as a release version, it kept compiling the dll in the debug folder and adding the pdb file along with it.

Today must not be my day for programming.

5/28/2005 11:50:27 PM Link | Reply | Edit | Quote

Jeff

Profile Send Private Message Web Site AOL Instant Message ICQ Message
Location: Cleveland, OH, USA | Joined: 8/15/2000 | Posts: 813 | Offline

The version of ASP.NET shouldn't matter (although yes, I tried in v2). The problem can be either a) your app isn't marked as an application in IIS on deployment (assuming you aren't using the root of the site), or b) you're not specifying the path right in web.config for the handler.


Jeff 'Jones' Putz
POP World Media, LLC

7/19/2005 12:28:02 PM Link | Reply | Edit | Quote

DanTheWebGuy

Profile Send Private Message
Location: Sunshine State | Joined: 7/19/2005 | Posts: 2 | Offline

how would you validate against an XML file for first, last name? So if a user types "http://www.company.com/JohnDoe" my app would check my xml file to see if "JohnDoe" exists, if so, show him some personalized content, if not, response.write out "You do not exist!".

7/19/2005 2:07:49 PM Link | Reply | Edit | Quote

DanTheWebGuy

Profile Send Private Message
Location: Sunshine State | Joined: 7/19/2005 | Posts: 2 | Offline

I get this error . . . .


Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load type MyPageFactory from assembly System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.

Source Error:


Line 5:
Line 6:
Line 7:
Line 8:

Line 9:

More: 1  2  3  4  >>  >|

Forum => Article discussions => Rewriting the URL using IHttpHandlerFactory