473,322 Members | 1,755 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,322 software developers and data experts.

How can I redirect static page requests?

We have a site that gets many requests for nonexistent pages, files and
folders. We want those requests redirected to the index page. However, for
static files (i.e. images and some other extensions) we do not want to
redirect and in that case want to return nothing.

We had been using the 404 error page to redirect but need to discriminate
the type of file being requested so that we do not return a page when an
image is required.

We'd also like to avoid the round trip of the redirect as performance is an
issue.

We are using Windows Server Web 64 bit and IIS7.

We tested some changes to the <handlerssection in web.config that is used
with IIS7 and were actually able to cause the desired behavior. However
documentation on the <handlerselement's <addsub-element is sketchy at
best. So is documentation for existing httpmodules that can be specified in
<addsub-element modules= parameter.

I am familiar with the default configuration. We made a few changes and here
is what seemed to work:
<!-- 082108 Handle known firstlook static files (1 - 9) as they had
been under StaticFile mapping with path="*" -->
<add name="StaticFile1" path="*.jpg" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile2" path="*.jpeg" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile3" path="*.gif" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile4" path="*.css" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile5" path="*.png" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile6" path="*.js" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile7" path="*.swf" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile8" path="*.vbs" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile9" path="*.ocx" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile" path="*" verb="*"
type="content.DefaultHttpHandler, content" modules="" scriptProcessor=""
resourceType="Either" requireAccess="Read" allowPathInfo="false"
preCondition="" responseBufferLimit="4194304" />

We took a survey of static files that our site used and elevated them above
the final add (path="*" verb="*") so that their handling was unchanged. Then
we changed the final (i.e. default or catch-all) add so that it used what is
a do-nothing httphandler (empty ProcessRequest method body).

We've tried some things that did not work and even experienced some site
hangs after deployment so we rolled back. This latest attempt will be tested
more thoroughly but it would be nice to understand more about this area.

Specifically, how does modules= parameter of the add sub-element work in the
context of the handler mappings?
Should only HttpModules be specified there?
Do any custom modules need to be registered?
What does it even mean to specify an HttpModule for a given handler mapping?
Would an HttpModule specified there be a replacement? Would the only
HttpModules in use be the ones specified without any others being implied?

This seems to be an entirely new context for HttpModules with very little if
any explanation as to how it works.

Also, why do some of the default add elements not specify any type=
parameter. In that case which HttpHandler is used?

If there is anyone out there with a firm understanding of this area then
whatever illuminationcan be provided would be most appreciated. I've Googled
til my fingers bled and there's not much there. Microsoft must know because
they have the source.

We just hope they are in a sharing mood....

Thanks!
--
Pat Pattillo
Aug 27 '08 #1
3 2711
Create an HttpHandler and handle the redirect through code. It will allow
you to discriminate between pages and static files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"PatP" <Pa**@discussions.microsoft.comwrote in message
news:18**********************************@microsof t.com...
We have a site that gets many requests for nonexistent pages, files and
folders. We want those requests redirected to the index page. However, for
static files (i.e. images and some other extensions) we do not want to
redirect and in that case want to return nothing.

We had been using the 404 error page to redirect but need to discriminate
the type of file being requested so that we do not return a page when an
image is required.

We'd also like to avoid the round trip of the redirect as performance is
an
issue.

We are using Windows Server Web 64 bit and IIS7.

We tested some changes to the <handlerssection in web.config that is
used
with IIS7 and were actually able to cause the desired behavior. However
documentation on the <handlerselement's <addsub-element is sketchy at
best. So is documentation for existing httpmodules that can be specified
in
<addsub-element modules= parameter.

I am familiar with the default configuration. We made a few changes and
here
is what seemed to work:
<!-- 082108 Handle known firstlook static files (1 - 9) as they had
been under StaticFile mapping with path="*" -->
<add name="StaticFile1" path="*.jpg" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile2" path="*.jpeg" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile3" path="*.gif" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile4" path="*.css" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile5" path="*.png" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile6" path="*.js" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile7" path="*.swf" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile8" path="*.vbs" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile9" path="*.ocx" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile" path="*" verb="*"
type="content.DefaultHttpHandler, content" modules="" scriptProcessor=""
resourceType="Either" requireAccess="Read" allowPathInfo="false"
preCondition="" responseBufferLimit="4194304" />

