且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除从查询字符串重定向项目?

更新时间:2023-11-15 16:57:58

您不得不重建URL,然后重定向。事情是这样的:

You'd have to reconstruct the url and then redirect. Something like this:

string url = Request.RawUrl;

NameValueCollection params = Request.QueryString;
for (int i=0; i<params.Count; i++)
{
    if (params[i].GetKey(i).ToLower() == "foo")
    {
        url += string.Concat((i==0 ? "?" : "&"), params[i].GetKey(i), "=", params.Get(i));
    }
}
Response.Redirect(url);

反正我没有测试或任何东西,但它应该工作(或者至少让你在THYE正确的方向)

Anyway, I didn't test that or anything, but it should work (or at least get you in thye right direction)