473,805 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2546
> 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.Rew ritePath prior to the HttpApplication 's MapHandler
execution step (which comes inbetween ResolveRequestC ache and AcquireRequestS tate).
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.redire ct 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******** *************@g 14g2000cwa.goog legroups.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..

IHttpAsyncHandl er theHandler = new DefaultHttpHand ler();
theHandler.Begi nProcessRequest (context, null, null);
return;

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

string pageLoaderVirtu alPath =
ConfigurationMa nager.AppSettin gs["pageLoaderVirt ualPath"];
string pageLoaderPhysi calPath =
context.Server. MapPath(pageLoa derVirtualPath) ;

// get an instance to the generic page loader aspx page
IHttpHandler handler =
PageParser.GetC ompiledPageInst ance(pageLoader VirtualPath,
pageLoaderPhysi calPath, context);

// process the redirected request
handler.Process Request(context );
context.Applica tionInstance.Co mpleteRequest() ;
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
DefaultHttpHand ler 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:

IHttpAsyncHandl er theHandler = new DefaultHttpHand ler();
theHandler.Begi nProcessRequest (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 DefaultHttpHand ler 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.GetC ompiledPageInst ance(pageLoader VirtualPath,
pageLoaderPhysi calPath, context);
handler.Process Request(context );
context.Applica tionInstance.Co mpleteRequest() ;

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.goo glegroups.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
3231
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 maps. I have come up with two approaches, one using inheritance and the other using composition. I am unable to decide which one is better. The sample source code follows.
1
7281
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 database field containing "somestring". Is there a way to avoid the need for the asterisks? This would make it easier for the users and also I wouldn't have to explain that asterisks are required when performing a wildcard search.
0
1560
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 app has about 50 file extensions that we map in IIS and handle in our HTTPHandler to catch the reference and then lookup the correct content from a database. In addition, we do some magic in a HTTPModule to rewrite paths for file types we don't...
3
2884
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 past I believe if it wasn't an aspx file, things didnt work right. Can anyone provide input if this really is the case now?
0
1070
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 IIS 6.0 ? Does anyone know a workaround? Or does anyone have code to replace the "default document settings" in an isapifilter? I don't have any clue how to do that. Any help would be very much appreciated Tiziana
2
2894
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 getting 404 error, not even the asp.net one, so I guess the IIS is blocking the request. I would uncheck to verify that file exists if it would be for special extension, but this is wildcarded so I don't know what to do... any solution?
5
1643
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 blocked." If that is whats causing the problems? My code has been uploaded to http://rafb.net/paste/results/NcOw3L40.html instead of filling this post up.
6
3099
by: Jan Kucera | last post by:
Hi, does anybody know about wildcard mapping ASP.NET 2 in IIS6? Any tutorial? Thanks, Jan
1
3732
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 were originally created under VS.Net 2003. The proper version number is generated as expected, assembly version and file version of the compiled executable are both 3.0.xxxx.yyyyy.
0
9718
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
9596
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
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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
7649
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
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.