im using the loginView in asp.net like this :
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
<a href="#login" id="HeadLoginStatus" runat="server">Log In</a>
</AnonymousTemplate>
<LoggedInTemplate>
<asp:LoginName ID="HeadLoginName" runat="server" />
<asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/" />
</LoggedInTemplate>
library.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace IRELBS.Library
{
public partial class Library : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
tbxUserID.Text = Membership.GetUser.ProviderUserKey.ToString();
}
}
}
and library.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Library.aspx.cs" Inherits="IRELBS.Library.Library" %>
<%@ Register Src="~/Mod/ReqPopup.ascx" TagPrefix="uc1" TagName="ReqPopup" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<%-- <div class="container">
<div class="jumbotron cent">
<h1>Welcome</h1>
<p>
to AZLearn library.
</p>
<a href="#" class="btn btn-default">Watch now</a>
<a href="#" class="btn btn-info">Tweet it!</a>
</div>
</div>--%>
<div class="container">
<div class="row">
<div class="col-md-3">
<h3 class="cent">Asp.net</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<asp:Button ID="btnR" runat="server" Text="Requirements" CssClass="btn btn-info pull-right" />
</div>
<div class="col-md-3">
<h3 class="cent">Java</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
<div class="col-md-3">
<h3 class="cent">HTML5</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
<div class="col-md-3">
<h3 class="cent">CSS</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
</div>
<div class="row">
<div class="col-md-3">
<h3 class="cent">Asp.net</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
<div class="col-md-3">
<h3 class="cent">Java</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
<div class="col-md-3">
<h3 class="cent">HTML</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
<div class="col-md-3">
<h3 class="cent">CSS3</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<a href="#" class="btn btn-default">Start Tutorial</a>
<a href="#" class="btn btn-info pull-right">Requirements</a>
</div>
</div>
</div>
<asp:TextBox ID="tbxUserID" runat="server"></asp:TextBox>
</asp:Content>
is there anyway to retrieve the user id the same way or do i need to write ADO.Net codes to get the userID ?? thank you in advance
Assuming you are using the standard FormsAuthentication you can get the ID by inspecting Membership.GetUser.ProviderUserKey
. It will be a GUID so if you want to display it you will need to use Membership.GetUser.ProviderUserKey.ToString
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.