当我使用Authorize过滤器对一个action或uplodify使用的控制器(
http://www.uploadify.com/)操作没有到达…
而且Session没有被检索。
我发现这个检索用户会话:
但是如何使用它与[授权]过滤器和检索会话?
解决方法
要纠正这个,我建议你一个解决方案…发送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); }
瞧,用这种方法它是完全透明的。
希望它帮助一些! 原文链接:https://www.f2er.com/aspnet/254905.html