asp.net-mvc – Uploadify(会话和身份验证)与ASP.NET MVC
发布时间:2020-12-15 19:39:03 所属栏目:asp.Net 来源:网络整理
导读:当我使用Authorize过滤器对一个action或uplodify使用的控制器( http://www.uploadify.com/)操作没有到达… 而且Session没有被检索。 我发现这个检索用户会话: http://geekswithblogs.net/apopovsky/archive/2009/05/06/working-around-flash-cookie-bug-in-
当我使用Authorize过滤器对一个action或uplodify使用的控制器(
http://www.uploadify.com/)操作没有到达…
而且Session没有被检索。 我发现这个检索用户会话: http://geekswithblogs.net/apopovsky/archive/2009/05/06/working-around-flash-cookie-bug-in-asp.net-mvc.aspx 但是如何使用它与[授权]过滤器和检索会话? 解决方法
要纠正这个,我建议你一个解决方案…发送aify cookie值和会话id cookie值与uploadify并重新创建会话之前检索。
这里是在视图中隐含的代码: <script> var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>"; var ASPSESSID = "<%= Session.SessionID %>"; $("#uploadifyLogo").uploadify({ ... formData: { ASPSESSID: ASPSESSID,AUTHID: auth } }); 然后在Global.asax: 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]); } else if (HttpContext.Current.Request.QueryString[session_param_name] != null) { UpdateCookie(session_cookie_name,HttpContext.Current.Request.QueryString[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]); } else if (HttpContext.Current.Request.QueryString[auth_param_name] != null) { UpdateCookie(auth_cookie_name,HttpContext.Current.Request.QueryString[auth_param_name]); } } catch { } } 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); } 瞧,用这种方法它是完全透明的。 希望它帮助一些! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 添加TwilioController基类继承后,Microsoft
- Asp.Net:将值从Page传递给UserControl
- asp.net – 在渲染到位图之前缩放WPF内容
- asp.net-mvc-3 – SelectList不显示所选项目
- entity-framework – 使用“迁移”实体框架6.0.2中的错误
- asp注入
- 强烈推荐的一个工具ReSharper
- 像TransactionScope一样使用DbTransaction
- asp.net – 触发OWIN cookie中间件设置为被动身份验证模式的
- 【ASP.NET Core】AddMvc和AddMvcCore的区别