Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have the session problem.
below the code please help me.


Web.config
XML
<sessionstate mode="SQLServer" sqlconnectionstring="data source= ;integrated security=true;Initial Catalog=;pooling=false" timeout="40" allowcustomsqldatabase="true" />


Global.aspx

C#
public static int numofcount = 0;

  void Session_Start(object sender, EventArgs e) 
    {
        Session["numberofAttempts"] = numofcount;
       
    }


Login.aspx.cs

C#
private int numberofAttempts = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
      
        if (!Session.IsNewSession && Request.UrlReferrer == null)
        {
          
           Session["numberofAttempts"]=0;
        }

        if (Session["numberofAttempts"] != null)
        {
            numberofAttempts = Convert.ToInt32(Session["numberofAttempts"]);
           
        }

    }


Button_Click

Passing numberofattempts to the stored procedure and returning error message:

ObjclientManager.GetLogin(UserName.Value, EncryptedPswrd, Client.Value, numberofAttempts);


After Result from database through stored Procedure:

C#
if (objclientuserInfo.Message=="INVALID_USR_PSWRD")
      {
          numberofAttempts = Convert.ToInt32(Session["numberofAttempts"]) + 1;
          Session["numberofAttempts"] = numberofAttempts;
      }


It is working fine .
But if I will open a new tab in same browser or Different browser, then it should not store the previous numberof attempts.
It is storing the number of attempts in different browser.
Posted
Updated 26-Sep-13 18:56pm
v2

1 solution

Hi This is the most common problem in session state management.
for instance if the session timeout is 30 minutes, even if u close the browser the server will not dispose ur session for 30 mins, thats y r getting the same result even if u open in new browser.
to resolve this problem, what u have to do is like, u have to end the session, sooner by make it to one minute ( minimum time value for session in asp.net ). this can be handled when the user closes the browser u can call a javascript funtion to hit a code in c# (.cs file ) to make the session timeout at 1 minute.
this wont give u an exact result wat u expected, but with a tolerance of 1 minute it will work as it should.

Thanks
karthik
 
Share this answer
 

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