468,136 Members | 1,406 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,136 developers. It's quick & easy.

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 2479
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Nazir | last post: by
reply views Thread by e | last post: by
3 posts views Thread by blu3g85 | last post: by
7 posts views Thread by Microsoft Newsserver | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.