不同浏览器中的会话问题。 [英] Session problem in different browser.

查看:92
本文介绍了不同浏览器中的会话问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有会话问题。

以下代码请帮帮我。





Web.config

Hi,
i have the session problem.
below the code please help me.


Web.config

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





Global.aspx





Global.aspx

public static int numofcount = 0;

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





Login.aspx.cs





Login.aspx.cs

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 < br $>


将numberofattempts传递给存储过程并返回错误消息:



ObjclientManager.GetLogin(UserName.Value, EncryptedPswrd,Client.Value,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:

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.

推荐答案

Hi
这是会话状态管理中最常见的问题。

,例如,如果会话超时为30分钟,即使你关闭浏览器,服务器也不会处理你的会话30分钟,即使你在新的浏览器中打开也会得到相同的结果。

解决这个问题,你要做的就是,你必须尽快结束会话将其设为一分钟(asp.net中会话的最小时间值)。这可以在用户关闭浏览器时处理你可以调用javascript函数来命中c#(。。c。文件)中的代码,使会话超时为1分钟。

这不会给你一个确切的结果是你预期的,但是它的容差为1分钟,它可以正常工作。



谢谢

karthik
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


这篇关于不同浏览器中的会话问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