ISAPI filter or http module

G

Guoqi Zheng

I know I can use http module in my asp.net project to rewrite url. However
that is only true for .aspx page, there are many other static page in my
application such as .htm. .asp, etc.

My question is:
1. Is it possible to map all those request (.gif, .jpg, .swf, .asp, .htm,
whatever) to my http module first?
2. Or in this situation, I have to use a ISAPI filter?
 
P

Peter Chadwick (MCP)

Hi,

You could use a HTTPHandler in .net to handle specified requests.

You write your handler (to do whatever you want) then you have to
"register" it in your web.config. In there you specify which requests
to handle. These can be from anything ("*") to just one specific file
("mypage.aspx"). And yes you can handle .gif, .jpg, .swf etc. using
this method.

If you do a search on MSDN you should be able to find a couple of
articles on writing HTTPHandlers.
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
 
M

MWells

You can use an http module if you configure IIS to handle those file-type
requests using ASP.NET.

+ Open IIS Manager
+ Select your website
+ Right-click, Properties
+ Select Home Directory tab
+ Click Configuration... button

You can see the application extension mappings here. Double click on, e.g.
the ".aspx" extension to see how the mapping to ASP.NET is setup.

You can duplicate this for all file types you want to pass through ASP.NET
(and your http module) by Adding / Editing as desired. Add one for .gif,
..jpg, .jpeg, and so on.

Note that on Server 2003 you can also do a wildcard mapping in the lower
listbox, however there are some disadvantages to this. Certain features
"break" such as default webpages. However if you have a very large number
of file types to map, you may want to explore this approach.

/// M
 
P

Peter Chadwick (MCP)

Hi,

This can be handled by specifying the default document in IIS. In the
properties of the website you can supply a list of default documents
(i.e. to try if no file is specified). It starts with files such as
default.htm, default.asp, default.aspx etc. but you can add your own.
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
 
G

Guoqi Zheng

That is what I think, but that does not work like it should be.

I think If I have a directory like http://www.mysite.com/aaaa/bbb/

IIS will check first to make sure whether that directory exists or not
before it load the default.aspx page. That direcotry is fake, so it is not
exists, so IIS return an page not found error.

Any idea?
 
P

Peter Chadwick (MCP)

Hi,

If IIS cannot find one of the default files it will return a page not
found error (because it isn't found).

I'm not really sure why you would want to try and load a page in a
directory that doesn't exist. Are you saying you want to know when a
url specifying a directory that doesn't exist is posted and handle that
in some special way, other than the not found special error?
Regards,

Peter Chadwick (MCP)
(e-mail address removed)
 
G

Guoqi Zheng

Those direcotry are created by URL rewrite. Those directories are not really
there. That is why I need the URL rewrite http module.

To make the site easily understood by people and search, we change url like
cateogry.aspx?id=2 to xxx/category/1.aspx

Any idea how can do this? Do I really have to use ISAPI filter?
 
D

David Jessee

I'm not sure that it would work....but I think it will.....

you're having to get around teh fact that IIS intercepts the request and
throws the 404 error PRIOR to the aspnet_pw getting a hold of it.

So, how about creating an ASPX doc and setting that to your custon page for
404 errors in IIS?

I know that this is a little clunky, but the issue here is that you need to
get IIS to get the request to .NET somehow...that's the only way I can think
about it.

I could be wrong, though
 
B

Ben Lovell

Hi,

Map all extensions to aspnet_isapi.dll using the wildcard mapping in server
2003 or '.*' extension in 2000 server, uncheck the 'check if file exists'
checkbox. This will let you intercept requests for folders whether or not
they physically exist.

Ben
http://bitarray.co.uk/ben
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top