Sorry for the delay, I have tried posting the project as an attachment,
isn't working, so here is the code:
Default.aspx has no code, just the login control. Code is below:
namespace BookTrack.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
/// <summary>
/// Summary description for WebUserControl1.
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtUserName;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.Label txtError;
protected System.Web.UI.WebControls.Button btnCheckLogin;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
txtError.Text="";
Session["UserID"]="";
Session["SecurityLevel"]="";
Session["UserName"]="";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnCheckLogin.Click += new
System.EventHandler(this.btnCheckLogin_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnCheckLogin_Click(object sender, System.EventArgs e)
{
Auth Authentication = new Auth();
try
{
Session["UserID"]=Authentication.GetUserID(txtUserName.Text,txtPassword.Text
Session["SecurityLevel"]=Authentication.GetSecurityLevel((int)Session["UserI
D"]);
Session["UserName"]=txtUserName.Text;
Session["PassChange"]=txtUserName.Text;
txtError.Text="";
Server.Transfer(Authentication.GetMainMenu((int)Session["SecurityLevel"]));
}
catch
{
Session["UserID"]="";
Session["SecurityLevel"]="";
Session["UserName"]="";
txtError.Text="You have entered incorrect user login credentials, please try
again";
}
}
}
}
From there, they get sent to a menu based off of the function called in the
CheckLogin_Click function. The Auth class is just a class I am using for DB
connection items.
Depending on who you log in as, you go to a main menu (different menu
depending on your credentials). Each menu (right now) is a blank page, with
the LoginStatusBar user control, giving information as to who they are
logged in as. The code for the LoginStatusBar.ascx.cs is below:
namespace BookTrack.UserControls
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for LoginStatusBar.
/// </summary>
public class LoginStatusBar : System.Web.UI.UserControl
{
int LogOutFlag=0;
HttpContext current = HttpContext.Current;
Auth Authenticate = new Auth();
protected System.Web.UI.WebControls.Label lblUserName;
protected System.Web.UI.WebControls.Button btnLogout;
protected System.Web.UI.WebControls.Label lblSecurity;
private void Page_Load(object sender, System.EventArgs e)
{
if(LogOutFlag==0)
{
try
{
lblUserName.Text="Logged in using: " +
current.Session["UserName"].ToString();
lblSecurity.Text="Security Level: " +
Authenticate.GetSecurityLevelText((int)current.Session["SecurityLevel"]);
}
catch
{
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLogout.Click += new System.EventHandler(this.btnLogout_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnLogout_Click(object sender, System.EventArgs e)
{
LogOutFlag=1;
Server.Transfer("../Default.aspx");
}
}
}
Up to this point, everything works fine.
One of the menus, I created a button and have it using Server.Transfer to
move to a password change page. It again has the same login status bar,
however this is where things break. It will produce the 'Logged in using:"
piece, and that is it. The "Security Level:" piece never shows up. In the
main page, I created a label to get the session variable, and it produces
nothing. The code for the Password Change.ascx.cs is below:
namespace BookTrack.UserControls
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for PasswordChange.
/// </summary>
public class PasswordChange : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button btnChangePassword;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox txtConfirmPassword;
protected System.Web.UI.WebControls.TextBox txtNewPassword;
protected System.Web.UI.WebControls.TextBox txtOldPassword;
protected System.Web.UI.WebControls.Label lblUserName;
protected System.Web.UI.WebControls.CompareValidator vldNewPass;
Auth Authenticate = new Auth();
private void Page_Load(object sender, System.EventArgs e)
{
lblUserName.Text=Session["UserName"].ToString();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnChangePassword.Click += new
System.EventHandler(this.btnChangePassword_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnChangePassword_Click(object sender, System.EventArgs e)
{
try
{
if((bool)Authenticate.ChangePassword((string)Session["UserName"],txtOldPassw
ord.Text,txtNewPassword.Text))
{
Server.Transfer(Authenticate.GetMainMenu((int)Session["SecurityLevel"]));
}
}
catch
{
}
}
}
}
If you need any more info, please let me know.
Paul
Alvin Bruney said:
Sure, post the code which reproduces the problem.
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Paul Yanzick said:
I should also mention I tried using httpcontext too, same thing...
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
i really have no idea. if you can't figure this out, i 'd be happy
to
look
at the code
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Thanks for the suggestion! I do have one question though, that being
the
case, why does it work once, but not once I move on from that page?
Thanks
Paul
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
you have custom controls on that page? custom controls cannot directly
access session, you need to first get a reference to the session
object
from
httpcontext.current.
If that still doesn't work, you will need to put code to display the
session
variable in the page load and troubleshoot from there
if(Session["UserName"]!= null)
Response.Write("<script>alert('" + Session["UserName"].ToString()
+
"')</script>");
should display something
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Hello!
The session state information in the web.config is as follows:
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
There is no <pages> element in the Web.config. I want to have the
session
variables be available to all of the pages in the project.
Most of the variables that are in the session state are
strings,
so
I
use
(string) to cast them. For example, in the status bar user control,
I
use:
lblUserName.Text="Logged in using: " +
Session["UserName"].ToString();
lblSecurity.Text="Security Level: " +
Authenticate.GetSecurityLevelText((int)Session["SecurityLevel"]);
The first line accesses the session directly, and uses
ToString()
to
get
the
info. The second line I am casting it to an integer to throw into
the
function. The funny thing with these and the status bar is
once
it
logs
on
and takes you to the menu, all of the info is currect, however
if
I
move
past that, the first line produces 'Logged in using:' and that is
it,
while
the second line produces absolutely nothing.
Thanks for your help!
Paul
Hi Paul,
I don't receive any errors, there just isn't anything that
appears
in
these
fields. Each page has sessions enabled. If you have any
suggestions,
PLEASE let me know!
You mentioned each page had session enabled. Is there a
chance
the
session is disabled in web.config? What does your
element
look like?
Also, do you happen to have a <pages> element in web.config that
disables the session state for certain files?
Also, how do you cast values you read from the Session object?