我在asp.net中使用loginView,如下所示:
<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();
}
}
}
和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>
无论如何都以相同的方式检索用户ID或者我是否需要编写ADO.Net代码来获取用户标识? 提前谢谢你
答案 0 :(得分:0)
假设您使用的是标准FormsAuthentication,则可以通过检查Membership.GetUser.ProviderUserKey
来获取ID。它将是一个GUID,因此如果您想要显示它,您将需要使用Membership.GetUser.ProviderUserKey.ToString