How to use Routing ASP.NET 4 WebForms with Query String?

谁说我不能喝 提交于 2019-12-04 05:05:32

take a look at this:
http://msdn.microsoft.com/en-us/library/cc668177.aspx

basically what its saying is:

void Application_Start(object sender, EventArgs e) 
{
    RegisterRoutes(RouteTable.Routes);
}


and then:

void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("",
        "SalesReport/{locale}/{year}/{*queryvalues}", "~/sales.aspx");

    routes.MapPageRoute("SalesSummaryRoute",
        "SalesReportSummary/{locale}", "~/sales.aspx");

    routes.MapPageRoute("SalesDetailRoute",
        "SalesReportDetail/{locale}/{year}/{*queryvalues}", "~/sales.aspx",
        false);

...

    routes.MapPageRoute("ExpenseDetailRoute",
        "ExpenseReportDetail/{locale}/{year}/{*queryvalues}", "~/expenses.aspx",
        false,
        new RouteValueDictionary 
            { { "locale", "US" }, { "year", DateTime.Now.Year.ToString() } },
        new RouteValueDictionary 
            { { "locale", "[a-z]{2}" }, { "year", @"\d{4}" } },
        new RouteValueDictionary 
            { { "account", "1234" }, { "subaccount", "5678" } });
}

Does this mean that you'd have to specify every route individually for each client? (if Yes, you could have always used web.config urlMapping for this)

Instead, use the client name as part of the route and then use the client name to look up your reallylongquerystring

something like this:

routes.MapPageRoute("ClientLoginRoute","Login/{clientName}","~/forms/login.aspx")

and then on the login.aspx page access the client name etc and look up the long string

String reallyLongQueryString = Magic.GetReallyLongQueryString(Page.RouteData.Values["clientName"]);

Dim reallyLongQueryString as String = Magic.GetReallyLongQueryString(Page.RouteData.Values("clientName"))

I'm presuming here that it doesn't matter if a client knew the name of another client as they wouldn't know the login details (if that makes sense)...as they would still need to enter the credentials etc

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