Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Saturday, March 24, 2012

session variable timeout?

I have a userID stored in a session variable. I use this ID to track who entered what.
My problem is that this ID seems to get lost every now and then,resetting to 0. How can I get my server to store the userID in asession for a set duration after the last refresh?
Hi,
What is the timeout you have specified for the session in the web.config. Try increasing the timeout.
Thanks.
There is no information on timeouts in my webconfig.
Where can I find information on how to add this?

Thank you/

Hi,
Try to locate the following in your web.config

<sessionState

mode="InProc"

stateConnectionString="tcpip=127.0.0.1:42424"

sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

cookieless="false"

timeout="20"

/>
You need to change it in the above (timeout).
Thanks.


The timeout is not with my database.
The timeout is because the userID stored in the session is being lost.How do I increase the time that a session variable is stored?

Sorry, my mistake. I thought he was setting the database timeout because I saw the connection string.
I'll try it and let you know how it goes.
Thank you.

What ranganh said is correct
The session variable will persist until the time out specified in the web.config is reached
or you cleared it in the code by removing the variable from session or by using
Session.Clear() or Session.Abandon() methods.

Session variable values being lost! Why?

I am running a site using ASP.NET and have discovered that values stored in session variables are being lost when moving from one page to another. I set the values on the first page and verify that the session variables are populated. Then, on another page, where my code needs to extract the values, the session variables have values of 'nothing'.

Has anyone encountered this and, if so, do you know how to fix it?Interesting...

Are you running ASP or ASPX pages?

Do you have session state enabled on the server?

Did it used to work?
I'm running ASPX pages. Session state is enabled. It works on my PC. I have other Websites on the same server and they work. In this application, I am using the following line in the Web.config file:

<identity impersonate = "true" />

The reason I'm playing with this is that I'm trying to set-up my application so that the Website runs on the Web server, but all the files that it accesses are on another server that is not exposed to the Web.
Dumb question but has to be asked: does your client allow cookies?

I don't see think the impersonation can be causing this. I'm doing the same thing as yourself and not having any problems.
Yes, the client allows cookies. If I put all of the files that the Website uses on the same server as the Website, there is no problem. However, I get this problem when I try to access files that are on another server using impersonation.

If I remove the following line...

<identity impersonate = "true" />

...and try to access the files on another server, I get the following message: "System.IO.IOException: Logon failure: unknown user name or bad password.". If I add the above line in, it still doesn't work properly. What happens then is that a dialog pops up asking me to log-in and, if I cancel, access to the other server is denied.

If I try the following line...

<identity impersonate="true" name="domain\user" password="something" />

...as it says can be used if you lookup "impersonation" in the help files, I get the following message: "Unrecognized attribute 'name'". I think the problem must be somehow related to authentication or the way I'm trying to use impersonation. Is there some other alternative way that I can go about doing this?
You're having a great day aren't you!

Your impersonate entry looks good to me.

Does your web.config authentication look like this:

<authentication mode="Windows" />
What are you doing for IIS authentication. You using Basic or Integrated? Definitely not Anonymous right?

I'm still amazed that this authentication issue is trashing your session variables.

What is your session state mode -- "InProc"?
Yes...what a wonderful day! Well, I appreciate that you're helping me out.

The authentication mode in Web.config is "Windows".

I had the authentication mode set to Integrated and now switched it to Basic. Since the site will have SSL, I guess Basic authentication should be okay to use. Now, when I go to the site, a login dialog appears. If I type in the user name and password, I get into the site and am able to access all of the files that are on the other server. I guess there must have been some problem with me using Integrated authentication.

My next question, then, is how to bypass the login dialog that appears when the user first navigates to the site. Can I add some code somewhere or change a setting to accomplish this?

If I use the following impersonate entry...

<identity impersonate="true" name="user" password="abc" />

...I still get the "Unrecognized attribute 'name'" error. Is there somewhere specifically within the web.config file that this line is supposed to appear?

The...

<identity impersonate="true" />

...line seems to be working now, since I am able to access the files on the other server from my Web application.
did you got the answer. I am getting same problem
No, I still haven't got a reply. I'm going to try assigning permissions to the IIS account on the other server and see if that will work using anonymous authentication.
it works fine if you use netscape's browser

Session variable vs. Stored Proc

