我在 Masterpage 页面加载中创建 asp.net 会话对象,并再次检查是否存在会话的内容页面。它在初始首次加载时不起作用。如果我刷新(F5)然后我就能得到这个。
掌握
Dim User As System.Security.Principal.IPrincipal
User = System.Web.HttpContext.Current.User
Dim username As String
username = User.Identity.Name
Try
lblUsername.Text = "Welcome " & IIf(Not String.IsNullOrEmpty(GetFullName(User.Identity.Name)), GetFullName(User.Identity.Name), User.Identity.Name)
Session("username") = username
Catch ex As Exception
End Try
内容页
If Not Page.IsPostBack Then
If Not Session("username") Is Nothing Then
Dim Clients As List(Of Dim_Client)
Dim c As New Dim_Client
Clients = c.GetClients(Session("username").ToString)
If Clients.Count > 0 Then
ddlClients.DataTextField = "Client_Name"
ddlClients.DataValueField = "Client_Idx"
ddlClients.DataSource = Clients
ddlClients.DataBind()
End If
End If
End If