473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Redirects with ASP.NET 2.0 and wildcard mappings

I have searched hard for 2 days on this and keep hitting a wall. I
have a custom IHttpHandler setup to do Url mappings to prop up some old
Urls for our site. I have also created a wildcard mapping in IIS6
using the ASP.NET 2.0 ISAPI DLL.

Here is what I am attempting and I cannot for the life of me figure
this out.

I have several situations:

1) Remap Urls configured in a .Xml file using my IHttpHandler and build
them using custom infrastructure.
2) Allow Urls that do not require a remapping to "pass thru" and
resolve as normal.
3) Still server normal static content. (asp.net 2.0 isapi will allow
this)

I know that the asp.net 2.0 ISAPI DLL behaves properly when using it as
a wildcard mapping in that it will not prevent static content from
being served, etc. This I have verified.

In my web.config, if I setup a handler for verb="*" and type="*" for my
IHttpHandler in addition to using the wildcard mapping, this pushes all
requests thru to me. However, what I am missing is how to
programatically or otherwise, temporarily disable my custom
IHttpHandler so I can allow a Url to pass thru that does not require
remapping. Does this make sense?

The reason I am using a wildcard mappings is because I want to remap
Urls that have paths that do not physically exist within the website.
I am having a hard time getting both sides of this to work together.

Any tips would be greatly appreciated.

Dec 21 '05 #1
7 2515
> However, what I am missing is how to
programatically or otherwise, temporarily disable my custom
IHttpHandler so I can allow a Url to pass thru that does not require
remapping.


This is based upon the static .config file mappings. So there's no public
API that I have ever found to change this at runtime. One approach that might
help is to call HttpContext.RewritePath prior to the HttpApplication's MapHandler
execution step (which comes inbetween ResolveRequestCache and AcquireRequestState).
There are problems with RewritePath, but it might work for you.

The other approach is to simply have your handler act as a pass-thru for
another IHttpHandler. So in your ProcessRequest you dynamically load someother
handler and call into its ProcessRequest.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Dec 21 '05 #2
You might be thinking just a bit too deep here by trying to intercept each
request with a handler when a few lines in the onBeginRequest method of an
ihttpmodule would probably suffice.

This is a likely route for evaluating the request path: For all requests
intercept the path in onBeginRequest and make sure its not a path that needs
no remapping - simply do nothing with them, and for those that need
remapping issue a response.redirect in the module (not a transfer). For
pages that dont exist, well they are also paths you should do nothing with
but you should implement a global error handler, let the page not found
error happen for any pages that do not exist and do not need remapping and
redirect in the error handler to the path you choose for any page that does
not exist. That should cope for each scenario you have described with one
caveat, files that do not exist should technically return a 404, you have to
watch for erros passed for things like not found images when globally
handling this and decide how you'll cope with that.

--
Regards

John Timney
Microsoft MVP
"SlimFlem" <sl******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have searched hard for 2 days on this and keep hitting a wall. I
have a custom IHttpHandler setup to do Url mappings to prop up some old
Urls for our site. I have also created a wildcard mapping in IIS6
using the ASP.NET 2.0 ISAPI DLL.

Here is what I am attempting and I cannot for the life of me figure
this out.

I have several situations:

1) Remap Urls configured in a .Xml file using my IHttpHandler and build
them using custom infrastructure.
2) Allow Urls that do not require a remapping to "pass thru" and
resolve as normal.
3) Still server normal static content. (asp.net 2.0 isapi will allow
this)

I know that the asp.net 2.0 ISAPI DLL behaves properly when using it as
a wildcard mapping in that it will not prevent static content from
being served, etc. This I have verified.

In my web.config, if I setup a handler for verb="*" and type="*" for my
IHttpHandler in addition to using the wildcard mapping, this pushes all
requests thru to me. However, what I am missing is how to
programatically or otherwise, temporarily disable my custom
IHttpHandler so I can allow a Url to pass thru that does not require
remapping. Does this make sense?

The reason I am using a wildcard mappings is because I want to remap
Urls that have paths that do not physically exist within the website.
I am having a hard time getting both sides of this to work together.

Any tips would be greatly appreciated.

Dec 21 '05 #3
Thanks for the tips. What I'm actually doing is building all pages
dynamically using an in-house CMS system, so I have one generic page
that pieces together content and renders a final output page. The
reason I choose a custom handler is because from what I've read, this
is the way to go for this. Here are some code snips of what I am
currently doing and attempting.

When I determine the request *does not* need remapping, I do this
inside an if..

IHttpAsyncHandler theHandler = new DefaultHttpHandler();
theHandler.BeginProcessRequest(context, null, null);
return;

and finally, when I am redirecting/rendering a dynamic page, I do
this...

string pageLoaderVirtualPath =
ConfigurationManager.AppSettings["pageLoaderVirtualPath"];
string pageLoaderPhysicalPath =
context.Server.MapPath(pageLoaderVirtualPath);

// get an instance to the generic page loader aspx page
IHttpHandler handler =
PageParser.GetCompiledPageInstance(pageLoaderVirtu alPath,
pageLoaderPhysicalPath, context);

// process the redirected request
handler.ProcessRequest(context);
context.ApplicationInstance.CompleteRequest();
of course there is other stuff I'm doing for making my decisions. The
piece I put that passes the request to an instance of
DefaultHttpHandler seems to be working most of the time. I am trying
this based on Brock's previous post.

I am new to some of these ways of building pages and using
IHttpHandlers in general, so it's trial and error right now.

thanks for the tips and any advice.

Dec 21 '05 #4
The stuff I posted in my last post appears to be working and doing what
I want it to do, except this code:

IHttpAsyncHandler theHandler = new DefaultHttpHandler();
theHandler.BeginProcessRequest(context, null, null);
return;

Does not allow aspx pages to be processed for Url's that do no require
remapping, ie: the pass-thru Url's. When running in the debugger for a
Url point to a .aspx that exists on disc and is not configured to be
remapped, my IHttpHandler gets called over and over and over after
hitting the code lines I pasted in above. If the Url is not for an
aspx, then it processes fine. When not running in the debugger, the
browser just says the page cannot be displayed.

Any ideas? I can paste more code snippets if needed.

Dec 22 '05 #5
I now understand what is happening. Since I have registered an
IHttpHandler in web.config such as:

<add verb="*" path="*" type="MyType"/>

and I am passing control back to DefaultHttpHandler for IIS to process
when the Url does not require remapping, IIS immediately sends it back
to ASP.NET and my handler catches the request again and the cycle
continues.

Can I somehow solve this using an IHttpModule instead but still allow
the equivalent of the following code to work?

IHttpHandler handler =
PageParser.GetCompiledPageInstance(pageLoaderVirtu alPath,
pageLoaderPhysicalPath, context);
handler.ProcessRequest(context);
context.ApplicationInstance.CompleteRequest();

Dec 22 '05 #6
John, I took your advice and I now have this working like a champ. I
disable my IHttpHandler and moved my code, slightly modified, into an
IHttpModule. Now all remapping occurs and stuff that should not be
remapped falls around an If statement and is handled normally. THanks.

Dec 22 '05 #7
Glad to have helped.

--
Regards

John Timney
Microsoft MVP

"SlimFlem" <sl******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
John, I took your advice and I now have this working like a champ. I
disable my IHttpHandler and moved my code, slightly modified, into an
IHttpModule. Now all remapping occurs and stuff that should not be
remapped falls around an If statement and is handled normally. THanks.

Dec 22 '05 #8

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

Similar topics

1
by: Generic Usenet Account | last post by:
Here's the requirement that I am trying to satisfy: Handle wildcards in STL such that the wildcard entry is encountered before non-wildcard entries while traversing containers like sets and...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
0
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our...
3
by: Adam | last post by:
Its my understanding that in asp.net 2.0 you can write an httpmodule that will acts as a wildcard handler and pass requests on to the proper engine, for instance, asp or perl for example, In the...
0
by: Tiziana Loporchio MCSD.NET | last post by:
On IIS6 I have configured a wildcard application mapping, but now when I just browse to a URL or an IP without specifying a document, it does not add the "default document" anymore. Is it a bug in...
2
by: Jan Kucera | last post by:
Hi, I have virtual MyFolder/* and MyFolder/MySubFolder/* mapped to an httphandler in the web.config file and all works perfectly on the asp.net development server. However on the IIS6/Win2003 I'm...
5
by: Advo | last post by:
Hey there. Is there any reason why redirects in my code would cause the error: "Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are...
6
by: Jan Kucera | last post by:
Hi, does anybody know about wildcard mapping ASP.NET 2 in IIS6? Any tutorial? Thanks, Jan
1
by: Lucvdv | last post by:
In my assembly.vb files, I'm using the revision/build wildcard style: <Assembly: AssemblyVersion("3.0.*")> <Assembly: AssemblyFileVersion("3.0.*")> This onkly seems to work in projects that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.