如何使用路由ASP.NET 4的WebForms与查询字符串? [英] How to use Routing ASP.NET 4 WebForms with Query String?

查看:158
本文介绍了如何使用路由ASP.NET 4的WebForms与查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这不是MVC,WebForms的只有..

First, this is not MVC, WebForms only..

我使用的路由,以保持我的网站为我们的客户后向兼容,而让我的项目组织。

I'm using routing to keep my site backwards compatible for our clients, while make my project organized.

我也想将我们的加密查询字符串到一个更友好的URL。 这是如何工作是我们的客户有书签巨大的加密网址$ P $由各地改变一个ID猜测我们的其他客户pvent他们。

I'm also thinking of moving our encrypted query string to a more friendly url. How this works is our clients have to bookmark a huge encrypted url to prevent them from guessing our other clients by changing an id around.

但不是在这个巨大的网址,想添加的路由像LoginClientName.aspx为每一个客户,并有加密的查询字符串硬codeD或者在数据库中。

But instead of having this huge url, wanted to add a route like LoginClientName.aspx for each client and have the encrypted query string hard coded or maybe in database.

但看不到的方式来查询添加到的MapPageRoute ..

But don't see a way to add a query to the MapPageRoute..

在想这样的事情(知道它不工作)

Was thinking of something like this (know it doesnt work)


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

现在,这将引发异常,因为它不允许?在网址..任何想法如何做到这一点?或者是不可能的?

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

推荐答案

一起来看看这个:
<一href="http://msdn.microsoft.com/en-us/library/cc668177.aspx">http://msdn.microsoft.com/en-us/library/cc668177.aspx

基本上就是它说的是:

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" } });
}

这篇关于如何使用路由ASP.NET 4的WebForms与查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