Default folder routes using Microsoft.AspNet.FriendlyUrls webforms

夙愿已清 提交于 2019-12-13 00:15:25

问题


I'm starting a new webforms project using Microsoft.AspNet.FriendlyUrls but want to be able to set a default route for a folder. I have a folder called news which contains news.aspx and newsitem.aspx. I'd like to be able to route as follows:

http://sitename/news - Routes to ~/news/news.aspx
http://sitename/news/news - Routes to ~/news/news.aspx
http://sitename/news/newsitem - Routes to ~/news/newsitem.aspx

The second and third routes work using the code below but not http://sitename/news

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

        routes.MapPageRoute("NewsDefault", "news", "~/news/news.aspx");

    }
}

回答1:


Found Solution

Needed to add routes.RouteExistingFiles = true;

public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings);
            routes.RouteExistingFiles = true;

            routes.MapPageRoute("NewsDefault", "news", "~/news/news.aspx");
        }


来源:https://stackoverflow.com/questions/24261737/default-folder-routes-using-microsoft-aspnet-friendlyurls-webforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!