0

I am getting familiar with Url routing and got stuck pretty fast. I am trying to adjust url of one file in root folder, so instead of "http://localhost:55805/Maps.aspx" it shows just "http://localhost:55805/maps". Simple stuff, no parameters etc. I created Global.asax file and added following code.

protected void Application_Start(object sender, EventArgs e)
        {
            routes.MapPageRoute("maproute", "maps", "~/Maps.aspx");
        }

Link I am calling looks like this.

<div id="Div6" class="menuitem"><h3><a class="fill-div" href="../Maps.aspx")">Maps</a></h3></div>

Does anyone have an idea how should I adjust the code. I experimented with various <% GetRouteUrl... %> commands, but without help. Is is caused by the fact that its not server control? Tried to use hyperlink instead, but didnt help. I am using .NET version 4.5.

Thanks a lot

2 Answers 2

1

There are several ways:

1.- Using RouteUrl expresion and HyperLink

<asp:HyperLink ID="HyperLink1" runat="server" 
    NavigateUrl="<%$RouteUrl:routename=maproute%>">
   Maps
</asp:HyperLink>

2.- Using virtual url and HyperLink

<asp:HyperLink ID="HyperLink1" runat="server" 
    NavigateUrl="~/maps">
    Maps
</asp:HyperLink>

3.- Using runat server anchor and RouteUrl expression

<a class="fill-div" href="<%$RouteUrl:routename=maproute%>" runat="server">Maps</a>

4.- Using runat server anchor and virtual url

<a class="fill-div" href="~/maps" runat="server">Maps</a>
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried to just use <a class="fill-div" href="/maps"> ?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.