locked
URL Rewriting creates extra name at the end RRS feed

  • Question

  • User-698989805 posted

    I've rewritten url for ASP.NET application that works fine. But unfortunately, I am having an issue as follows:

    Suppose, I've a link that uses id at the end to redirect to a specific product to edit. So when I click on the link, it redirects like this:

    http://localhost:56317/AddProducts/123456

    Now when I like to redirect to another link, say ProductDetails, then it becomes this:

    http://localhost:56317/AddProducts/ProductDetails

    For url rewriting, I've done this in the Global.asax file:

    routes.MapPageRoute("detailsProducts", "ProductDetails", "~/ProductDetails.aspx");
    routes.MapPageRoute("addProducts", "AddProducts", "~/AddProducts.aspx");
    routes.MapPageRoute("addProductsWithId", "AddProducts/{Code}", "~/AddProducts.aspx");

    Anything I missed here? Initially it works fine, when I click on any of the links. It redirects perfectly. But when I click on any product with ids, it creates the extra name at the end and never redirects to another links with the contents expected.

    Friday, November 23, 2018 10:26 AM

Answers

  • User753101303 posted

    Hi,

    Or could it be that you are using a link such as "ProductDetails" (ie you stay inside the same folder) rather than "/ProductDetails" (what you should see in the HTML markup) or "~/ProductDetails" ? 

    ~ is a server side notation  that allows to start from the "application root" allowing your app to work regardless if it is installed at site.com or site.com/subfolder/ (in this later case it will create a "/subfolder/ProductDetails" link rather than a "/ProductDetails" link).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 23, 2018 11:55 AM

All replies

  • User753101303 posted

    Hi,

    Or could it be that you are using a link such as "ProductDetails" (ie you stay inside the same folder) rather than "/ProductDetails" (what you should see in the HTML markup) or "~/ProductDetails" ? 

    ~ is a server side notation  that allows to start from the "application root" allowing your app to work regardless if it is installed at site.com or site.com/subfolder/ (in this later case it will create a "/subfolder/ProductDetails" link rather than a "/ProductDetails" link).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 23, 2018 11:55 AM
  • User-698989805 posted

    Hello PatriceSc! Thanks a lot and missed it earlier. Just changed the link as follows:

    ProductDetails To /ProductDetails

    Friday, November 23, 2018 2:51 PM