我正在尝试从SqlDataSource
的返回设置一些会话变量。我能够将值设置为标签/文本框/隐藏字段,但我似乎无法设置会话变量。
我正在使用page_load
函数来尝试设置它们。
protected void Page_Load(object sender, EventArgs e)
{
this.Session["UserName"] = User.Identity.Name;
this.Session["EmplID"] = Eval("EmplID");
}
我有SqlDataSource
:
<asp:SqlDataSource ID="SQLGetEmplID" runat="server"
ConnectionString="<%$ ConnectionStrings:MAFapp %>"
SelectCommand="SELECT DISTINCT EmplID, Status FROM Employees WHERE (intLogin = @UserName) AND (Dept = N'Eng' OR Dept = N'IS') AND (Status = N'Active')">
<SelectParameters>
<asp:SessionParameter Name="UserName" SessionField="UserName" />
</SelectParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
如果您的User.Identity.Name
string fullUserName = null;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(pc,User.Identity.Name))
{
if (user != null)
{
fullUserName = user.DisplayName;//this can be what ever you like
}
}
}