Application_BeginRequest issue

J

Joe

I'm trying to use the Application_BeginRequest to re-write the path but it
doesn't work on the published site when a non-existing URL is called. This
does work fine in my dev environment.

For example:
If I call www.mysite.com/UserName. I want to rewrite the UserName part. This
works fine in my dev environment but when I publish the site
Application_BeginRequest does not get called for this URL. It does however
get called for any of the existing URLs.

Is there a setting that needs to be changed in IIS maybe to make this work?

Thanks,
Joe
 
T

ThatsIT.net.au

Joe said:
I'm trying to use the Application_BeginRequest to re-write the path but it
doesn't work on the published site when a non-existing URL is called. This
does work fine in my dev environment.

For example:
If I call www.mysite.com/UserName. I want to rewrite the UserName part.
This works fine in my dev environment but when I publish the site
Application_BeginRequest does not get called for this URL. It does however
get called for any of the existing URLs.

Is there a setting that needs to be changed in IIS maybe to make this
work?

not sure

but you can redirect the 404 error page to one of your own, then you can
redirect from there to wherever you want
 
S

Steven Cheng [MSFT]

Hi Joe,

As you mentioned that the rewriting for that nonexisting path used to work
on development machine, are you using the Visual Studio test server on dev
machine? If so , this is the expected behavior because Visual Studio test
server always intercept all requests to process by ASP.NET runtime.
However, in IIS hosting scenario, by default, it only forward those
requests with the registerred extensions(such as .aspx , .ascx , .asmx ...)
to ASP.NET runtime.

For the following kind of path:

Http:// www.mysite.com/UserName

it will not be forwarded to ASP.NET runtime and be processed by IIS
directlly. I think you can consider the following means to resolve the
problem:


1. You can consider set the default document for the certain IIS site or
virtual directory so that those directory path url request will be forward
to the default document page(you configured) and you'll be able to process
the request in ASP.NET runtime:

#Setting Up Default Documents (IIS 6.0)
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d
c6eb1b4-9028-4308-9935-52b64edfad36.mspx?mfr=true

#A Complete URL Rewriting Solution for ASP.NET 2.0
http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-
for-asp.net-2.0/


2. As other member suggested, you can also configure a custom 404 error
page(use your own ASPX page) in IIS:

#Creating a Custom 404 Error Page
http://www.4guysfromrolla.com/webtech/061499-1.shtml

http://www.4guysfromrolla.com/webtech/123000-1.shtml

thus, you can get handle of those 404 error for non-existing url request in
IIS.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.











--------------------
 
J

Joe

Hi Steven,

The "Complete URL Rewriting Solution for ASP.NET 2.0" doesn't seem to cover
re-writing URLs without extensions.

If I just reconfigure IIS I guess it bypasses all the rules in IIS such as
the default document and just passes it on. In this case my default page
doesn't come up.

I'm running IIS 6.

Any other suggestions other then handeling the 404 page?

-Joe
 
G

George Ter-Saakov

With IIS 6 you do not have much choice.
The only good solution is to modify IIS settings so it would serve custom
aspx page (for example 404.aspx). in case of 404 error.

But then ASP.NET will kick in and you can rewrite URL to anything you
need....
Just be careful cause your 404.aspx page will be hit even in case some
picture is missing.


George.
 
J

Joe

Well I ended up using the code from the Complete URL Rewriting Solution for
ASP.NET 2.0 article. I just handle the default document myself.
 
S

Steven Cheng [MSFT]

Thanks for your reply Joe,

Yes, the "Complete URL Rewriting Solution for ASP.NET 2.0" article is a
complete overview of all the url rewriting part at ASP.NET site while
another article I mentioend included something about using the default
document in IIS.

Also, I'm afraid so far for request path without extension, we have to use
IIS configuration together (default document or 404 page) so as to
intercept them in ASP.NET side. This is because ASP.NET runtime is
completely hosted upon the underlying IIS framework and all requests arrive
IIS first and IIS side control whether the requests will be further
forwarded to ASP.NET side.

As far as I know, for complete Url Rewriting(include all request paths,
with extension or without), raw IIS ISAPI filter would be capable of this,
however, developing raw ISAPI filter is much more expensive than an ASP.NET
component.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
Subject: Re: Application_BeginRequest issue
Date: Mon, 21 Apr 2008 15:34:26 -0400
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top