Saturday, March 31, 2012
Session Timeout.
We have a simple application which has login page, users login to it
and enter their contact details and all other stuff. It is working
fine. Now we have moved to new windows 2003 server. The page works
but it gets refreshed every 5 mintues and goes back to login.aspx page.
How do I fix this.
Thanks for any help.
KAdd this in your Web.config file to elongate Session to 60min for example:
<sessionState cookieless="UseCookies" mode="InProc" timeout="60" />
but add it between
<system.web> </system.web>
--
Bishoy George
bishoy@.bishoy.com
20102550399
"Sai" <kumar877@.gmail.com> wrote in message
news:1145074352.770881.44720@.u72g2000cwu.googlegroups.com...
> Friends,
> We have a simple application which has login page, users login to it
> and enter their contact details and all other stuff. It is working
> fine. Now we have moved to new windows 2003 server. The page works
> but it gets refreshed every 5 mintues and goes back to login.aspx page.
> How do I fix this.
> Thanks for any help.
> K
>
no that did not help. same thing is happening again.
Do you have code in your page to redirect to your login page? Sounds like
your session is timing out and your code is kicking in to repost. Write some
code in your session_end event handler to dump a file with a time-stamp to
tell you when the session is dying. You can trouble-shoot from there.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Sai" <kumar877@.gmail.com> wrote in message
news:1145116360.101576.258960@.i40g2000cwc.googlegroups.com...
> no that did not help. same thing is happening again.
>
Hi Alvin,
thanks for the advise. Iam inputting the values to a text file when
session times out. It is coming as 60 seconds. So the session is
timing out at every 60 seconds, but I could not find where to change
these value. I checked the web.config and machine.config and
application pools .
Let me know specific place to change this value.
thanks,
K
So you have an override somewhere in your code because the timeout value is
20 minutes by default. Search your code for that value. Alternatively, it
may be overridden in the web.config file. As a quick test, you can set
session.timeout = 10 minutes. It should stick otherwise, you have something
funky going on in your app that you either don't know about or aren't
sharing.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Sai" <kumar877@.gmail.com> wrote in message
news:1145288352.456543.4650@.t31g2000cwb.googlegroups.com...
> Hi Alvin,
> thanks for the advise. Iam inputting the values to a text file when
> session times out. It is coming as 60 seconds. So the session is
> timing out at every 60 seconds, but I could not find where to change
> these value. I checked the web.config and machine.config and
> application pools .
> Let me know specific place to change this value.
> thanks,
> K
>
Nothing in the code, nothing in the web.config. It has to be some
other place. I have seen all my code and no where I am setting these
values.
I tried changing session timeout to 10 minutes and still nothing
happens. So it got to be some where, not that simple.
Where else it can be.?
Thanks.
K
you need that check. go back and put it in there so that your application
can be resilient to memory issues. However, raise the limit to around 1gig
or so. The reason for this is that the application pool should be recycled
if an errant application (your code) decides to hog memory. Removing that
check prevents detection of this and other conditions.
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
----
"Sai" <kumar877@.gmail.com> wrote in message
news:1145306983.181641.177810@.i40g2000cwc.googlegroups.com...
> Thanks for all your help. It got fixed just now. The problem is
> Virtual memory was so low (250MB), so every time a worker process
> initiates it goes to 250 MB and it recycles, so what we did was, we
> just removed the check box next to virtual memory of application pool.
> that's it. It works...great relief.
> Thanks,
> K
>
Thanks for all your help. It got fixed just now. The problem is
Virtual memory was so low (250MB), so every time a worker process
initiates it goes to 250 MB and it recycles, so what we did was, we
just removed the check box next to virtual memory of application pool.
that's it. It works...great relief.
Thanks,
K
Where is the Virtual memory checked/set? Somewhere in IIS?
Ron
Session Timeout.
We have a simple application which has login page, users login to it
and enter their contact details and all other stuff. It is working
fine. Now we have moved to new windows 2003 server. The page works
but it gets refreshed every 5 mintues and goes back to login.aspx page.
How do I fix this.
Thanks for any help.
KAdd this in your Web.config file to elongate Session to 60min for example:
<sessionState cookieless="UseCookies" mode="InProc" timeout="60" /
but add it between
<system.web> </system.web>
--
Bishoy George
bishoy@.bishoy.com
20102550399
--------
"Sai" <kumar877@.gmail.com> wrote in message
news:1145074352.770881.44720@.u72g2000cwu.googlegro ups.com...
> Friends,
> We have a simple application which has login page, users login to it
> and enter their contact details and all other stuff. It is working
> fine. Now we have moved to new windows 2003 server. The page works
> but it gets refreshed every 5 mintues and goes back to login.aspx page.
> How do I fix this.
> Thanks for any help.
> K
no that did not help. same thing is happening again.
Do you have code in your page to redirect to your login page? Sounds like
your session is timing out and your code is kicking in to repost. Write some
code in your session_end event handler to dump a file with a time-stamp to
tell you when the session is dying. You can trouble-shoot from there.
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------
"Sai" <kumar877@.gmail.com> wrote in message
news:1145116360.101576.258960@.i40g2000cwc.googlegr oups.com...
> no that did not help. same thing is happening again.
Hi Alvin,
thanks for the advise. Iam inputting the values to a text file when
session times out. It is coming as 60 seconds. So the session is
timing out at every 60 seconds, but I could not find where to change
these value. I checked the web.config and machine.config and
application pools .
Let me know specific place to change this value.
thanks,
K
So you have an override somewhere in your code because the timeout value is
20 minutes by default. Search your code for that value. Alternatively, it
may be overridden in the web.config file. As a quick test, you can set
session.timeout = 10 minutes. It should stick otherwise, you have something
funky going on in your app that you either don't know about or aren't
sharing.
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------
"Sai" <kumar877@.gmail.com> wrote in message
news:1145288352.456543.4650@.t31g2000cwb.googlegrou ps.com...
> Hi Alvin,
> thanks for the advise. Iam inputting the values to a text file when
> session times out. It is coming as 60 seconds. So the session is
> timing out at every 60 seconds, but I could not find where to change
> these value. I checked the web.config and machine.config and
> application pools .
> Let me know specific place to change this value.
> thanks,
> K
Nothing in the code, nothing in the web.config. It has to be some
other place. I have seen all my code and no where I am setting these
values.
I tried changing session timeout to 10 minutes and still nothing
happens. So it got to be some where, not that simple.
Where else it can be.?
Thanks.
K
Thanks for all your help. It got fixed just now. The problem is
Virtual memory was so low (250MB), so every time a worker process
initiates it goes to 250 MB and it recycles, so what we did was, we
just removed the check box next to virtual memory of application pool.
that's it. It works...great relief.
Thanks,
K
you need that check. go back and put it in there so that your application
can be resilient to memory issues. However, raise the limit to around 1gig
or so. The reason for this is that the application pool should be recycled
if an errant application (your code) decides to hog memory. Removing that
check prevents detection of this and other conditions.
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------
"Sai" <kumar877@.gmail.com> wrote in message
news:1145306983.181641.177810@.i40g2000cwc.googlegr oups.com...
> Thanks for all your help. It got fixed just now. The problem is
> Virtual memory was so low (250MB), so every time a worker process
> initiates it goes to 250 MB and it recycles, so what we did was, we
> just removed the check box next to virtual memory of application pool.
> that's it. It works...great relief.
> Thanks,
> K
Where is the Virtual memory checked/set? Somewhere in IIS?
Ron
it's under one of the application pool health monitoring tabs in IIS
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------
"RonL" <sal_paradise_93@.yahoo.com> wrote in message
news:1145322157.561147.218050@.j33g2000cwa.googlegr oups.com...
> Where is the Virtual memory checked/set? Somewhere in IIS?
> Ron
I couldn't find it. I see you're talking about Windows 2003 and I'm
looking at IIS 5 and XP Pro on my local machine.
Ron
IIS 5 doesn't have these characteristics. sorry.
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-----------------
"RonL" <sal_paradise_93@.yahoo.com> wrote in message
news:1145411388.245339.46900@.i40g2000cwc.googlegro ups.com...
>I couldn't find it. I see you're talking about Windows 2003 and I'm
> looking at IIS 5 and XP Pro on my local machine.
> Ron
Thursday, March 29, 2012
session values
user logs in, and they're taken to a page with the order details and items
from their shopping cart. This order detail page checks a session variable to
check that the customer is logged in. The problem is that some users are
taken back to the login page even though they are entering the correct
username and password. We know that their cookies are on. We have a script on
another page that checks for cookies, and we've scanned through the logs and
it shows that their cookies are on. What is more baffling is that many users
are going through ok, but some are not, and there aren't any patterns as to
their browser type, or isp origin or whatnot. Anyone have a similar issue?Are you using Forms Authentication? If not, you may find that arrangement
more reliable. You can easily set up custom Forms Auth against a database.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"George" wrote:
> I'm having a problem with sessions. Basically, my site has a place where a
> user logs in, and they're taken to a page with the order details and items
> from their shopping cart. This order detail page checks a session variable to
> check that the customer is logged in. The problem is that some users are
> taken back to the login page even though they are entering the correct
> username and password. We know that their cookies are on. We have a script on
> another page that checks for cookies, and we've scanned through the logs and
> it shows that their cookies are on. What is more baffling is that many users
> are going through ok, but some are not, and there aren't any patterns as to
> their browser type, or isp origin or whatnot. Anyone have a similar issue?
>
session values
user logs in, and they're taken to a page with the order details and items
from their shopping cart. This order detail page checks a session variable t
o
check that the customer is logged in. The problem is that some users are
taken back to the login page even though they are entering the correct
username and password. We know that their cookies are on. We have a script o
n
another page that checks for cookies, and we've scanned through the logs and
it shows that their cookies are on. What is more baffling is that many users
are going through ok, but some are not, and there aren't any patterns as to
their browser type, or isp origin or whatnot. Anyone have a similar issue?Are you using Forms Authentication? If not, you may find that arrangement
more reliable. You can easily set up custom Forms Auth against a database.
Peter
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"George" wrote:
> I'm having a problem with sessions. Basically, my site has a place where a
> user logs in, and they're taken to a page with the order details and items
> from their shopping cart. This order detail page checks a session variable
to
> check that the customer is logged in. The problem is that some users are
> taken back to the login page even though they are entering the correct
> username and password. We know that their cookies are on. We have a script
on
> another page that checks for cookies, and we've scanned through the logs a
nd
> it shows that their cookies are on. What is more baffling is that many use
rs
> are going through ok, but some are not, and there aren't any patterns as t
o
> their browser type, or isp origin or whatnot. Anyone have a similar issue?
>
Monday, March 26, 2012
Session variable details
Good afternoon, I have two pages one is a select movie page the other is a view cart page, the problem is when i select a movie the details do not show up on the view cart page, can someone point me in the right direction please. below is my code;
select movie code;
<%
@dotnet.itags.org.PageLanguage="C#"Debug="true"AutoEventWireup="true"CodeFile="SelectedFilm.cs"Inherits="SelectedFilm "%><!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="en"lang="en"><
head><
metahttp-equiv="Content-Type"content="text/html; charset=iso-8859-1"/><
metaname="description"content="Description of your web page goes here."/><
metaname="keywords"content="Keywords for you web page go here. Each keyword or group of keyword phrases are separated by a comma. Keep this keyword list short and relevant to the content of this specific page and also relevant to the tile of the specific page."/><
title>Movie Stream</title><
linkrel="shortcut icon"href="shortcut.jpg"/><
linkhref="moviestream.css"rel="stylesheet"type="text/css"/><
scriptlanguage="javascript"type="text/javascript"></
script></
head><
bodystyle="background-color: #dcdcdc"><formid="form1"runat="server"><
divid="mainnav-container"><divid="mainnav"><divclass="none"><ahref="#maincontent"></a> </div><ul><li><ahref="layout.aspx"title=""><spanstyle="font-size: 11pt">Home</span></a><spanstyle="font-size: 11pt"> </span></li><li><ahref="#"title=""><spanstyle="font-size: 11pt">Contact</span></a></li><li><ahref="MS_Admin.aspx"title=""><spanstyle="font-size: 11pt">Admin Login</span></a><spanstyle="font-size: 11pt"><%
-- <li><a href="http://links.10026.com/?link=MS_Admin.aspx" title=""><span style="font-size: 11pt">Admin Login</span></a><span style="font-size: 11pt">--
%></span></li></ul></div><divid="mainnav-side"><ul><li><ahref="registered_customer.aspx"title=""><spanstyle="font-size: 12pt">Login</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="new_customer.aspx"title=""><spanstyle="font-size: 12pt">Register</span></a></li></ul></div><divclass="clear"></div></
div><!--
SITE NAME & SLOGAN
-->
<
divid="header"><
ahref="layout.aspx"title="Site name home page"></a><divid="slogan"><spanstyle="font-family: Trebuchet MS"><spanstyle="font-size: 12pt">MOVIE STREAM
<br/></span>"Delivering movies to your desk top"
</span></div></
div><
divid="breadcrumb-container"><divid="breadcrumb"><ahref="layout.aspx"title="Users will see this text ">Home</a> /<ahref="#"title="Users will see this text">Breadcrumb link</a> / Page Title</div><divid="breadcrumb-side">
Search <asp:TextBoxid="SearchWord"runat="server"></asp:TextBox> <asp:ButtonID="Button1"runat="server"Text="go"OnClick="Button1_onclick"/>
<%
-- <asp:Button /> id="Button1" type="button" value="Go" language="javascript" onclick="Button1_onclick()" />--%><asp:LabelID="lblMessage"runat="server"Text=""></asp:Label><br/> </div><divclass="clear"></div></
div><!--
CONTENT
-->
<
divid="content-container"style="background-color: #ffffff"><!--
SIDE COLUMN
-->
<divid="content-side"style="left: 1px"><p><spanstyle="font-size: 14pt; font-family: Trebuchet MS; color: gray;">Genre</span></p><ulclass="link-list-vertical"><li><ahref="MS_Action.aspx"title="Movies to give you an Adrenaline rush."><spanstyle="font-size: 12pt">Action
</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="MS_Anime.aspx"title="Animated movies."><spanstyle="font-size: 12pt">Anime</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Movies to make you laugh."><spanstyle="font-size: 12pt">Comedy</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Strong following movies"><spanstyle="font-size: 12pt">Cult</span></a><spanstyle="font-size: 12pt"></span></li><li><ahref="#"title="Facts or fiction."><spanstyle="font-size: 12pt">Documentary</span></a></li><li><spanstyle="font-size: 12pt"></span></li></ul></div><!--
MAIN COLUMN
-->
<divid="content"style="height: 1%"><aname="maincontent"id="maincontent"></a><h1><spanstyle="font-family: Trebuchet MS"></span></h1><br/><br/><asp:DataListID="DataList1"runat="server"DataSourceID="SqlDataSource1"OnSelectedIndexChanged="DataList1_SelectedIndexChanged1"><ItemTemplate>
Movie ID:
<asp:LabelID="Movie_IDLabel"runat="server"Text='<%# Eval("Movie_ID") %>'></asp:Label><br/><br/>Genre Category:
<asp:LabelID="Genre_CategoryLabel"runat="server"Text='<%# Eval("Genre_Category") %>'></asp:Label><br/><br/>Movie name:
<asp:LabelID="Movie_nameLabel"runat="server"Text='<%# Eval("Movie_name") %>'></asp:Label><br/><br/>Release date:
<asp:LabelID="Release_dateLabel"runat="server"Text='<%# Eval("Release_date") %>'></asp:Label><br/><br/>Length:
<asp:LabelID="LengthLabel"runat="server"Text='<%# Eval("Length") %>'></asp:Label><br/><br/>Synopsis:
<asp:LabelID="SynopsisLabel"runat="server"Text='<%# Eval("Synopsis") %>'></asp:Label><br/><br/>Starring:
<asp:LabelID="StarringLabel"runat="server"Text='<%# Eval("Starring") %>'></asp:Label><br/><br/>Director:
<asp:LabelID="DirectorLabel"runat="server"Text='<%# Eval("Director") %>'></asp:Label><br/><br/>Price:
<asp:LabelID="PriceLabel"runat="server"Text='<%# Eval("Price") %>'></asp:Label><br/><br/><asp:ButtonID="addToCartel"runat="server"OnClick="addToCart"Text="Select movie"/><br/></ItemTemplate></asp:DataList><asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:movie_streamConnectionString5 %>"SelectCommand="SELECT [Movie_ID], [Genre_Category], [Movie_name], [Release_date], [Length], [Synopsis], [Starring], [Director], [Price] FROM [MS_Movies] WHERE ([Movie_name] = @dotnet.itags.org.Movie_name)"><SelectParameters><asp:QueryStringParameterDefaultValue="Movie_name"Name="Movie_name"QueryStringField="Movie_name"Type="String"/></SelectParameters></asp:SqlDataSource>
<!--
FOOTER
-->
<
divid="footer"><p>Movie Stream
</p><p>382 Brent Cross Road.
</p><p>? 2007 Movie Stream. All rights reserved.
</p></
div></div><!--
SIDE 2 COLUMN
-->
<divid="content-side-2"><divclass="listbox"><divclass="header"><spanstyle="font-size: 12pt; font-family: Trebuchet MS; color: #dcdcdc;"><strongstyle="color: gray">New releases</strong></span></div><olclass="listbox"><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Deja Vu</span></b></a><spanstyle="font-family: Trebuchet MS"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Red Eye</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Dodgers</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li><li><ahref=""><b><spanstyle="font-family: Trebuchet MS; font-size: 10pt;">Basketball diaries</span></b></a><spanstyle="font-family: Trebuchet MS; font-size: 10pt;"></span></li></ol></div></div></
div></
form></
body></
html>
<%
-- <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="DataList1_SelectedIndexChanged1"><ItemTemplate>
Movie ID:
<asp:Label ID="Movie_IDLabel" runat="server" Text='<%# Eval("Movie_ID") %>'></asp:Label><br />
<br />
Genre Category:
<asp:Label ID="Genre_CategoryLabel" runat="server" Text='<%# Eval("Genre_Category") %>'></asp:Label><br />
<br />
Movie name:
<asp:Label ID="Movie_nameLabel" runat="server" Text='<%# Eval("Movie_name") %>'></asp:Label><br />
<br />
Release date:
<asp:Label ID="Release_dateLabel" runat="server" Text='<%# Eval("Release_date") %>'></asp:Label><br />
<br />
Length:
<asp:Label ID="LengthLabel" runat="server" Text='<%# Eval("Length") %>'></asp:Label><br />
<br />
Synopsis:
<asp:Label ID="SynopsisLabel" runat="server" Text='<%# Eval("Synopsis") %>'></asp:Label><br />
<br />
Starring:
<asp:Label ID="StarringLabel" runat="server" Text='<%# Eval("Starring") %>'></asp:Label><br />
<br />
Director:
<asp:Label ID="DirectorLabel" runat="server" Text='<%# Eval("Director") %>'></asp:Label><br />
<br />
Price:
<asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>'></asp:Label><br />
<br />
<asp:Button ID="addToCartie" runat="server" OnClick="addToCart" Text="Select movie" /><br />
</ItemTemplate>
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:movie_streamConnectionString5 %>"
SelectCommand="SELECT [Movie_ID], [Genre_Category], [Movie_name], [Release_date], [Length], [Synopsis], [Starring], [Director], [Price] FROM [MS_Movies] WHERE ([Movie_name] = @dotnet.itags.org.Movie_name)">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="Movie_name" Name="Movie_name" QueryStringField="Movie_name"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>--
%>selectfilm.cs code;
using
System;using
System.Data;using
System.Data.SqlClient;using
System.Configuration;using
System.Collections;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;public
partialclassSelectedFilm : System.Web.UI.Page{
protectedvoid addToCart(object sender,EventArgs e)
{
if (IsPostBack){
Session[
"Movie_IDLabel"] = ("Movie_ID");Session[
"Movie_nameLabel"] = ("Movie_name");Session[
"Genre_CategoryLabel"] = ("Genre_Category");Session[
"Movie_IDLabel"] = ("Movie_ID");Session[
"Release_dateLabel"] = ("Release_date");Session[
"LengthLabel"] = ("Length");Session[
"SynopsisLabel"] = ("Synopsis");Session[
"StarringLabel"] = ("Starring");Session[
"DirectorLabel"] = ("Director");Session[
"PriceLabel"] = ("Price");// Response.Redirect("viewcart.aspx");}
Response.Redirect(
"viewcart.aspx");}
And my view cart code;
<%
@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="viewcart.aspx.cs"Inherits="viewcart" %><!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"><
headrunat="server"><scriptlanguage="javascript"type="text/javascript">
</
script></
head><
body><formid="Form1"runat="server"><asp:Labelid="Movie_IDLabel"runat="server"Font-size="30"></asp:Label><br/><br/><asp:Labelid="Movie_nameLabel"runat="server"Font-size="30"></asp:Label><br/><br/><asp:Labelid="PriceLabel"runat="server"Font-size="30"></asp:Label>
</form>
</
body></
html>
viewcart cs code
using
System;using
System.Data;using
System.Configuration;using
System.Collections;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;using
System.Web.Configuration;using
System.Data.SqlClient;using
System.Text.RegularExpressions;
public
partialclassviewcart : System.Web.UI.Page{
void Page_Load(object sender,EventArgs e){
Movie_IDLabel.Text =
Convert.ToString(Session["Movie_ID"]);Movie_nameLabel.Text =
Convert.ToString(Session["Movie_name"]);PriceLabel.Text =
Convert.ToString(Session["Price"]);
}
Hi, I have not gone through all the code you have up there...but here is how you could do it..
On your first page set the session variables and access them on your second page...
I think you want to access the value of the textbox's or label's value in the second page rather than the name of them..
On first page...
Session["variable1"] = textBox1.value;
On the second page
string str = Session["variable1"];
Where as you are doing as the following..
Session["variable1"] = "Text" // where your text is the name of the control from what i see in the example you gave...
Hi thanks for your response, the problem is im trying to bring up a label and not a textbox, how would i go about doing this. thank you
Is there anyone out there who can help me please.
I believe you are saying that you want to get the "text value" of the label...
If thats right, you could do something like
Session["key1"] = label1.text; // this should be done on Page One
One second page, get the value from session as Session["key1"]
Thursday, March 22, 2012
session variables
Hi i have created a log in page which verifies a users login details, these details will include their access rights and user id which then allows them based on their access rights to view certain pages, this page is then meant to take the user to the home page where the uses details will be displayed in the footer of the page, my problem is i am unsure of how to store the session variables in the login page. below is my cs file, thank you.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace xxx{
publicpartialclassindex : System.Web.UI.Page
{
protectedvoid cvAuthentication_ServerValidate(Object Source, System.Web.UI.WebControls.ServerValidateEventArgs args){
SqlConnection SqlConn =null;SqlCommand SqlCmd =null;
String strConnection =null;String strSQL =null;
try
{
args.IsValid =false;strConnection =ConfigurationManager.AppSettings["strConnectionString"];
SqlConn =newSqlConnection(strConnection);SqlConn.Open();
strSQL ="SELECT * FROM tblUser WHERE Username ='" + txt_Username.Text +"' and User_Password='" + txt_Password.Text +"'";
SqlCmd =newSqlCommand(strSQL, SqlConn);
SqlCmd.Parameters.Add(newSqlParameter("Username", txt_Username.Text));SqlCmd.Parameters.Add(newSqlParameter("User_Password", txt_Password.Text));
if (SqlCmd.ExecuteScalar() !=null){
args.IsValid =true;}
}
finally
{
if (SqlConn !=null){
SqlConn.Close();
}
}
}
protectedvoid btnLogin_ServerClick(Object sender, System.EventArgs e){
if (Page.IsValid){
Session["UserAccess"] = ("Access_Right_ID");Session["UserFullName"] = ("User_Forename") +" "("User_Surname");
Session["UserID"] = ("User_ID");Session["Username"] = ("Username");Session.Timeout = 60;
Response.Redirect("home.aspx");}
}
}
}
Here is the code which the user will go to;
</div>
</td></tr>
<tr>
<tdcolspan="2"class="container_footing">
<divid="footing">
Currently logged in as<ahref="javascript:logout();"><%=Session["UserFullName"]%></a>
</div>
</td></tr>
</table>
This is the page which the homepage refences.
publicclasshome_front_page : System.Web.UI.Page
{
//protected System.Web.UI.WebControls.DataGrid dgAMPs;
protected skmDataGrid.PrettyDataGrid dgAMPs;privateDataSet dsetRecordsFound =newDataSet();
protected System.Web.UI.WebControls.DataGrid dgCustomers;privateDataView dvSelectedRecord =newDataView();
protected skmDataGrid.PrettyDataGrid dgSurveys;protectedDataSet dsetStatistics ;privatevoid Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(Session["UserAccess"]==null){
Response.Redirect("index.aspx?log_out=0",true);}
ViewState["UserAccess"] = Session["UserAccess"].ToString();
if(!IsPostBack)
{
clsxxx objxxx =newclsxxx();dsetStatistics =clsxxx.GetDataSetByIDfield("dhoc_FrontPage_Statistics","User_ID",Convert.ToInt32(Session["UserID"]));
Session["dsetStatistics"] = dsetStatistics;if(ViewState["UserAccess"].ToString()=="2")
{
objxxx.BindGrid(dsetStatistics.Tables[0],"Survey_ID",this.dgSurveys);this.dgAMPs.Visible =false;
this.dgSurveys.Visible =true;}
if(ViewState["UserAccess"].ToString()=="3" || ViewState["UserAccess"].ToString()=="4" )
{
objxxx.BindGrid(dsetStatistics.Tables[0],"Survey_ID",this.dgAMPs);this.dgSurveys.Visible =false;
this.dgAMPs.Visible =true;}
this.dgAMPs.RowSelectionEnabled =true;
}
Sorry Peter, I'm not to sure what you are asking. Can you explain a little more?
Hi Jperry4, thanks for responding, basically what i am trying to do is set some session variables in my login page which will then be passed through to other pages such as the home page. The code i have pasted above shows that in the home page it is trying to retrieve session variables from the login page(index.cs), thank you
Ok, I think I see what you are asking now. (Sorry it's Monday ;-))
First off your parameters should be like this...
strSQL ="SELECT * FROM tblUser WHERE Username = @.UserName and User_Password= @.Passsword";
SqlCmd =newSqlCommand(strSQL, SqlConn);
SqlCmd.Parameters.Add(newSqlParameter("@.Username", txt_Username.Text));
SqlCmd.Parameters.Add(newSqlParameter("@.User_Password", txt_Password.Text));
Then retrieve the data using a DataReader..
DataReader dbReader = SqlCmd.ExecuteReader();
Then if it has rows store your values in session...
if(dbReader.HasRows)
{
Session["UserAccess"] = dbReader["UserAccessFromDB"].ToString();
//etc...
}
You could do all of this in the Login button click event and redirect after the Session data has been loaded.
It that what you are looking for?
Once again John thanks for answering it is truly appreciated, I have placed the code you suggested into mine, i get this error now can you have a look and see if i have done it properly, thank you
strSQL ="SELECT * FROM tblUser WHERE Username = @.Username and User_Password= @.User_Password";
SqlCmd =newSqlCommand(strSQL, SqlConn);
SqlCmd.Parameters.Add(newSqlParameter("@.Username", txt_Username.Text));SqlCmd.Parameters.Add(newSqlParameter("@.User_Password", txt_Password.Text));DataReader dbReader = SqlCmd.ExecuteReader();
if (SqlCmd.ExecuteScalar() !=null)
{
args.IsValid =true;}
}
finally
{
if (SqlConn !=null){
SqlConn.Close();
}
}
}
protectedvoid btnLogin_ServerClick(Object sender, System.EventArgs e){
if (dbReader.HasRows){
Session["UserAccess"] = dbReader["Access_Right_ID"].ToString();Session["UserID"] = dbReader["UserID"].ToString();
Session["Username"] = dbReader["Username"].ToString();Session.Timeout = 60;
Response.Redirect("home.aspx");//etc...
}
Sorry John this is the error i am getting "CS0246: The type or namespace name 'DataReader' could not be found (are you missing a using directive or an assembly reference?), thank you.
SqlDataReader is what you have to use. For the problem you are facing validate the user credentials and if that is a valid one create the session variables and then redirect to the home page...
Hi thanks for answering, i used SqlDataReader but it now gives me this error "CS0103: The name 'dbReader' does not exist in the current context", and can you give me a bit more info about what you are suggesting im a bit of a newbie when it comes to c#, thanks
This is how my code looks right now and the error it gives is "CS0103: The name 'dbReader' does not exist in the current context"
publicpartialclassindex : System.Web.UI.Page
{
protectedvoid cvAuthentication_ServerValidate(Object Source, System.Web.UI.WebControls.ServerValidateEventArgs args){
SqlConnection SqlConn =null;SqlCommand SqlCmd =null;
String strConnection =null;String strSQL =null;
try
{
args.IsValid =false;strConnection =ConfigurationManager.AppSettings["strConnectionString"];
SqlConn =newSqlConnection(strConnection);SqlConn.Open();
strSQL ="SELECT * FROM tblUser WHERE Username = @.Username and User_Password= @.User_Password";
SqlCmd =newSqlCommand(strSQL, SqlConn);
SqlCmd.Parameters.Add(newSqlParameter("@.Username", txt_Username.Text));SqlCmd.Parameters.Add(newSqlParameter("@.User_Password", txt_Password.Text));SqlDataReader dbReader = SqlCmd.ExecuteReader();
if (SqlCmd.ExecuteScalar() !=null)
{
args.IsValid =true;}
}
finally
{
if (SqlConn !=null){
SqlConn.Close();
}
}
}
protectedvoid btnLogin_ServerClick(Object sender, System.EventArgs e){
if (dbReader.Hasrows){
Session["UserAccess"] = dbReader["Access_Right_ID"].ToString();Session["UserID"] = dbReader["UserID"].ToString();
Session["Username"] = dbReader["Username"].ToString();Session["UserFullName"] = dbReader["Username"].ToString() +" " + dbReader["User_Surname"].ToString();Session.Timeout = 60;
Response.Redirect("home.aspx");
//etc...
}
ok Peter...here it is..
You have created the sqldatareader object(dbReader) in the function "cvAuthentication_ServerValidate" and that is why dbReader object is not accessible from the function "btnLogin_ServerClick". ie..The objects declared inside a function has a scope local to that function and is not available outside. You can make it accessible by declaring it as a class level variable(inside the class but out side the function)
publicpartialclassindex : System.Web.UI.Page
{
SqlDataReader dbReader;
protectedvoid cvAuthentication_ServerValidate(Object Source, System.Web.UI.WebControls.ServerValidateEventArgs args)
.....same code as you have written but change the line
SqlDataReader dbReader = SqlCmd.ExecuteReader();
to
dbReader = SqlCmd.ExecuteReader();
i suggest you write all these ( code inside the cvAuthentication_ServerValidate) in the btnLogin_ServerClick. the sqlreader requires a open connection so make sure you are not closing it before the use of dbreader is completely over.
Hi Joe thanks for answering, if i transfer all the code from the cvAuthentication to the btnLogin will i still be able to achieve validation?
I guess you have textboxes to enter the userid and password and a login button....in that case in the validation function you can check if the user has entered his username or has left it blank sort of validations....once you are sure that the user has entered some thing proper in the fields you can check what he has eneter in the inputs fields match with the ones present in the database...in if it matches you create the session variables and redirect to the home page...
Thanks for all your help Joe, I have now placed it under the login button, it seems to be working but is now giving me a different error so i think I am making progress with it, this is the error "Invalid attempt to read when no data is present. "
and here is my code;
publicpartialclassindex : System.Web.UI.Page
{
protectedvoid btnLogin_ServerClick(Object sender, System.EventArgs e){
SqlConnection SqlConn =null;SqlCommand SqlCmd =null;
String strConnection =null;String strSQL =null;
strConnection =ConfigurationManager.AppSettings["strConnectionString"];SqlConn =newSqlConnection(strConnection);SqlConn.Open();
strSQL ="SELECT * FROM tblUser WHERE Username = @.Username and User_Password= @.User_Password";
SqlCmd =newSqlCommand(strSQL, SqlConn);
SqlCmd.Parameters.Add(newSqlParameter("@.Username", txt_Username.Text));SqlCmd.Parameters.Add(newSqlParameter("@.User_Password", txt_Password.Text));SqlDataReader dbReader = SqlCmd.ExecuteReader();
if (dbReader.HasRows)
{
Session["UserAccess"] = dbReader["Access_Right_ID"].ToString();
Session["UserID"] = dbReader["UserID"].ToString();Session["Username"] = dbReader["Username"].ToString();
Session["UserFullName"] = dbReader["Username"].ToString() +" " + dbReader["User_Surname"].ToString();Session.Timeout = 60;
Response.Redirect("home.aspx");//etc...
}
else
{
lblMessage.Text ="Please check your Username and password and try again";}
}
}
}
Now the code looks better...
SqlDataReader reads data row by row from the data base...so before you try to access the data in a datareader you have to do a read operation...in your case dbreader.read() before checking if it has data or not. But even the read operation returns a boolean value indicating there is data to be read or not. So you can make it work by just changingif (dbReader.HasRows) to if(dbReader.Read())...that should work fine..
Tuesday, March 13, 2012
Session Variables arent retrieved during Postback
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
'Login into the system
Dim l As New Security()
Dim Outcome As PPPL.Security.LoginOutcome
Outcome = l.DoLogin(Login.Text, Password.Text)
Select Case Outcome
Case Security.LoginOutcome.lgBADLOGIN
Case Security.LoginOutcome.lgBADPASSWORD
Case Security.LoginOutcome.lgINACTIVE
Case Security.LoginOutcome.lgLOCKED
Case Security.LoginOutcome.lgLOGGEDIN
Session("User") = l
If l.IsAdmin Then
EnableFixtureEntry(True)
Else
EnableFixtureEntry(False)
End If
Label3.Text = "You are logged in as " & l.User
End Select
End Sub
When the page postsback to itself, I need that session variable saved, so that I can access it. Trouble is when I try to retrieve it, I get a null value.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack Then
'Determine if the user is logged in.
Dim l As New Security()
l = Session("User")
If Not l Is Nothing Then
pnlPredictions.Controls.Add(New LiteralControl(l.User))
End If
End If
End Sub
Problem is that when it gets to evaluating whether l Is Nothing, it always returns true. Please can someone help me?Well, I always use
Session.Add("User",1)
1 being the value or whatever you assign to it.
Put a breakpoint on your assignment. After that line executes, type
? Session("User") in your Command Window. If you get a null or nothing, then it isn't setting in the first place.
Thanks for the response.
I have done that as well, and I get the same result.
When I do a response.write on the session("User") within the Button.Click Event, it does work.
The session variable seems to reset when the Postback to the page occurs.
Could you post the entire code of the page, aspx.vb along with the aspx ?
I also wonder if your class is not properly serializing. If it doesn't serialize properly it won't be stored in viewstate. However, ASP.NET compiler would most likely error when you attempt putting Session("user") = l.
This is what I would do, use Session.add("User","LOGGEDIN")
in your login code, then in the postback, put
dim st as string = Session.Item("User")
Put a breakpoint on the line right after you grab the Session.Item("user"), and see if st = "LOGGEDIN". If it does, we know its not some weird web configuration problem.
We would then ascertain your class does not properly serialize to a string (XML).
Strange things happen when trying to reteieve complex objects from viewstate or sessions whout a proper cast. A datagrid for example must be properly casted before it can be used...
try
dim s as new Security()
s = CType(Session("User"), Security)