开发者

ASP.NET 4.0 Routing and Subfolders

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>

T开发者_C百科he links provided by Raj helped me find the answer :-)

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


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


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>


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