7

I created a C# web form project in Visual Studio 2013. When I run my sample.aspx page, the page automatically uses the /sample friendly URL routing.

I want to handle the routing myself manually and not let .NET to do it automatically. How can I disable the friendly URL feature. I don't want it uninstalled via NuGet, but only disabled in code.

Liron Harel
  • 10,819
  • 26
  • 118
  • 217

3 Answers3

12

You could also just set the AutoRedirect mode to Off. This kinda gives you the best of both worlds.

    public static class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        var settings = new FriendlyUrlSettings();
        settings.AutoRedirectMode = RedirectMode.Off;
        routes.EnableFriendlyUrls(settings);
    }
}
4

In your solution, open RouteConfig.cs (in the App_Start directory) and comment out or remove this line

    routes.EnableFriendlyUrls();
Scotty
  • 1,127
  • 1
  • 7
  • 17
  • 1
    It doesn't work for me. Nothing I do make the friendly URL walk away :( – Liron Harel Jul 22 '16 at 01:32
  • 3
    @IdanShechter - I wrestled with this same thing. I couldn't figure out how it was still trying to redirect to the Friendly Urls, even with every part of it removed from my app. Then I realized it was using HTTP 301 *permanent* redirect. Clearing my browser cache fixed the issue. – Daniel Schilling May 16 '17 at 15:12
3

After uninstalling the NUGET package and deleting all the dll you must clear the browser cache

Shomaail
  • 493
  • 9
  • 30