We took a survey of static files that our site used and elevated them
above
the final add (path="*" verb="*") so that their handling was unchanged.
Then
we changed the final (i.e. default or catch-all) add so that it used what
is
a do-nothing httphandler (empty ProcessRequest method body).

We've tried some things that did not work and even experienced some site
hangs after deployment so we rolled back. This latest attempt will be
tested
more thoroughly but it would be nice to understand more about this area.

Specifically, how does modules= parameter of the add sub-element work in
the
context of the handler mappings?
Should only HttpModules be specified there?
Do any custom modules need to be registered?
What does it even mean to specify an HttpModule for a given handler
mapping?
Would an HttpModule specified there be a replacement? Would the only
HttpModules in use be the ones specified without any others being implied?

This seems to be an entirely new context for HttpModules with very little
if
any explanation as to how it works.

Also, why do some of the default add elements not specify any type=
parameter. In that case which HttpHandler is used?

If there is anyone out there with a firm understanding of this area then
whatever illuminationcan be provided would be most appreciated. I've
Googled
til my fingers bled and there's not much there. Microsoft must know
because
they have the source.

We just hope they are in a sharing mood....

Thanks!
--
Pat Pattillo
Aug 27 '08 #2
Sorry, thought I'd mentioned that I'd like to avoid redirect which involves a
round trip. Without further reading maybe the title is misleading (my bad) as
I am using redirect in the loosest sense rather than the formal one.

I have had solutions involving tweaks to handlers section that gave the
correct behavior but the site would sometimes hang. That was rolled back with
nothing conclusive determined. I made changes shown in original post which
also give desired behavior and will try them but it is black magic and
nothing in doc suggests why it should work. I don't want a klooj not based on
firm understanding of supported function...thus my questions that were posed.

Do you understand function of modules= parameter? I've posed several
questions. I am trying to find out whether anyone understands how the
parameters work. Does a httpmodule specified using modules= apply to all
requests etc. etc.

Maybe someone actually knows.

Therefore I have posed some questions about how certain <handlers><add>
element parameters do work, hoping someone has familiarity.
--
Pat Pattillo
"Cowboy (Gregory A. Beamer)" wrote:
Create an HttpHandler and handle the redirect through code. It will allow
you to discriminate between pages and static files.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"PatP" <Pa**@discussions.microsoft.comwrote in message
news:18**********************************@microsof t.com...
We have a site that gets many requests for nonexistent pages, files and
folders. We want those requests redirected to the index page. However, for
static files (i.e. images and some other extensions) we do not want to
redirect and in that case want to return nothing.

We had been using the 404 error page to redirect but need to discriminate
the type of file being requested so that we do not return a page when an
image is required.

We'd also like to avoid the round trip of the redirect as performance is
an
issue.

We are using Windows Server Web 64 bit and IIS7.

We tested some changes to the <handlerssection in web.config that is
used
with IIS7 and were actually able to cause the desired behavior. However
documentation on the <handlerselement's <addsub-element is sketchy at
best. So is documentation for existing httpmodules that can be specified
in
<addsub-element modules= parameter.

I am familiar with the default configuration. We made a few changes and
here
is what seemed to work:
<!-- 082108 Handle known firstlook static files (1 - 9) as they had
been under StaticFile mapping with path="*" -->
<add name="StaticFile1" path="*.jpg" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile2" path="*.jpeg" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile3" path="*.gif" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile4" path="*.css" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile5" path="*.png" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile6" path="*.js" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile7" path="*.swf" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile8" path="*.vbs" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile9" path="*.ocx" verb="*" type=""
modules="StaticFileModule,DefaultDocumentModule,Di rectoryListingModule"
scriptProcessor="" resourceType="Either" requireAccess="Read"
allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile" path="*" verb="*"
type="content.DefaultHttpHandler, content" modules="" scriptProcessor=""
resourceType="Either" requireAccess="Read" allowPathInfo="false"
preCondition="" responseBufferLimit="4194304" />