I have a registration page that captures 75% of the users data. After they
enter that info they are redirected to one of two pages depending on how
they answered a question on the registation page. My question is would it
be better to store all of the fields(15 or so) from the first page in
session variables and reference them from the next page and run ONE stored
procedure OR would it be better to run a stored procedure the first page and
then run an update procedure on the next page with the rest of the fields?
So it would be 15 session variables with 1 stored procedure or 1 stored
procedure with 1 update stored procedure?

ThanksYou could also use one ASPX page for the whole process, store the
information from page one in hidden form fields, & then submit everything at
the end using one stored procedure.

Otherwise, probably still better to store in session & run one stored proc
at the end. Otherwise if your users bail out halfway through then you're
left with half-data in the database. Also, the one-proc approach will
probably perform better.

Only reasons you might want to do two procs is if a) you want to "remember"
the user's answers from the first page if they leave halfway through & come
back later, or b) you have so many users that storing that data in the
session object is causing the web server to run out of memory, or c) you
have environmental factors that cause users to lose their session
information from time to time (e.g. non-sticky load balancing, unstable
server, app pools recycyle frequently, etc.).

--
Ben Strackany
www.developmentnow.com

<a href="http://links.10026.com/?link=http://www.developmentnow.com">dn</a
"Andy G" <ajgould@.iastate.edu> wrote in message
news:eB6pHmy1EHA.1192@.tk2msftngp13.phx.gbl...
> I have a registration page that captures 75% of the users data. After
they
> enter that info they are redirected to one of two pages depending on how
> they answered a question on the registation page. My question is would it
> be better to store all of the fields(15 or so) from the first page in
> session variables and reference them from the next page and run ONE stored
> procedure OR would it be better to run a stored procedure the first page
and
> then run an update procedure on the next page with the rest of the fields?
> So it would be 15 session variables with 1 stored procedure or 1 stored
> procedure with 1 update stored procedure?
> Thanks
The answer ought to be answered by the desired persistance of your data.

If a user fills the first page but not the 2nd, should the data be
persisted? (ie, if the user was to come back, should he/she have to fill in
the first page again, or just the 2nd).

I would do 1 update (after both pages) if the two pages together are a
single transaction (either fill both or none). I would do 2 updates only if
it was imperitive that the first page data was saved regardless of what
happened to the 2nd page - unless this was a well defined requirement, I
would likely fall back to a single update.

Also note, that there are alternatives to using sesssions to persist the
data from one page to another. For example, Sever.Transfer can be made to
preserve state without requiring sessions (not that I have anything against
sessions, but just wanted to point out to alternatives).

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/

"Andy G" <ajgould@.iastate.edu> wrote in message
news:eB6pHmy1EHA.1192@.tk2msftngp13.phx.gbl...
> I have a registration page that captures 75% of the users data. After
they
> enter that info they are redirected to one of two pages depending on how
> they answered a question on the registation page. My question is would it
> be better to store all of the fields(15 or so) from the first page in
> session variables and reference them from the next page and run ONE stored
> procedure OR would it be better to run a stored procedure the first page
and
> then run an update procedure on the next page with the rest of the fields?
> So it would be 15 session variables with 1 stored procedure or 1 stored
> procedure with 1 update stored procedure?
> Thanks
Andy G wrote:
> I have a registration page that captures 75% of the users data.
> After they enter that info they are redirected to one of two pages
> depending on how they answered a question on the registation page.
> My question is would it be better to store all of the fields(15 or
> so) from the first page in session variables and reference them from
> the next page and run ONE stored procedure OR would it be better to
> run a stored procedure the first page and then run an update
> procedure on the next page with the rest of the fields? So it would
> be 15 session variables with 1 stored procedure or 1 stored procedure
> with 1 update stored procedure?
> Thanks

Just a note: if you are going for the session-variable approach, you don't need
to store the 15 values in 15 separate session variables: you can build a class
to hold those 15 values and store that class as a single session variable.

Hans Kesting
Hans that is a good idea. Where would you say I could declare that class?

"Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
news:u0S2sI41EHA.3468@.TK2MSFTNGP14.phx.gbl...
> Andy G wrote:
> > I have a registration page that captures 75% of the users data.
> > After they enter that info they are redirected to one of two pages
> > depending on how they answered a question on the registation page.
> > My question is would it be better to store all of the fields(15 or
> > so) from the first page in session variables and reference them from
> > the next page and run ONE stored procedure OR would it be better to
> > run a stored procedure the first page and then run an update
> > procedure on the next page with the rest of the fields? So it would
> > be 15 session variables with 1 stored procedure or 1 stored procedure
> > with 1 update stored procedure?
> > Thanks
> Just a note: if you are going for the session-variable approach, you don't
need
> to store the 15 values in 15 separate session variables: you can build a
class
> to hold those 15 values and store that class as a single session variable.
> Hans Kesting
>>
>> Just a note: if you are going for the session-variable approach, you
>> don't need to store the 15 values in 15 separate session variables:
>> you can build a class to hold those 15 values and store that class
>> as a single session variable.
>>
>> Hans Kesting

