5

Uploadifyで問題が発生しているので、誰かが助けてくれることを願っています。Uploadifyをアプリに入れましたが、開発ではすべて正常に機能します(VS Webサーバーを使用)。統合Windows認証を使用するテスト環境にアプリをデプロイするまで、すべて正常に機能し、チェックされました。

実際にファイルをアップロードしようとすると、ブラウザにログインプロンプトが表示されます。この時点で、正しいユーザー名とパスワードを入力しても、リクエストは完了していないようです。ブラウザにパスワードを記憶するように指示しても、ログインプロンプトが表示されます。

これが起こり始めたとき、私はFiddlerを起動して、何が起こっているのかを確認することにしました。しかし、Fiddlerを実行しているときは、問題は発生しません。

残念ながら、Fiddlerの実行をアプリを実行するための要件にすることはできません。したがって、誰かが何かアイデアを持っていますか。フォーム認証を使用するときにUploadify/flashにいくつかの問題があることは知っていますが、統合Windows認証に引き継がれるとは思いませんでした。

4

1 に答える 1

3

このページを見て諦めかけたところ、Craig at PluralSight の記事に出くわしました。これにより、IIS ではなく ASP.Net から 401 を返すというアイデアが得られました。これが、IIS で匿名認証が有効になっている理由です。

この問題を回避する手順は次のとおりです。

手順 1: IIS で匿名認証と Windows 認証を有効にします。

ステップ 2: このコードを Global.asax.cs に追加してください
クレジット/感謝: Uploadify (セッションと認証) with ASP.NET MVC
注:私のバージョンでは、このコードを機能させたいだけなので、POST リクエストのみが特別なロジックを使用します。アップロードします。つまり、GET リクエストのコードを削除します。GET をサポートする場合は、上記のリンクを参照してください。

protected void Application_BeginRequest(object sender, EventArgs e)
{
    /* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */
    try
    {
        string session_param_name = "ASPSESSID";
        string session_cookie_name = "ASP.NET_SessionId";

        if (HttpContext.Current.Request.Form[session_param_name] != null)
        {
            UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
        }

    }
    catch
    {
    }

    try
    {
        string auth_param_name = "AUTHID";
        string auth_cookie_name = FormsAuthentication.FormsCookieName;

        if (HttpContext.Current.Request.Form[auth_param_name] != null)
        {
            UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
            return; // this is an uploadify request....get out of here.
        }

    }
    catch
    {
    }

    // handle the windows authentication while keeping anonymous turned on in IIS.
    // see: https://stackoverflow.com/questions/2549914/uploadify-flash-file-upload-integrated-windows-authentication

    if (Request.ServerVariables["LOGON_USER"].Length == 0) // They haven't provided credentials yet
    {
        Response.StatusCode = 401;
        Response.StatusDescription = "Unauthorized";
        Response.End();
        return;
    }

    FormsAuthentication.SetAuthCookie(Request.ServerVariables["LOGON_USER"], true); 

}

private void UpdateCookie(string cookie_name, string cookie_value)
{
    HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
    if (null == cookie)
    {
        cookie = new HttpCookie(cookie_name);
    }
    cookie.Value = cookie_value;
    HttpContext.Current.Request.Cookies.Set(cookie);
} 

ステップ 3: Uploadify を呼び出す JavaScript を更新して、フォームの認証キーとセッション キーを含めます。

<script> 
    var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>"; 
    var ASPSESSID = "<%= Session.SessionID %>"; 

    $("#uploadifyLogo").uploadify({ 
        ... 
        scriptData: { ASPSESSID: ASPSESSID, AUTHID: auth } 
    }); 

ステップ 4: web.config を更新する

  <system.web>
    ...
    <authentication mode="Forms">
      <forms defaultUrl="/" />
    </authentication>
    ...
于 2010-11-18T23:46:07.623 に答える