Bulding off this code, I put this code in my master page:
<div id="userLoggedIn" runat="server">
</div>
Then in my Page_Load method, I put this code:
// if user is logged in, set the innerhtml of the userLoggedIn div to show the user name
// else, set the text telling the user how to log in.if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{
string userName = "<p>Hello, " + System.Web.HttpContext.Current.User.Identity.Name +
"! Not you? <a href=\"Default.aspx\">Click here to log in.</a><p>";
userLoggedIn.InnerHtml = userName;
}
else
{
string userName = "<p><a href=\"week2.aspx\">Click here to log in.</a><p>";
userLoggedIn.InnerHtml = userName;
}
Now the user name displays when the user is logged in.
I saw this post which is pretty much what I am looking for except that I'm not using the Membership. I am validating users against oracle table. Is there a way to display username as they login to the page when connecting to oracle table???
How can I store the username in Session? I know you add the Label.Text = Session["UserName"].ToString(); in the default page. Can you tell me step by step in storing username? I am using Oracle database.
Somehow I get his error: Object reference not set to an instance of an object
richsoryu
Member
12 Points
1 Post
Re: Display user name in the header when logged in
Feb 22, 2009 06:59 AM|LINK
Bulding off this code, I put this code in my master page:
Then in my Page_Load method, I put this code:
Now the user name displays when the user is logged in.
Thank you for answering this guy's questions. :)
chetan.sarod...
All-Star
65709 Points
11133 Posts
Re: Display user name in the header when logged in
Feb 24, 2009 02:22 AM|LINK
Thats nice
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Aug 25, 2009 09:10 PM|LINK
Hello-
I saw this post which is pretty much what I am looking for except that I'm not using the Membership. I am validating users against oracle table. Is there a way to display username as they login to the page when connecting to oracle table???
qarjami
Member
228 Points
218 Posts
Re: Display user name in the header when logged in
Aug 25, 2009 11:32 PM|LINK
quickest way to do it use session state to store name. (of course, u should b using stored procedure to do this).
chetan.sarod...
All-Star
65709 Points
11133 Posts
Re: Display user name in the header when logged in
Aug 26, 2009 03:24 AM|LINK
Afetr authenticating the user, store that user name in Session. Add label t Master Page then set the text to it
Label.Text = Session["UserName"].ToString();
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Aug 26, 2009 03:42 PM|LINK
How can I store the username in Session? I know you add the Label.Text = Session["UserName"].ToString(); in the default page. Can you tell me step by step in storing username? I am using Oracle database.
Somehow I get his error: Object reference not set to an instance of an object
chetan.sarod...
All-Star
65709 Points
11133 Posts
Re: Display user name in the header when logged in
Aug 27, 2009 02:57 AM|LINK
How you are passing the username and password to the oracle table.
Read it from textbox when you click the button from lagin form, if the authentication successful, store that user name in session
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Aug 27, 2009 07:54 PM|LINK
Basically this is how I am passing the username and password to oracle table.
void LoginUser(object s, EventArgs e)
{
bool blnAuthenticate = Authenticate(username.Text, password.Text);
if (blnAuthenticate)
{
FormsAuthentication.RedirectFromLoginPage(username.Text, true);
}
else
{
lblError.Text = "Your login was invalid. Please try again.";
}
}
bool Authenticate(string strusername, string strPassword)
{ //declaring objects
OracleConnection objConn = new OracleConnection(ConfigurationManager.AppSettings["DSN"]);
OracleCommand objComd;
OracleDataReader objDR;
bool userFound;
objComd = new OracleCommand("SELECT * FROM REGISTER " + "WHERE USER_NAME='"
+ strusername + "' AND PASSWORD='" + strPassword + "'", objConn);
objConn.Open();
objDR = objComd.ExecuteReader();
userFound = objDR.Read();
objDR.Close();
return userFound;
}
From here what do I need to add in order to display username when they logged in (example: "Welcome Cadeey")
I appreciate your help.....
.
chetan.sarod...
All-Star
65709 Points
11133 Posts
Re: Display user name in the header when logged in
Aug 31, 2009 02:52 AM|LINK
When the code executes
FormsAuthentication.RedirectFromLoginPage(username.Text, true);
store "username.Text" in Session
Session["UserName"] = username.Text;
When it redirects (logged in) palce this value to lable
userNameLabel.text = "Welcome " + Session["UserName"].ToString();
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Cadeey
Member
102 Points
55 Posts
Re: Display user name in the header when logged in
Aug 31, 2009 01:19 PM|LINK
Thanks Chetan. That works.