Disable auto Friendly URLs in a Web Form project

2019-06-19 02:53发布

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.

3条回答
霸刀☆藐视天下
2楼-- · 2019-06-19 03:34

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

    routes.EnableFriendlyUrls();
查看更多
干净又极端
3楼-- · 2019-06-19 03:43

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

查看更多
够拽才男人
4楼-- · 2019-06-19 03:45

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);
    }
}
查看更多
登录 后发表回答