[英]how to fix request.querystring before pageload
My previous question is urlrewriter problem: Query string is duplicated shown? 我以前的问题是urlrewriter问题:查询字符串是否重复显示?
I'm developing asp.net web site. 我正在开发asp.net网站。 But has a one problem.
但是有一个问题。 There is duplicated query string like this
www.domainname.com/default.aspx?Query=Value1&Query=Value2
I'm using to too many pages like this Request.QueryString["Query"]
. 有重复的查询字符串,例如
www.domainname.com/default.aspx?Query=Value1&Query=Value2
我正在使用太多这样的页面,例如Request.QueryString["Query"]
。 But this return Value1,Value2
. 但这返回
Value1,Value2
。 I don't want to fix this problem to too many pages. 我不想将此问题解决过多的页面。 I want to fix querystring before pageload.
我想在页面加载之前修复querystring。 I think that Maybe will write some function on global.asax.
我认为也许可以在global.asax上编写一些功能。 But i don't know to how write it.
但是我不知道怎么写。
You have a any idea? 你有什么主意吗
I beleive Request.QueryString itself is read-only. 我相信Request.QueryString本身是只读的。 You could setup your own collection containing whatever you want to use:
您可以设置自己的集合,其中包含要使用的任何内容:
public Dictionary<string, object> qsValues = new Dictionary<string, object>();
foreach (string key in Request.QueryString.Keys) {
if (Request.QueryString[key].Count > 1) {
qsValues[key] = Request.QueryString[key][0];
}
else {
qsValues[key] = Request.QueryString[key];
}
}
Or just access the first entry in the list of values for that query string parameter in your code: 或者只访问代码中该查询字符串参数的值列表中的第一项:
if (Request.QueryString["Query"].Count > 1) {
queryValue = Request.QueryString[0];
}
public static bool bi = false;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (bi == false)
{
bi = true;
Response.Redirect("MainPage.aspx?id=null");
}
else if (bi)
{
string s = Request.QueryString["id"].ToString();
if (s != "null")
{
switch (s)
{
case "News":
{
ProjectsManagment.Controls.AllNews n = new Controls.AllNews();
MainContentsAsp.Controls.Add(n);
break;
}
default:
break;
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.