0

リダイレクトであるすべてのリクエストからクエリ パラメータ「mobile」を削除したいと考えています。ページ Redirect.aspx は、訪問者を Default.aspx?mobile=1 にリダイレクトします。また、訪問者が Redirect,aspx を参照すると、最終的にはアドレス バーにパラメーターのない Default.aspx に誘導されます。私が行った手順: 現在のリクエストがリダイレクトの場合、クエリ文字列からクエリ パラメータ "mobile" を削除する必要があります。問題は次のとおりです。ステータス コードが 3xx で、クエリに「モバイル」パラメータがあるかどうかを確認していますが、この条件が true になることはありません。

リダイレクト.aspx:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    Context.Response.Redirect("Default.aspx?mobile=1");
}

ParamModule の削除:

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 またはパラメータ 'mobile' が含まれているのに、両方が同時に含まれていないのはなぜですか? また、リダイレクトのパラメータ「モバイル」を削除するにはどうすればよいですか?

4

1 に答える 1