0

Azure でホストされている ASP.NET C# アプリのweb.configファイルに次のコードがあります。

<!-- Turn on Custom Errors -->
<!-- Switch the mode to RemoteOnly for Retail/Production -->
<!-- Switch the mode to On for to see error pages in the IDE during development -->
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
   <error statusCode="403" redirect="ErrorPage403.aspx"/>
   <error statusCode="404" redirect="ErrorPage404.aspx"/>
</customErrors>

これは、自分のサイト ( http://ipredikt.com/ErrorPage.aspx ) をネイティブにアクセスしたときのエラーに対してはうまく機能しますが、すべてのページが異なる MasterPage を使用する Facebook バージョンのアプリも持っているため、別の URL ( http://ipredikt.com/ErrorPageFB.aspx )。

web.config に次の設定があるかのように、Facebook アプリ モードで実行しているときに、実行時に customError リダイレクト値を変更することは可能ですか。

<customErrors mode="On" defaultRedirect="ErrorPageFB.aspx">
   <error statusCode="403" redirect="ErrorPage403FB.apx"/>
   <error statusCode="404" redirect="ErrorPage404FB.apx"/>
</customErrors>

Facebook モードで実行されているかどうかを知っているのはアプリ内の個々のページであるため、これを Application スコープで設定できるとは思いません。

4

4 に答える 4

1

だからここに力ずくの解決策があります。Facebook以外のモードの404エラーのページでこれを使用しています:

  protected override void OnInit(System.EventArgs e)
  {         
     // If the user tries, for example, to navigate to" /fb/foo/bar
     // then the Request.Url.Query will be as follows after the 404 error: ?aspxerrorpath=/fb/foo/bar
     string queryString = Request.RequestContext.HttpContext.Request.Url.Query;

     string[] str = queryString.Split('=');

     if (str.Length > 0)
     {
        string[] str2 = str[1].Split('/');

        if (str2.Length > 1)
        {
           string test = str2[1].ToLowerInvariant();

           if (test == "fb")
           {
              string pathAndQuery = Request.RequestContext.HttpContext.Request.Url.PathAndQuery;
              string absolutePath = Request.RequestContext.HttpContext.Request.Url.AbsolutePath;

              string mungedVirtualPath = pathAndQuery.Replace(absolutePath, "/ErrorPage404FB.aspx");

              Response.Redirect(mungedVirtualPath);
           }
        }
     }

     base.OnInit(e);
  }

理想的ではありませんが、うまくいきます。

于 2011-06-20T08:15:17.343 に答える
1

「Facebook モード」は、ErrorPageFB.aspx への転送をトリガーするために ErrorPage.aspx でアクセスできる Session で追跡できるもののように思えます。

更新 - 以下を使用して、ブルート フォース ソリューションをかなりきれいにすることができますRequest.QueryString

protected override void OnInit(System.EventArgs e)
{         
    // If the user tries, for example, to navigate to" /fb/foo/bar
    // then the Request.Url.Query will be as follows after the 404 error: ?aspxerrorpath=/fb/foo/bar
    var requestedPath = Request.RequestContext.HttpContext.Request.QueryString["aspxerrorPath"];

    if (requestedPath.StartsWith("/fb/", StringComparison.OrdinalIgnoreCase))
    {
        var requestedUrl = Request.RequestContext.HttpContext.Request.Url;
        var pathAndQuery = requestedUrl.PathAndQuery;
        var absolutePath = requestedUrl.AbsolutePath;

        var mungedVirtualPath = pathAndQuery.Replace(absolutePath, "/ErrorPage404FB.aspx");

        Response.Redirect(mungedVirtualPath);
    }

    base.OnInit(e);
}

Request.RequestContext.HttpContext.Request実際には単に とは異なるインスタンスを返しますRequestか?

于 2011-06-20T06:17:00.937 に答える
1

こんにちは、あなたができることは、リファラーに従ってカスタムエラーページ内に別のリダイレクトを作成することだと思います-Request.UrlReferrerいつかリファラーがnullなので、必ずそれに対処してください

于 2011-06-20T06:20:23.010 に答える
0

これを行う簡単な方法はセッションを使用することですが、Web サイトでセッションを使用しない場合はいつでも Cookie を使用でき、ユーザーがエラー ページに到達したときに Cookie を調べて、新しいエラー ページにリダイレクトするかどうかを決定します。

于 2011-06-20T07:14:43.433 に答える