Url Rewrite Error: 404.0 - Not Found in ASP.Net

Last Reply 11 days ago By Indresh

Posted 11 days ago

global.apax file:

<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">

    //code rewwrite url
    void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute("home", "home", "~/index.aspx");
        // routes.MapPageRoute("about", "about-us", "~/AboutUs.aspx");

        //  routes.MapPageRoute("productdetails", "product_details/{nameEn}-{id}", "~/Article.aspx");


        routes.MapPageRoute("account", "account", "~/account.aspx");

        routes.MapPageRoute("login", "login", "~/login.aspx");

        routes.MapPageRoute("contactus", "contact-us", "~/contact-us.aspx");

        routes.MapPageRoute("cart", "cart", "~/cart.aspx");

        routes.MapPageRoute("paid", "thanhtoan", "~/thanhtoan.aspx");

        routes.MapPageRoute("shops", "shop/{name}/{id}", "~/shop.aspx");

        routes.MapPageRoute("productdetails", "product_details/{name}/{id}", "~/product_details.aspx");

    }

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        //code rewwrite url
        RegisterRoutes(RouteTable.Routes);

    }

web.config file:

<system.webServer>
    <!--"//code tránh lỗi khi dung url rewwrite -->
    <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>
    <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>
 </system.webServer>

i use 

<a href="/contact-us">contact</a>

==> so open contact-us.aspx is ok     but when i use code in code behind for productdetails Routing. HTTP Error 404.0 - Not Found

  LB_RANDOMSNPHAM.Text += "<a href='/product-details/"+ datatable_2.Rows[z][1].ToString()+"/" + datatable_2.Rows[z][0].ToString() + "'>";

so what is wrong?

Posted 11 days ago
yeutuihok says:
LB_RANDOMSNPHAM.Text += "<a href='/product-details/"+ datatable_2.Rows[z][1].ToString()+"/" + datatable_2.Rows[z][0].ToString() + "'>";

 Replace above code with below.

 LB_RANDOMSNPHAM.Text += "<a href='~/product-details/" + datatable_2.Rows[z][1].ToString() + "/" + datatable_2.Rows[z][0].ToString() + "'>";

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html