views:

251

answers:

3

I have a folder structure like this:

www.mysite.com/About/About.aspx

I have a link in a user control like this:

<a href="~/About/About" id="aboutLink" title="About" runat="server">About</a>

And in my RegisterRoutes() method, I have this:

routes.MapPageRoute("", "About/About/", "~/About/About.aspx");

It works but produces the following URL:

www.mysite.com/About/About

What I would like is this:

www.mysite.com/About

Is this possible with out-of-the-box 4.0 routing?

UPDATE 2 - 05-14-2010:

Apparently, I introduced an extra issue by naming the .aspx Web Form the same as the containing folder. Finally, this is what worked for me:

RouteTable.Routes.MapPageRoute("", "About/", "~/AboutUs/About.aspx");

<asp:HyperLink ID="aboutLink" NavigateUrl="~/About" 
    Text="About" runat="server"></asp:HyperLink>

The links provided by Raj helped me find the answer :-)
http://msdn.microsoft.com/en-us/library/cc668201.aspx

A: 

Your a tag links to /About/About, so, naturally, that's what you get. Did you try to make it point to /About instead? (and correspondingly change the route definition)

Or do I misunderstand the question?

Fyodor Soikin
I think I introduced an extra problem by naming the Web Form the same as the folder...
IrishChieftain
+1  A: 

The second parameter is how the URL will look and accessing the virtual page will do the trick

// Global.asax
void Application_Start(object sender, EventArgs e) 
{
    // Code that runs on application startup
    System.Web.Routing.RouteTable.Routes.MapPageRoute("", "About", "~/About/About.aspx");
}


<a href="/About" id="aboutLink" title="About" runat="server">About</a>
BrunoLM
I've edited the question and replaced "mysite" with "www.mysite.com"
IrishChieftain
Gives me a 403.14 - Forbidden
IrishChieftain
I noticed now thanks to @Fyodor. You were using relative path in a HTML control. You can't do that, you need a asp:Hyperlink, or just put the full path. I fixed it.
BrunoLM
It should work with a HTML control because I have runat="server"? Still can't get it to work; will try the Hyperlink control just to see :-)
IrishChieftain
So, is it working?
BrunoLM
+1 because you were close! See my comment to Fyodor about the naming :)
IrishChieftain
+1  A: 

Your question is not clear to me. Try this

routes.MapPageRoute("", "About/", "~/About/About.aspx"); 

Also, consider using RouteURl expressions.

http://msdn.microsoft.com/en-us/library/dd329551.aspx

http://msdn.microsoft.com/en-us/library/cc668176.aspx

Raj Kaimal
Thanks Raj, links helped me resolve it :-)
IrishChieftain