Disable auto Friendly URLs in a Web Form project

Idan Shechter picture Idan Shechter · Aug 21, 2014 · Viewed 8.6k times · Source

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.

Answer

Michael Hornaday picture Michael Hornaday · Mar 8, 2016

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);
    }
}