我想从所有重定向请求中删除查询参数'mobile'。 Redirect.aspx页面将访问者重定向到Default.aspx?mobile = 1。当访问者浏览到重定向,aspx时,最终他应该被引导到Default.aspx,而不在地址栏中添加参数。 我采取的步骤: 因此,如果当前请求是重定向,我必须从查询字符串中删除查询参数“mobile”。这里是问题:我正在检查状态码是否为3xx,查询是否有'mobile'参数,但这种情况永远不会等于true。检查重定向是否改变查询字符串
Redirect.aspx:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Context.Response.Redirect("Default.aspx?mobile=1");
}
RemoveParamModule:
public class RemoveParamModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.EndRequest += RewriteHandler;
}
private void RewriteHandler(object sender, EventArgs eventArgs)
{
var context = (HttpApplication)sender;
var statusCode = context.Response.StatusCode;
if (statusCode.IsInRange(300, 399) && context.Request.QueryString["mobile"] != null)
{
DeleteMobileParameter(context.Request.QueryString);
context.Response.Redirect(context.Request.Path, true);
}
}
private static void DeleteMobileParameter(NameValueCollection collection)
{
var readOnlyProperty = collection.GetType().GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
readOnlyProperty.SetValue(collection, false, null);
collection.Remove("mobile");
readOnlyProperty.SetValue(collection, true, null);
}
public void Dispose()
{
}
}
为什么模块中的请求或者具有的StatusCode = 302或参数 '移动',但从来没有同时在同一时间?我怎样才能删除重定向参数'移动'?
感谢您的解释,但我从查询字符串解析'移动'。它现在开始工作,只是因为我的故事中的Response.aspx应该用'mobile'参数来调用。 – myroman