Mega Code Archive

 
Categories / ASP.Net / Login Security
 

Outputs the name of the currently logged user as authenticated by the ASP NET application

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"      Inherits="Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Welcome aboard</title> </head> <body>     <div>         <form id="form1" runat="server">             <table><tr>                 <td><asp:loginname ID="Loginname1" runat="server" FormatString="Welcome, {0}" /></td>                 <td><asp:LoginStatus ID="LoginStatus1" runat="server" LogoutText="Log off" LogoutAction="Refresh" /></td>             </tr></table>             <asp:Label runat="Server" ID="Msg" />         </form>     </div> </body> </html> File: Default.aspx.cs 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; public partial class Default : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {         if (User.Identity.IsAuthenticated)             Msg.Text = "Authenticated";         else             Msg.Text = "Not Authenticated";     } }