Andy G wrote:
> Hans that is a good idea. Where would you say I could declare that
> class?

Anywhere you like really, as long as you can access it from your web project.
Maybe some library project in the same solution.
Don't forget to add a (project-)reference to that library project in the webproject!

Hans Kesting

Session variable vs. Stored Proc

I have a registration page that captures 75% of the users data. After they
enter that info they are redirected to one of two pages depending on how
they answered a question on the registation page. My question is would it
be better to store all of the fields(15 or so) from the first page in
session variables and reference them from the next page and run ONE stored
procedure OR would it be better to run a stored procedure the first page and
then run an update procedure on the next page with the rest of the fields?
So it would be 15 session variables with 1 stored procedure or 1 stored
procedure with 1 update stored procedure?
ThanksYou could also use one ASPX page for the whole process, store the
information from page one in hidden form fields, & then submit everything at
the end using one stored procedure.
Otherwise, probably still better to store in session & run one stored proc
at the end. Otherwise if your users bail out halfway through then you're
left with half-data in the database. Also, the one-proc approach will
probably perform better.
Only reasons you might want to do two procs is if a) you want to "remember"
the user's answers from the first page if they leave halfway through & come
back later, or b) you have so many users that storing that data in the
session object is causing the web server to run out of memory, or c) you
have environmental factors that cause users to lose their session
information from time to time (e.g. non-sticky load balancing, unstable
server, app pools recycyle frequently, etc.).
Ben Strackany
www.developmentnow.com
<a href="http://links.10026.com/?link=http://www.developmentnow.com">dn</a>
"Andy G" <ajgould@.iastate.edu> wrote in message
news:eB6pHmy1EHA.1192@.tk2msftngp13.phx.gbl...
> I have a registration page that captures 75% of the users data. After
they
> enter that info they are redirected to one of two pages depending on how
> they answered a question on the registation page. My question is would it
> be better to store all of the fields(15 or so) from the first page in
> session variables and reference them from the next page and run ONE stored
> procedure OR would it be better to run a stored procedure the first page
and
> then run an update procedure on the next page with the rest of the fields?
> So it would be 15 session variables with 1 stored procedure or 1 stored
> procedure with 1 update stored procedure?
> Thanks
>
The answer ought to be answered by the desired persistance of your data.
If a user fills the first page but not the 2nd, should the data be
persisted? (ie, if the user was to come back, should he/she have to fill in
the first page again, or just the 2nd).
I would do 1 update (after both pages) if the two pages together are a
single transaction (either fill both or none). I would do 2 updates only if
it was imperitive that the first page data was saved regardless of what
happened to the 2nd page - unless this was a well defined requirement, I
would likely fall back to a single update.
Also note, that there are alternatives to using sesssions to persist the
data from one page to another. For example, Sever.Transfer can be made to
preserve state without requiring sessions (not that I have anything against
sessions, but just wanted to point out to alternatives).
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Andy G" <ajgould@.iastate.edu> wrote in message
news:eB6pHmy1EHA.1192@.tk2msftngp13.phx.gbl...
> I have a registration page that captures 75% of the users data. After
they
> enter that info they are redirected to one of two pages depending on how
> they answered a question on the registation page. My question is would it
> be better to store all of the fields(15 or so) from the first page in
> session variables and reference them from the next page and run ONE stored
> procedure OR would it be better to run a stored procedure the first page
and
> then run an update procedure on the next page with the rest of the fields?
> So it would be 15 session variables with 1 stored procedure or 1 stored
> procedure with 1 update stored procedure?
> Thanks
>
Andy G wrote:
> I have a registration page that captures 75% of the users data.
> After they enter that info they are redirected to one of two pages
> depending on how they answered a question on the registation page.
> My question is would it be better to store all of the fields(15 or
> so) from the first page in session variables and reference them from
> the next page and run ONE stored procedure OR would it be better to
> run a stored procedure the first page and then run an update
> procedure on the next page with the rest of the fields? So it would
> be 15 session variables with 1 stored procedure or 1 stored procedure
> with 1 update stored procedure?
> Thanks
Just a note: if you are going for the session-variable approach, you don't n
eed
to store the 15 values in 15 separate session variables: you can build a cla
ss
to hold those 15 values and store that class as a single session variable.
Hans Kesting
Hans that is a good idea. Where would you say I could declare that class?
"Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
news:u0S2sI41EHA.3468@.TK2MSFTNGP14.phx.gbl...
> Andy G wrote:
> Just a note: if you are going for the session-variable approach, you don't
need
> to store the 15 values in 15 separate session variables: you can build a
class
> to hold those 15 values and store that class as a single session variable.
> Hans Kesting
>
>>
Andy G wrote:
> Hans that is a good idea. Where would you say I could declare that
> class?
>
Anywhere you like really, as long as you can access it from your web project
.
Maybe some library project in the same solution.
Don't forget to add a (project-)reference to that library project in the web
project!
Hans Kesting

