本文介绍了如何在ashx中设置2分钟的会话...我试过这个显示会话过期错误请刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 System.Net;
使用 System.Web.SessionState;
namespace handlerTest.UI.Handler
{
public 类 AuthHandler:IHttpHandler,IRequiresSessionState
{
private static ILog log = LogManager.GetLogger( typeof (AuthHandler));
public void ProcessRequest(HttpContext context)
{
string req = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd() ;
context.Response.ContentType = application / json; charset = UTF-8
JObject jo = JObject.Parse(req);
string sessionType =( string )jo [ SessionType];
string par =( string )jo [param];
string [] paramArray = null ;
if (par.Contains(,))
{
paramArray = par.Split(,);
}
其他
{
paramArray = new string [ 1 ];
paramArray [ 0 ] = par;
}
// context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (sessionType == 1)
{
string loggedIntime = DateTime.Now.ToString( dd-MMM-yyy / hh:mm:ss);
context.Session.Add( TEST,par);
}
其他
{
}
$。ajax({
url:' Handler / AuthHandler.ashx',
data:myData,
dataType:' text',
类型:' POST',
cache: false ,
timeout: 120000 ,
解决方案
using System.Net; using System.Web.SessionState; namespace handlerTest.UI.Handler { public class AuthHandler : IHttpHandler, IRequiresSessionState { private static ILog log = LogManager.GetLogger(typeof(AuthHandler)); public void ProcessRequest(HttpContext context) { string req = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd(); context.Response.ContentType = "application/json; charset=UTF-8" JObject jo = JObject.Parse(req); string sessionType = (string)jo["SessionType"]; string par = (string)jo[param]; string[] paramArray = null; if (par.Contains(,)) { paramArray = par.Split(,); } else { paramArray = new string[1]; paramArray[0] = par; } //context.Response.Cache.SetCacheability(HttpCacheability.NoCache); if (sessionType == "1") { string loggedIntime = DateTime.Now.ToString("dd-MMM-yyy/hh:mm:ss"); context.Session.Add("TEST", par); } else { }
$.ajax({ url: 'Handler/AuthHandler.ashx', data: myData, dataType: 'text', type: 'POST', cache: false, timeout: 120000,
解决方案
这篇关于如何在ashx中设置2分钟的会话...我试过这个显示会话过期错误请刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!