advertisement

Search | Recent | Register

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

Jump to:

Next Oldest | Next Newest

More: |< <<  1  2  3  4  >|
1/5/2006 5:16:42 PM Link | Reply | Edit | Quote

Thomas

Profile Send Private Message
Location: | Joined: 1/5/2006 | Posts: 6 | Offline

Hi all,

at first: thanks for the solution. I've implemented it successfully in some projects. But now I have a big problem and I don't know how to solve.

In short:

I use this method of rewriting the url with my ASP.NET 2.0 web, which uses some not existing directories in url (www.site.com/de/Default.aspx or www.site.com/en/Default.aspx for language key in url).

As far es good. All is working fine, except Forms Authentication:

public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
{
System.Web.HttpContext.Current.Response.Write(url);
string filename = Path.GetFileName(context.Request.FilePath);
return PageParser.GetCompiledPageInstance(filename, context.Server.MapPath("~/" + filename), context);
}







If the URL is /Default.aspx all works fine, if the URL is /de/Default.aspx nothing happens.

I created a sample web application which you can find at:

I hope somebody can reproduce the error and give me a tip because I am looking around for a working solution since some hours ...

1/5/2006 6:53:25 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 determination about what folder the framework looks for is determined by the httpHandler declaration in web.config... so you'd have to post that.

But if you're doing language variations of the same stuff, you might want to look into using resources.


Jeff 'Jones' Putz
POP World Media, LLC

1/6/2006 9:13:16 AM Link | Reply | Edit | Quote

Thomas

Profile Send Private Message
Location: | Joined: 1/5/2006 | Posts: 6 | Offline

I am using resources, that is not the point. They have been ignored in the sample to simplify it and to concentrate on the main problem.

The httpHandler-Section looks like this:



1/6/2006 10:30:44 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

That handler declaration is only going to handle .aspx files in the root. You need to use something like */*.aspx instead.


Jeff 'Jones' Putz
POP World Media, LLC

1/6/2006 10:40:15 AM Link | Reply | Edit | Quote

Thomas

Profile Send Private Message
Location: | Joined: 1/5/2006 | Posts: 6 | Offline

Have you ever tested this? I does not work ... Neither */*.aspx nor * or something else.

1/6/2006 11:16:03 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

Sure... for the next version of the forum I'm using:


Jeff 'Jones' Putz
POP World Media, LLC

1/7/2006 6:51:06 AM Link | Reply | Edit | Quote

Thomas

Profile Send Private Message
Location: | Joined: 1/5/2006 | Posts: 6 | Offline

Of course this works for rewriting, but then the forms authentication does not work.

Calling /Default.aspx -> redirecting to Login-Page, what is right.
Calling /xyz/Default.aspx -> nothing happens.

1/7/2006 7:18:46 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

I don't follow what you mean. FormsAuth works as it should. I'm using it in this manner every day. Can you be more clear about what you want to happen (in English, not using code) and what is actually happening?


Jeff 'Jones' Putz
POP World Media, LLC

1/8/2006 6:59:35 AM Link | Reply | Edit | Quote

Thomas

Profile Send Private Message
Location: | Joined: 1/5/2006 | Posts: 6 | Offline

Just download the sample project and take a look in it, then you will see what I mean.

But it is okay, I have decided for another way in the meantime.

1/22/2006 8:22:58 AM Link | Reply | Edit | Quote

Thomas

Profile Send Private Message
Location: | Joined: 1/5/2006 | Posts: 6 | Offline

And here is the other way, maybe you take a look at it:
http://www.urlrewriting.net/

Regards, Thomas

1/23/2006 10:20:07 AM Link | Reply | Edit | Quote

JonB101

Profile Send Private Message
Location: | Joined: 10/12/2005 | Posts: 12 | Offline

Hello again.

I've had this solution implemented now for 3-4 months. It has helped us out tremendously.

Originally I complained about a memory leak, and then declared that I figured out the problem, that debug was set to true in the web.config. Well, that’s only partially correct, by setting it to false, it seems that IIS was able to restart the offending process every once in a while, to keep the leak in check. However, over the last few months, we have had an increase in traffic and hence an increase in the number pages rendered by the handler.

IIS is no longer able to keep the leak in check, and I find ourselves restarting IIS almost daily.

Over this weekend, we set up our load balancer to direct all non-handler pages to one web server, and all handler pages to the other. After a 24 hr period, the non-handler webserver remained almost constant with only a slight rise in RAM. The other webserver, was fast approaching 700 mb of RAM. Overall, there are far more non-handler pages than handler pages being rendered.

We get around a million page views a day. I mention that, because this leak probably wouldn't be noticed if we had far less traffic.

Now it still feels like I’m missing something. Is there an object that needs to be explicitly destroyed? Maybe the httpContext Items (HttpContext.Current.Items.Clear)

Does releaseHandler need to be called? (I have one line of code here ‘handler = nothing')

I have isResuable set to true.

Any insight is much appreciatedJon

1/23/2006 7:14:43 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

Nothing you describe indicates a memory leak as far as I'm concerned. My memory usage gets as high as a gig.

Are you experiencing a performance issue? If so, I suspect it's coming from somewhere else.


Jeff 'Jones' Putz
POP World Media, LLC

1/23/2006 7:45:24 PM Link | Reply | Edit | Quote

JonB101

Profile Send Private Message
Location: | Joined: 10/12/2005 | Posts: 12 | Offline

w3wp.exe is the offending process that consumes all the RAM. Our web servers have 2 gigs of RAM, but IIS starts serving up 'out of memory errors' around 800 mb - 1 gb of RAM. At this point, ISS has to be restarted. Until it starts giving errors, there are no noticeable performance issues.

web1/web2. WEB1 is running the handler code and WEB2 is running non handler code. Alot of the same code is used for both the handler and non handler pages. WEB2 is serving 10-15 pages for every 1 page that WEB1 serves. And yet, WEB2 uses a pretty consistent 300 MB and WEB1 continues to grow to it throws errors.

1/25/2006 2:28:43 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

Very odd. I still think there has to be something else going on though, because memory leaks using managed code generally just doesn't happen. If I was more curious and had spare time I'd love to help you figure it out, but alas, time is tight these days!


Jeff 'Jones' Putz
POP World Media, LLC

1/26/2006 1:27:19 PM Link | Reply | Edit | Quote

Dave Brophy

Profile Send Private Message Web Site
Location: | Joined: 1/26/2006 | Posts: 3 | Offline

Hi guys... I posted this question on www.asp.net today, but I thought I'd post it here too because you lot seem to be well into it...

I've put a wildcard application mapping in IIS6 (on Windows Server 2003), pointing at the ASP.NET 2.0 aspnet_isapi.dll.

Here's my web.config httpHandlers section:

httpHandlers>
add verb="*" path="*" type="MyProject.MyHandlerFactory, MyProject"/>
/httpHandlers>

Here's my IHttpHanderFactory:

public class MyHandlerFactory : IHttpHandlerFactory
{
public virtual IHttpHandler GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
{
return PageParser.GetCompiledPageInstance("/MyPage.aspx", context.Server.MapPath("/MyPage.aspx"), context);
}
public virtual void ReleaseHandler(IHttpHandler handler) { }
}

I've had this (well, this is a simplification of my code) working perfectly for a year on www.dontstayin.com under ASP.NET 1.1. However with ASP.NET 2.0, I get the following bug:

Navigating to any URL gives me the expected result, but navigating to the root of the site causes GetCompiledPageInstance to throw a "Object reference not set to an instance of an object" error.

Can anyone repeat this error / suggest a workaround? *** Edited 1/26/2006 6:32:55 PM UTC by Dave Brophy***

1/26/2006 1:33:39 PM Link | Reply | Edit | Quote

Dave Brophy

Profile Send Private Message Web Site
Location: | Joined: 1/26/2006 | Posts: 3 | Offline

I've done a bit of digging with the help of .NET Reflector:

GetCompiledPageInstance calls the context.Request.BaseDir.Combine() method.

... but Request.BaseDir is null for a request on the root...

I can't see a reason for this. Surely BaseDir should be the same for a root request and a page request...

1/26/2006 2:00:15 PM Link | Reply | Edit | Quote

Dave Brophy

Profile Send Private Message Web Site
Location: | Joined: 1/26/2006 | Posts: 3 | Offline

I've confirmed this is the problem. In .NET 1.1, Request.BaseDir returns a value when you're doing a root request. With .NET 2.0, it returns null...

Does anyone know the best way to report this to Microsoft? Can anyone think up a workaround?

1/26/2006 11:38:46 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

I forget the URL, but you can submit a support request to Microsoft, which eventually will get to the right people. It could take upward of a month. I found a bug in v1.1 a long time ago, and it was dealt with.


Jeff 'Jones' Putz
POP World Media, LLC

2/21/2006 10:16:28 AM Link | Reply | Edit | Quote

Rixke

Profile Send Private Message
Location: Belgium | Joined: 2/21/2006 | Posts: 2 | Offline

Hi,

Just implemented your code and it works great! Thx.

However, I'd also like to point a page without extention (actualy a folder) to content.aspx. Something like (without ".aspx") points to . I can 't figure it out using an IHttpHandlerFactory. Can this be done? I've no access to IIS.

Thx...

Eric

2/21/2006 10:21:27 AM Link | Reply | Edit | Quote

Rixke

Profile Send Private Message
Location: Belgium | Joined: 2/21/2006 | Posts: 2 | Offline

Hi,

Thanx for this code. Just got it to work.

However, I'd like to point a page without extention, actually a folder, to context.aspx. Something like:

points to

Can this be done with an IHttpHandlerFactory? Can 't figure it out? I've no access to IIS.

Thanx.

Eric

More: |< <<  1  2  3  4  >|

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