views:

499

answers:

2

I'm using System.Web.Routing to have some better URL's and have come across a problem. I need to know the actual page that's handling the request.

for example a request comes in as:

/basketball/home

I need to find the page that handles that request, like:

/management/default.aspx

I'm only using the System.Web.Routing and not MVC. I have a handle to the RequestContext that contains some of the route information, but i don't see what i need.

Thanks in advance.

*** UPDATE ***

I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.

+2  A: 

Can you not retrieve this from the current HttpContext object?

Perhaps somemthing like this:

public string GetCurrentPageName() 
{ 
    string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath; 
    System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); 
    string sRet = oInfo.Name; 
    return sRet; 
}

UPDATE:
Have you tried this article?

How to: Construct a URL from a Route

You should be able to retrieve it back from the Routing table you have constructed.

Chris Ballance
This doesn't work because System.Web.HttpContext.Current.Request.Url.AbsolutePath gives me /basketball/home, which doesnt really exist.
John Boker
I have tried finding it using the routing table, but there's no public member or accessor for the handler. That article on constructing a URL from a route only gives the URL, which would be '/basketball/home' and not the aspx page.
John Boker
trying one more thing described in that article.
John Boker
yeah, the method in that article didn't work either, there isn't a way to get to the .aspx page that i can see.
John Boker
@chris-ballance thanks for your help with this.
John Boker
Perhaps using reflection you could get the current class, which would map 1:1 to your aspx file
Chris Ballance
A: 

I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.

John Boker