开发者

Cannot retrieve Session value

I've written a simple code to keep a USerID with the help of session. However I can't get Session value although it's not null. I've done exactly the way microsoft official tutorial says. Here's the code:

The code on the Default.aspx

string reg开发者_如何学CCode = loginBase.getRegCodePerUser(txtLogin.Text);
Session["regCode"] = regCode;
//lblInfo.text=(string)Session["regCode"];When I check it shows the right string.It's OK
Response.Redirect("Selection.aspx");

I do not directly go to that page.I first go to Selection.aspx, then UpdateStages.

And this is the code on the other page(UpdateStages.apsx):

       if ((string)Session["connSTR"] == null && (string)Session["user"] == null)
    {
        Response.Redirect("Default.aspx");
    }
    else if ((string)Session["regCode"]!=null)
    {
        regCode=(string)Session["regCode"];
        lblInfo.Text = regCode;//Show nothing. Empty.           
    }


It might very well be that when you set the session variable:

Session["regCode"] = loginBase.getRegCodePerUser(txtLogin.Text);

That the username is not available yet and that is why it's returning an empty string, and I would assume that you are executing this code: lblStatus.Text =loginBase.getRegCodePerUser(txtLogin.Text); on a different page/after the user has logged in and that is why you get the value in the label when you assign it directly.

Put a breakpoint on where you set the Session variable and see if the value is being set.

Otherwise your session settings could be incorrect in your web.config which causes the session values to be cleared before you get to your second page where you are accessing it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