473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to change the login hyper link to logout when successfully logged in

I have created a login page when the user logs in it will take to a specified page with the text "welcome Username" and logout link on the right.but am not getting any logout link but instead itz login link which functions as a logout link though.and no message as "welcome Username"

Below is the code I have used:

Expand|Select|Wrap|Line Numbers
  1. <div class="loginDisplay">
  2.   <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
  3.     <AnonymousTemplate>
  4.       [<a href="~/Account/Login.aspx" id="HeadLoginStatus" runat="server">Log In</a>]
  5.     </AnonymousTemplate>
  6.     <LoggedInTemplate>
  7.       <span>Welcome</span>
  8.       Welcome 
  9.       <span class="bold">
  10.         <asp:LoginName ID="HeadLoginName" runat="server" FormatString="Welcome {0}"/>
  11.       </span>! 
  12.       [<asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/Account/Login.aspx" />]
  13.     </LoggedInTemplate>
  14.   </asp:LoginView>
  15. </div>
Oct 11 '11 #1
10 18334
Frinavale
9,735 Expert Mod 8TB
It sounds like the login process is not working properly.
Could you please post the server-side code that you have for when the user logs in?
Oct 11 '11 #2
The code I have send is in the master page.
Oct 11 '11 #3
Frinavale
9,735 Expert Mod 8TB
I asked you to post the server-side code that is executed in order to log in the user. This will be the C# or the VB.NET code that authenticates the user. If you do not have this code, then that would explain why you're "login" method isn't working...and therefore the reason for why your "log-out" link is never showing up.

-Frinny
Oct 11 '11 #4
I haven't written any code on the backend.could u please help me out with the code.Thanks

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.         {            
  3.             //MembershipUser membershipUser = Membership.GetUser();
  4.             //if (membershipUser != null)
  5.             //{
  6.             //    string loggedinuser = Membership.GetUser().ToString();
  7.             //    //HeadLoginView.Controls = "Welcome " + loggedinuser;
  8.             //}
  9.             //else
  10.             //{
  11.             //    namelbl2 = "";
  12.             //}
  13.  
  14.  
  15.  
  16.         }
Oct 12 '11 #5
This the code:login.aspx
Expand|Select|Wrap|Line Numbers
  1. <asp:Login ID="LoginUser" runat="server" EnableViewState="false" 
  2.     RenderOuterTable="false" onauthenticate="LoginUser_Authenticate">
  3.         <LayoutTemplate>
  4.             <span class="failureNotification">
  5.                 <asp:Literal ID="FailureText" runat="server"></asp:Literal>
  6.             </span>
  7.             <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification" 
  8.                  ValidationGroup="LoginUserValidationGroup"/>
  9.             <div class="accountInfo">
  10.                 <fieldset class="login">
  11.                     <legend>Account Information</legend>
  12.                     <p>
  13.                         <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:</asp:Label>
  14.                         <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
  15.                         <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" 
  16.                              CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required." 
  17.                              ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
  18.                     </p>
  19.                     <p>
  20.                         <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
  21.                         <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
  22.                         <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
  23.                              CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required." 
  24.                              ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
  25.                     </p>
  26.                     <p>
  27.                         <asp:CheckBox ID="RememberMe" runat="server"/>
  28.                         <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
  29.                     </p>
  30.                 </fieldset>
  31.                 <p class="submitButton">
  32.                     <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
  33.                 </p>
  34.             </div>
  35.         </LayoutTemplate>
  36.     </asp:Login>




login.aspx.cs
Expand|Select|Wrap|Line Numbers
  1.  public partial class Login : System.Web.UI.Page
  2.     {
  3. protected void Page_Load(object sender, EventArgs e)
  4.         {
  5.             RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
  6.         }
  7.  
  8.         protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
  9.         {
  10.             OdbcConnection conn = new OdbcConnection("Dsn=PostgreSQL35W2;uid=root;pwd=aeiou123");
  11.             conn.Open();
  12.             OdbcCommand cmd = new OdbcCommand();
  13.             cmd.CommandText = string.Format( "select lower( user_id) as user_id,password from mdb.users where user_id ='{0}' and password ='{1}'",LoginUser.UserName,LoginUser.Password);
  14.             cmd.Connection = conn;
  15.  
  16.             OdbcDataReader dr = cmd.ExecuteReader();
  17.  
  18.             if (dr.HasRows)
  19.             {
  20.                 e.Authenticated = true;
  21.                 dr.Close();
  22.                 cmd.CommandText = "select emp_number from mdb.emp_details where lower(official_email_id) = '" + LoginUser.UserName + "'";
  23.                 var emp_number = cmd.ExecuteScalar();
  24.                 Session["EmployeeID"] = emp_number.ToString();
  25.                 Response.Redirect("~/Forms/testRadcomboBox.aspx");
  26.             }
  27.             else
  28.                 e.Authenticated = false;
  29.  
  30.         }
Oct 12 '11 #6
Frinavale
9,735 Expert Mod 8TB
The ASP.NET Login control works with Forms Authentication.

The code that you posted in post #6 does not use this type of authentication. So, I don't think you can use the login control.

You'll have to check session to see if your user is logged in and manually display the login or logout buttons/links accordingly (by setting their Visible property).

-Frinny
Oct 12 '11 #7
Hi could u plz help with how to proceed further.I was in a different domain.Recently(1.5 months bak) shifted to .net
Oct 14 '11 #8
I have also tried another way to create login using table control.in masterpage.cs my code is:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. public partial class MasterPage : System.Web.UI.MasterPage
  9. {
  10.     protected void Page_Load(object sender, EventArgs e)
  11.     {
  12.         if (Session["Empname"] != null)
  13.         {
  14.             string ssn = Session["EmpName"].ToString();
  15.             Label1.Text = ssn;
  16.             btnlogout.Text = "Logout";
  17.         }
  18.         else
  19.         {
  20.             btnlogout.Text = "Login";
  21.         }
  22.  
  23.     }
  24.     protected void btnlogout_Click(object sender, EventArgs e)
  25.     {
  26.         if (Session["EmpName"] == null)
  27.         {
  28.             Response.Redirect("~/login.aspx");
  29.         }
  30.         else
  31.         {            Response.Redirect("~/radcmbox.aspx");
  32.         }
  33.             }
  34. }
Oct 14 '11 #9
In the above code if i login it wl take me to "radcmbox.aspx" & once i login and then on clicking logout how do i go to login page again?
Oct 14 '11 #10
Frinavale
9,735 Expert Mod 8TB
It would probably be a better idea to have 2 buttons/linkbuttons instead of using 1 for two different functions.

Instead of changing the text of the one button, set the Visible property of each button.

That way you know when the user clicked the "logout" button/linkbutton and when the user clicked the "login" button/linkbutton so that you can take the appropriate action.

-Frinny
Oct 14 '11 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: VIJAY KUMAR | last post by:
Hi pals, I am using 2 web forms (pages). In first page, i have Datagrid control and on second page i have a hyper link control to the first page and Add value to the data grid/Database. ...
2
by: AlanHill1965 | last post by:
Hi All, I have developing a database system for the last couple of weeks and got stuck on one part of the functionality. I have posted this question over at MSDN, but no joy, perhaps they got...
3
by: ajaspersonal | last post by:
"i want to change font_style (hyper link<a href...>text</a>) normal to italics.when load a page" this is my problem but that label included in one 'USERCONTROL' This user controls may...
1
by: simons | last post by:
Hi All, I'm trying to add a hyper link to one of the filed in my DataList control. I added a link button but could not bound it to an ID filed and then link it to the page that i need. I'm...
0
by: mclewell | last post by:
i created an html hyper link field and clicking on the data in the field produces a security warning pop up requiring a yes click before the link is activated, is there a way to turn off this...
1
by: Kalaram | last post by:
I am makeing a CD, and in this CD i have alot of .pdf & .ppt & .pps files and i have one html page that i use as index to all the files, when i click on the hyper link of .pdf file , it opens...
1
by: Adrock952 | last post by:
I have a link on my site which obviously says "Login" where users log in. I would like that link to be changed to "Logout" when the user has successfully logged in and the session has been created...
3
Fary4u
by: Fary4u | last post by:
Hi is any body know how to create the hyper link with following code i can't do it ? <?xml version="1.0" encoding="utf-8" standalone="yes"?> <images> <pic> <image>img/1.jpg</image>...
3
by: rahullko05 | last post by:
i am using this code in one of my .php file: <a href="thanks.php" onclick = "return registerUser(){return false;}"> <input type="button" name="userText" value="Submit" id="memberRegisteration" />...
3
by: impin | last post by:
i wnat to store the login time and logout time in the database.... plz help... also how to retrieve stored logiin.logout times from database.... when i use the simple time disply $t=time();...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.