Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > Problem with Session in .NET c# help please

Reply
Thread Tools

Problem with Session in .NET c# help please

 
 
maffarazo maffarazo is offline
Junior Member
Join Date: Mar 2012
Posts: 2
 
      03-19-2012
Hi, i'm working with a website and im just trying to do something simple for now.
I can't get my Sessions working in the master page that i set up in the content page.
Here's a piece of my code in the master page:

if (Page.IsPostBack == true)
{
string name = Session["namn"].ToString();
namn.Text = Session["namn"].ToString();
Response.Write(Session["namn"].ToString());
}

and here's some code from my content page:

protected void button_click(object sender, EventArgs e)
{
OleDbConnection DB = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" + Server.MapPath("../App_Data/Solfilmdata.mdb"));
DB.Open();



OleDbCommand info = new OleDbCommand("SELECT * FROM users WHERE anv='"+username.Text+"' AND pw='"+pw.Text+"'", DB);

OleDbDataReader read = info.ExecuteReader();
read.Read();



if (read.HasRows == true)
{
Session["namn"] = read["anv"].ToString();
Session["epost"] = read["e-post"].ToString();
Session["id"] = read["behorighet"].ToString();


}
else
{
fel.Visible = true;

}
read.Close();
DB.Close();

}

In the master page i have a textbox that should state the username, so at first it's just visitor and then when i'm logging in i'm setting up a session for the username but when i try to use that session in the masterpage it says it doesnt exist. and if i do a empty session in the masterpage then it doesnt change. so basicly i have two sessions, one for master page and one for the content pages.
please help and thanks in advance


Found the solution, just changed the code in the master page to:

if (Session["namn"] == null)
{
namn.Text = "Besökare";
}
else
{
namn.Text ="Välkommen " + Session["namn"].ToString();
}

since it just kept changing the session back to the default setting in master page i removed it entirely from the masterpage.
 

Last edited by maffarazo; 03-19-2012 at 12:11 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session Timeout problems-web.confg session state and IIS session s =?Utf-8?B?Um9iSEs=?= ASP .Net 4 04-11-2007 04:52 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
Session State - What does it take to establish one single ASP.NET session per "browser session" Jeff Smythe ASP .Net 3 01-02-2004 04:10 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM
How can I "know" the difference between a session timed out and a session that did session.abort? Jazzis ASP General 2 09-23-2003 07:16 AM



Advertisments