HttpHandlers for Paths with a depth greater than 1

  • Thread starter Ole Viaud-Murat
  • Start date
O

Ole Viaud-Murat

Hello,

i just asked myself if it was possible to create a HttpHandler that
listens to a specific path scheme like

~/reports/subpath1/subpath2/*.extension

Currently i just manage to get simple Paths to work, like:

~/reports/*.extension

So it seems that asp.net's HttpHandlers have a restriction to only
work with Paths of a depth of 1, making paths like ~/reports/subpath1/
subpath2/*.extension impossible to work for HttpHandlers.

I use a workaround in the handlers section of the web.config:

i change

<add ... path="reports/subpath1/*.csv" ... />

to

<add ... path="reportssubpath1/*.csv" ... />

And change the corresponding link-factory to create links that point
to that paths. But this seems to be pretty bad practive afaic.

I know, that the use of asp.net MVC would (hopefully?) "rectifiy" this
limitation of asp.net but perhaps i'm missing something? I'd like to
implement such thing now, before switching to mvc.

Would that be possible in asp.net 3.5, without the use of MVC?

thanks in advance for any hints

Ole
 
I

ib.dangelmeyr

Edit: the paths do not exist physically.

Why don't you use url-rewriting in the global.asax file?

Try something like: (Example global.asax)

<%@ Application Language="C#" %>
<script runat="server">
void Application_BeginRequest(object sender, EventArgs e)
{
string[] parts = HttpContext.Current.Request.FilePath.Split(
new char[] {'/'}, 2, StringSplitOptions.RemoveEmptyEntries);
if ( parts.Length > 0 && parts[0].ToLower() == "products" )
HttpContext.Current.RewritePath("~/products.aspx?product=" +
(parts.Length > 1 ? parts[1] : ""));
}
</script>

This example would map all requests like

http://server/products/x/y/z/abc

to the URL

http://server/products.aspx?product=x/y/z/abc

hope it helps.
 

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,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top