Uploadify(闪存文件上传)和集成Windows身份验证
我在使用Uploadify时遇到了问题,希望有人可以提供帮助.我已将Uploadify放入我的应用程序,并且所有工作正常(使用VS Web服务器).一切正常并检查,直到我将应用程序部署到使用集成
Windows身份验证的测试环境中.
当我实际上去上传文件时,浏览器会显示登录提示.此时,即使您输入正确的用户名和密码,该请求似乎也无法完成,即使您告诉浏览器记住密码,它仍然会显示登录提示. 当这种情况开始发生时,我决定旋转Fiddler,看看发生了什么.但是猜猜是什么,当Fiddler正在运行问题时不会发生. 不幸的是,我无法让运行Fiddler成为运行应用程序的必要条件.因此,任何人都有任何想法.我知道在使用表单身份验证时,Uploadify / flash存在一些问题,但我认为它们并未贯彻到集成Windows身份验证. 解决方法
我看到这个页面,我几乎放弃了,但后来我在PluralSight的Craig遇到了这个
article.这给了我从ASP.Net而不是IIS返回401的想法,这就是IIS中启用匿名身份验证的原因.
以下是解决此问题的步骤. 步骤1:在IIS中启用匿名身份验证和Windows身份验证. 第2步:将此代码添加到Global.asax.cs 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步:更新javascript调用uploadify以包含表单的身份验证密钥和会话密钥. <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> ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- windows – 是否可以设置服务的处理器关联,并在重新启动后保
- 如何添加会徽到Windows文件图标?
- windows – 通过Citrix Receiver(或Citrix服务器)登录Citri
- 将本地化资源.DLL嵌入到C#中的可执行文件中?
- 如何在WindowStyle =“None”的WPF窗口中执行MinWidth&
- windows-xp – 如何创建自己的Windows XP键盘映射?
- Window RabbitMq安装
- windows-server-2008 – 通过Powershell创建网络打印机
- windows-server-2012 – 有没有办法同时更改多台服务器上的
- windows – VBS:检查IP地址并打开URL(但只有一次)