ashx 使用Session最近做一个项目,调用ashx文件,其中ashx文件里面有用到Session,但是总无法获取Session,经过调试,出现的错误的原因:
大体如下
context.Session["requeststate"] = state;
查阅MSDN得到ashx文件要使用Session,必须实现Session接口,如下
public class QQCallbackHandle : IHttpHandler,System.Web.SessionState.IRequiresSessionState {
public void ProcessRequest (HttpContext context) {
var QQcontext = new QConnectSDK.Context.QzoneContext();
string state = Guid.NewGuid().ToString().Replace("-", "");
string scope = "";
var authenticationUrl = QQcontext.GetAuthorizationUrl(state, scope);
//request token, request token secret 需要保存起来
//在demo演示中,直接保存在全局变量中.真实情况需要网站自己处理
context.Session["requeststate"] = state;
context.Response.Redirect(authenticationUrl);
}
public bool IsReusable {
get {
return false;
}
}
}
大体如下
context.Session["requeststate"] = state;
查阅MSDN得到ashx文件要使用Session,必须实现Session接口,如下
public class QQCallbackHandle : IHttpHandler,System.Web.SessionState.IRequiresSessionState {
public void ProcessRequest (HttpContext context) {
var QQcontext = new QConnectSDK.Context.QzoneContext();
string state = Guid.NewGuid().ToString().Replace("-", "");
string scope = "";
var authenticationUrl = QQcontext.GetAuthorizationUrl(state, scope);
//request token, request token secret 需要保存起来
//在demo演示中,直接保存在全局变量中.真实情况需要网站自己处理
context.Session["requeststate"] = state;
context.Response.Redirect(authenticationUrl);
}
public bool IsReusable {
get {
return false;
}
}
}