Thursday, March 22, 2012

Session Variables

I have a question regarding session variables. I have a stored procedure that runs and grabs a person's jobid and stores it in a session variable. My question is: how is this session variable stored? What happens if two people are trying to access the page. If they have different jobID's, how does it know which session variable to use. When the variable saves on the server, does it have a connection to each computer accessing the server?Session variables are stored in in-process memory on the server. Each connection to the web server gets it own session and is isolated from any other session. Like threads. The session variables are not really "saved" on the server in the literal since.

You can actually have several session and, therefore, several sets of session variables from one computer. Just open another browser and connect to the application and you have another session.

I would not be concerned about how the server keep up with them; just know that you will never see the server give the wrong session variable to the wrong user.

Chad
Sessions are maintained through the use of cookies that hold a unique session id. When a person visits your site (and your site uses sessions), the response from the server will contain a cookie with a new session id that the browser will continue to send throughout the length of the person's visit.

Another user hitting the same page will get a response with a different session id cookie.

This ID is the indexer into the Session information on the server.

Session Variables

How long does it take a session variable to expire or loose its value, or
it the value stored until the client closes the browser window?

TIAHi TC,

The default is 20 minutes after the last request from the client. As the
server has no way of knowing what the client does after receiving a request,
it is not dependent upon the client.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"TC" <tcordonb@.hotmail.com> wrote in message
news:ufzuTyjhFHA.2072@.TK2MSFTNGP14.phx.gbl...
> How long does it take a session variable to expire or loose its value, or
> it the value stored until the client closes the browser window?
> TIA
How can I change this, or do I have to validate in every page that the
session variable still has some value?

Thanks

"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:eSuXaIkhFHA.1444@.TK2MSFTNGP10.phx.gbl...
> Hi TC,
> The default is 20 minutes after the last request from the client. As the
> server has no way of knowing what the client does after receiving a
> request, it is not dependent upon the client.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Ambiguity has a certain quality to it.
> "TC" <tcordonb@.hotmail.com> wrote in message
> news:ufzuTyjhFHA.2072@.TK2MSFTNGP14.phx.gbl...
>> How long does it take a session variable to expire or loose its value,
>> or it the value stored until the client closes the browser window?
>>
>> TIA
>>
>>
Hi TC,

As Sessions time out (and you can't change that, only the time interval), it
is ALWAYS a good idea to check for and handle the eventuality that some
Sessions will time out. Changing the timeout is usually a bad idea, as it
causes more memory usage on the server. Each Session allocates memory, and
the more Sessions that are alive, the more memory will be used at any given
point.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"TC" <tcordonb@.hotmail.com> wrote in message
news:umLolPmhFHA.1048@.tk2msftngp13.phx.gbl...
> How can I change this, or do I have to validate in every page that the
> session variable still has some value?
> Thanks
> "Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
> news:eSuXaIkhFHA.1444@.TK2MSFTNGP10.phx.gbl...
>> Hi TC,
>>
>> The default is 20 minutes after the last request from the client. As the
>> server has no way of knowing what the client does after receiving a
>> request, it is not dependent upon the client.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> .Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "TC" <tcordonb@.hotmail.com> wrote in message
>> news:ufzuTyjhFHA.2072@.TK2MSFTNGP14.phx.gbl...
>>> How long does it take a session variable to expire or loose its value,
>>> or it the value stored until the client closes the browser window?
>>>
>>> TIA
>>>
>>>
>>
>>