简体   繁体   中英

ASP.NET 4 Webforms Routing

I'm creating a CMS, and want all request sent to Default.aspx except for the administrator route. Here is what I have:

protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.Ignore("favicon.ico");

        RouteTable.Routes.MapPageRoute("Administrator",
            "Administrator",
            "~/Admin/Default.aspx");

        RouteTable.Routes.MapPageRoute("CMS",
            "{PageURL}",
            "~/Default.aspx");
    }

This is working for a request such as:

mywebsite.com mywebsite.com/test mywebsite.com/anothertest

However, I get a resource cannot be found for:

mywebsite.com/another/test

How can I alter my routing so that it catches multiple levels?

You could try making your {PageURL} into {*PageURL} (or I even think {*} will work, but am not sure) using route wildcards.

Or, you could do something like PageURL/{*TheRest}

Just remember that wildcards are very powerful and should be put at the end of your routes since routes are figured out in order.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM