1

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

IrishChieftain
  • 15,108
  • 7
  • 50
  • 91

3 Answers3

2

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
  • 8,304
  • 27
  • 18
1

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
  • 97,872
  • 84
  • 296
  • 452
0

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
  • 78,590
  • 9
  • 125
  • 172