We took a survey of static files that our site used and elevated them
above
the final add (path="*" verb="*") so that their handling was unchanged.
Then
we changed the final (i.e. default or catch-all) add so that it used what
is
a do-nothing httphandler (empty ProcessRequest method body).

We've tried some things that did not work and even experienced some site
hangs after deployment so we rolled back. This latest attempt will be
tested
more thoroughly but it would be nice to understand more about this area.

Specifically, how does modules= parameter of the add sub-element work in
the
context of the handler mappings?
Should only HttpModules be specified there?
Do any custom modules need to be registered?
What does it even mean to specify an HttpModule for a given handler
mapping?
Would an HttpModule specified there be a replacement? Would the only
HttpModules in use be the ones specified without any others being implied?

This seems to be an entirely new context for HttpModules with very little
if
any explanation as to how it works.

Also, why do some of the default add elements not specify any type=
parameter. In that case which HttpHandler is used?

If there is anyone out there with a firm understanding of this area then
whatever illuminationcan be provided would be most appreciated. I've
Googled
til my fingers bled and there's not much there. Microsoft must know
because
they have the source.

We just hope they are in a sharing mood....

Thanks!
--
Pat Pattillo

Aug 27 '08 #3

"PatP" <Pa**@discussions.microsoft.comwrote in message
news:DD**********************************@microsof t.com...
Sorry, thought I'd mentioned that I'd like to avoid redirect which
involves a
round trip. Without further reading maybe the title is misleading (my bad)
as
I am using redirect in the loosest sense rather than the formal one.
I was pinging off your wording. The redirect is not a client redirect when
you use a handler or module. It is done all server side.
Do you understand function of modules= parameter? I've posed several
questions. I am trying to find out whether anyone understands how the
parameters work. Does a httpmodule specified using modules= apply to all
requests etc. etc.
You can handle by types of files. Or you can handle by directory URL, as in
the hierarchical URL samples (now used in MVC?). I will see if I can find a
good article on this.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************

Aug 28 '08 #4

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

Similar topics

5
by: Nazir | last post by:
I am trying to do something pretty simple - but can't see how it can be done in ASP.NET. I have an aspx web page with a form which opens up a new window. The web page uses code behind to build...
0
by: e | last post by:
I've got an asp.net website using role-based, forms authentication against active directory. The website has been using the LogonUser api on every Authenticate_Request to impersonate the user as...
3
by: blu3g85 | last post by:
how to redirect a page? as in after a few sec, the page will auto direct u to another page. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----...
5
by: darrel | last post by:
I have a 'cancel' button that should reload the current page. Ie, reset the page back to it's initial state. Is the best way to do this to simply have the event handler for that button redirect...
3
by: Big Charles | last post by:
Hi, How to redirect any page to Login.aspx? I tried writting this in web.config <authentication mode="Forms"> <forms name="aucoockie" loginUrl="wf_login.aspx" protection="All" path="/" />...
2
windows_mss
by: windows_mss | last post by:
hi Programmers, In course of my project now i facing an proble that i have to Redirect the page to some other Page after the Default Session Time Expire <sessionState ...
7
by: Microsoft Newsserver | last post by:
Hi Folks. I have an issue I need some help with if thats OK. I am running Framework 2.0 using Windows Integrated Security. For most of the application we manage session timeouts without the...
8
luckysanj
by: luckysanj | last post by:
Dear Sir, How can i redirect index page to wwx.site.com/me/index.php. I have not fineshed front index page work so now i want to redirect this page to my personal information which is located...
2
by: amskape | last post by:
Hi pals, I have a problem regarding the page with listing. The listing page is arranged using pagination with 3 results per page. I need to delete each entry and redirect the page to proper...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.