Routes dont work, its only show the real page name in link

siraero

Active member
Joined
Jan 21, 2012
Messages
32
Programming Experience
Beginner
Hi
Im looking on some routes.MapPageRoutes but i cant get it to work.
I have these link
ROOT
default..aspx
brands.aspx
service.aspx
contact.aspx
aboutus.aspx
shopping.aspx
ALL these pages is running with a masterpage
eb.master (also in the root)
And then i have the global file that have the namespace in the global file also.

when im running the pages/website and i have the default.aspx page activ, it show
www.mydomain.dk/default.aspx
when i wanted it to be
www.mydomain.dk/Butikken
Its the same problem with the others routes, can someone help me !?

VB.NET:
<%@ Application Language="VB" %>
<%@ Import Namespace="System.Web.Routing" %> 

<script runat="server">

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        
        '///// Denne linje er den der kalder Sub'en RegisterRoutes ved opstart, er meget vigtig. /////
        RegisterRoutes(RouteTable.Routes)
    End Sub
    
    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
    End Sub
        
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a session ends. 
        ' Note: The Session_End event is raised only when the sessionstate mode
        ' is set to InProc in the Web.config file. If session mode is set to StateServer 
        ' or SQLServer, the event is not raised.
    End Sub
    
    '///// Dette Sub er vigtig i Routes, sammen med import namespace System.Web.Routing. /////
    Sub RegisterRoutes(ByVal routes As RouteCollection)
        'for de forskellige link adresses/ruter skal der laven en 
        routes.MapPageRoute("", _
                            "Butikken", _
                            "~/default.aspx")
        ' adresse nr. 2
        routes.MapPageRoute("", _
                            "Brands", _
                            "~/brands.aspx")
        ' adresse nr. 3
        routes.MapPageRoute("", _
                            "Kontakt", _
                            "~/contact.aspx")
        ' adresse nr. 4
        routes.MapPageRoute("", _
                            "VoresService", _
                            "~/service.aspx")
        ' adresse nr. 5
        routes.MapPageRoute("", _
                            "OmOs", _
                            "~/aboutus.aspx")
        
        ' adresse nr. 6
        routes.MapPageRoute("", _
                            "OnlineButik", _
                            "~/shopping.aspx")
   
    End Sub
       
</script>
 
just some info.


If i have a link to "Butikken" then it works, it show www.mydomain.dk/Butikken (Real link www.mydomain.dk/default.aspx)
But first time loading the page as www.mydomain.dk then it show www.mydomain.dk/default.aspx and then my websitemap menu is not working, its not showing the css for selected/activ page/link for www.mydomain.dk/default.aspx
If i then click my logo or a link to "Butikken" then it refresh the page and show the www.mydomain.dk/Butikken and then my websitemap menu is working just fine.
How do i fix this "error" when users at visiting my site first time !?
 
The purpose of routing is to route from a url to a physical file. Bi-directional means a route can be decomposed from a url.
For initial request you can check Request.Url or something and do Response.Redirect.
 
The purpose of routing is to route from a url to a physical file. Bi-directional means a route can be decomposed from a url.
For initial request you can check Request.Url or something and do Response.Redirect.

Hi JohnH

I have tryed to make a code on the codebehind for the default.aspx page, but i get an NullRef error

VB.NET:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.UrlReferrer.AbsolutePath = "/default.aspx" Then
            Response.Redirect(Request.Url.AbsoluteUri.Replace("/default.aspx", "/Butikken"))
        End If

    End Sub
 
I said Request.Url, not Reqest.UrlReferrer. UrlReferrer is irrelevant.
 
Back
Top