Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have an asp.net web form application and need to add url routing.
Had followed MSDN[^].
I have also added <modules runAllManagedModulesForAllRequests="true" > into web.config.
always return HTTP Error 404.0 - Not Found
I have looked on-line alot and tried all possible solutions with no luck

Please advise

Thanks in advance!!
Samira

What I have tried:

Global.asax.cs
C#
protected void Application_Start(object sender, EventArgs e)
        {
            urlRouting(RouteTable.Routes);
        }
        
        void urlRouting(RouteCollection routes)
        {
            routes.MapPageRoute("IC", "IC", "~/EN/en-ic.aspx");
            routes.MapPageRoute("brands", "brands", "~/EN/brands.aspx");
        }

assign href in master page
C#
if (Page.User.Identity.IsAuthenticated)
{
  brands_li.HRef = "brands";
  li_IC.HRef = "IC";
}

web.config
XML
<!-- routing -->
    <modules runAllManagedModulesForAllRequests="true" >
      <remove name="UrlRoutingModule" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </modules>
    <!--end of routing-->
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
Posted
Updated 12-Jul-18 8:56am

Could you try below -

//Global.asax
protected void Application_Start(object sender, EventArgs e)
{
    RegisterRoutes(RouteTable.Routes);
}

public void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("IC", "IC", "~/Page1.aspx");
}


Have your link as -
<asp:LinkButton ID="lnkLC" runat="server" OnClick="lnkLC_Click">IC_PAGE_TEST</asp:LinkButton>


and then have your event as -
  protected void lnkLC_Click(object sender, EventArgs e)
{
    Response.RedirectToRoute("IC");
}
 
Share this answer
 
Comments
Samira Radwan 22-Mar-17 12:40pm    
Thank you, but your solution not really different from mine, still not working
[no name] 22-Mar-17 12:42pm    
Are you trying with asp:linkbutton or anchor tag? I tried with link button n worked
Samira Radwan 22-Mar-17 12:46pm    
I have tried both, still giving 404 error
[no name] 22-Mar-17 12:48pm    
the above piece did not worked for you? Can you update your code as tried.
Samira Radwan 22-Mar-17 14:15pm    
what i found out the problem is not in your code or mine, the problem is global.asax is on the root and all my aspx files and master pages are inside a folder called (EN) not on the root. Routing works fine with any page/form that located on the main root of the project not files located inside folders!!
Did you ever find a solution? I have the same issue right now.
 
Share this answer
 
Comments
Vincent Maverick Durano 12-Jul-18 20:28pm    
Hi, Please don't reply as solution. Use comments when asking for clarity or inquiry. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900