Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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
            {
              
            }


C#
$.ajax({
        url: 'Handler/AuthHandler.ashx',
        data: myData,
        dataType: 'text',
        type: 'POST',
        cache: false,
        timeout: 120000,
Posted
Updated 27-Oct-14 20:33pm
v4
Comments
Robert Welliever 28-Oct-14 1:24am    
Are you talking about Session timeout or Response timeout? You have two minutes set in the response timeout but you keep using the word Session.
sheena k 28-Oct-14 1:32am    
In this i have given session timeout:120000
But when i am running my page session is clearing within 2 sec.
Robert Welliever 28-Oct-14 1:37am    
I don't use Ajax, but that doesn't make sense that you would set a Session timeout in an Ajax call. That is not a Session timeout; it's going to be a request or response timeout. A session timeout is typically set in the web.config or dynamically during the Session load event in the Global.asax.
sheena k 28-Oct-14 2:04am    
void Session_Start(object sender, EventArgs e)
{

}

void Session_End(object sender, EventArgs e)
{
if (Session["SESSIONINFO"] != null)
{
Info Info = (Info)Session["SESSIONINFO"];
if (Info != null)
{
using (TestSrvc wbSvc = new TestSrvc())
{
wbSvc.LogoutBC(Info.BCID, DateTime.Now);
}
}
}

Session.Clear();
Session.Abandon();
}
Yes that ajax call only for request n response purpose but i set for session start nd session end like this in global.asax
Robert Welliever 28-Oct-14 2:12am    
Where? It isn't above in the code you just pasted. If you dynamically set the timeout the code would look like this: System.Web.HttpContext.Current.Session.Timeout = 120000;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900