How to use ASP.NET 4 WebForms routing with query string?

Firstly, it is not only MVC, WebForms.

I use routing to keep my site backward compatible for our clients while my project is organized.

I am also thinking of porting our encrypted query string to a friendlier URL. How it works, our customers need to bookmark a huge encrypted URL so that they do not guess our other customers by changing the identifier.

But instead of having this huge URL, you wanted to add a route, such as LoginClientName.aspx for each client, and have an encrypted request string hardcoded or possibly in the database.

But I see no way to add a query to MapPageRoute ..

Thought of something like that (I know that it does not work)

  routes.MapPageRoute ("MapClient1", "LoginClient1.aspx", "Login.aspx? secure = mylongquerystring");
 routes.MapPageRoute ("MapClient2", "LoginClient2.aspx", "Login.aspx? secure = differentmylongquerystring");

Now this throws an exception, since it doesn't allow it? in url .. any ideas how to do this? or is it impossible?

+7
source share
2 answers

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

basically what he says:

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", "[az]{2}" }, { "year", @"\d{4}" } }, new RouteValueDictionary { { "account", "1234" }, { "subaccount", "5678" } }); } 
+6
source

Does this mean that you will need to indicate each route individually for each client? (if so, you could always use web.config urlMapping for this)

Instead, use the customer name as part of the route, and then use the customer name to view your edit.

something like that:

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

and then on the login.aspx page, enter the client name, etc. and find the long string

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

I assume that it doesnโ€™t matter if the client knew the name of another client, since they would not know the registration data (if that makes sense) ... because they still need to enter credentials, etc.

+3
source

All Articles