Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

httpmodules 1

Status
Not open for further replies.

RicksAtWork

Programmer
Nov 1, 2005
120
GB
I am wanting to map part of a URL to an ID in my data base.

For example:


path1 maps to an ID in a database
path2 maps to an ID in a database

I have been told that I can use HTTPMODULES to parse the URL to extract the path1 part of the URL, perform a lookup and then redirect to a base page that will access the values.

Has anybody ever attempted this or seen information on this?
 
So if the directory path1 and path2 dont exist, it wont fire?
 
not using ASP.NET, why?
cause the .NET engine will fire only when IIS calls it, and IIS will call .NET only if it finds an ASPX extension (and other defined extensions) in the path.

A better forum for this could be the IIS forum, but even there i dont think u acn do much...

Known is handfull, Unknown is worldfull
 
Each path represents a product. We could potentially have 1000s of them. Basically I dont want to duplicate the same page in a directory for each product!!!

Thoughts on how to achieve this?
 
i did this once, but that was in PHP and the concept is like this:

1. Open a DataReader picking out all the products.
2. Run a loop and create folders in the name of the products (You will get this from the datareader).
3. Place an index.aspx file in it (This file will simply redirect the user to the products page). This file has to be created at run time (as it has to redirect to with different parameters for each product)...

Known is handfull, Unknown is worldfull
 
yes, the index.aspx in each folder will just have a redirect command...

Known is handfull, Unknown is worldfull
 
You don't have to go through all of that just to rewrite a URL (i.e. creating an index.aspx papeg and a folder for each product) - that's complete overkill and not necessary. Read the following MSDN article and follow it's walkthrough:



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
Hi ca8msm,

I took a look at the article. HttpHandlers was the approach I intended to use, however...

I still think I'll need to create a page, because in order for an httpModule to execute, I was under the impression that a requestable page had to exist.

Am I mistaken?
 
No, you shouldn't need the page to exist - if you follow the walkthrough you'll see that they inherit IHttpModule and wire up the relevant events to that.

If you did want to use a page based approach, a slight "cheat" would be to create a custom 404 page that redirected the user to the correct page (if it was a valid request in the first place) otherwise show the 404 error.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
According to the article you need to map all requests to .NET - this could be a problem because I'm on a shared host.

I like the custom 404 page error though.

Will this incur much overhead?
 
Well it would incur the cost of doing the lookup but you could implement it in the same way as the module does (i.e. with a RegEx) so that no database lookups are involved.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Note:
However HttpModule will fire ONLY if there is a request to an ASPX file."

That's not entirely true, it depends on the IIS mappings. ASP.NET can process any URI/extension it's configured to handle (including extensionless URI), though if you're in a shared hosting environment you're hosed as far as configuring all of that.

Fortunately, as long as you pretend the URI is a reference to a file that ASP.NET would handle, you can rewrite it easily enough. In other words, if you want:


...but are in a shared hosting environment, you'll have to settle for:


As long as you do that, you can intercept and rewrite the URI so that:


...could become:


...and of course:


...could become:


Naturally (if you're set up right), the user would never see the URI: in their browser, rather they'd always see the more friendly, pre-change URI.

Where this becomes a little tricky is in knowing at exactly what point to rewrite the URI. Depending on when you do it, you may either accidently bypass security checks (if that matters) or you may rewrite it such that if the user refreshes, they see the less-friendly URI.
 
Hi BoulderBum,

How do I do the following from the IIS point of view :

'ASP.NET can process any URI/extension it's configured to handle (including extensionless URI)'

My hosting company is very accomodating and will probably perform these configuration changes for me!
 
>>That's not entirely true, it depends on the IIS mappings

i was speaking only from shared hosting point of view. standardly only certain extenstions are supported in them...

>>ca8msm
nice one on the 404, deserve a star for that...

Known is handfull, Unknown is worldfull
 
I've set IIs for the extension .*

This forwards all requests to asp.net apart from those already defined in IIS!!!

So if I add path1 to my web.config i.e.

<add verb="*" path="path1" type="HttpHandlerTests.TestHttpHandler,HttpHandlerTests" />

Then asp.net handles


However, this means that I have to define avery path I want to support in the web.config.

Can I add these paths anywhere else than the web.config??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top