c# - Session variables not propagating -


i have set standard asp.net webforms application on pc. login pages stores 3 session variables; username, password , redirect.

from i've seen, can use session["user"] = username or session.add("user", username); set variables.

once variables have been set, redirect page performs further authentication checks.

in receiving page, have following

protected void page_load(object s, eventargs e) {    if (!ispostback)    {       var user = (string)(session["user"]);    }  } 

when come @ user though, null.

everything on set out of box values.

further info

in caller, session set this

 if (user.username == "admin")  {      session.add("user", username.text);      session.add("pass", password.text);      session.add("redir", request.querystring["returnurl"]);      response.redirect("secondpage.aspx", false);  } 

in secondpage.aspx

    if (!ispostback)     {         returnurl = (string)(session["redir"]);         username = (string)(session["user"]);         password = (string)(session["pass"]);     } 

(returnurl, username , password simple get;set properties)

** additional

just make sure i'm not losing marbles, i've performed 2 additional tests.

first added in page_load first page following

session["fish"]="chips"; 

i read in within page2 , "chips" shows.

next created static class , assigned properties of class , tried read in within page 2 - of them null despite them being set (and tested) before redirect page2.

this has got me perplexed!

i'm assuming if statement sets session variables inside of button click? otherwise setting them right away value of empty text boxes. simplify code test see if there actual issue. put in each page_load (not in !ispostback).

page one

session["user"] = "test user"; 

page two

//set breakpoint here var user = session["user"].tostring(); 

that show if there actual issue or if there problem way trying use it. make sure session state set "inproc" in web.config file.

<system.web>       <sessionstate mode="inproc"                     timeout="20"/>       </sessionstate> </system.web> 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -