简体   繁体   English

获取当前用户的Asp。 净C#

[英]get current user Asp. Net C#

Is there is a way to get the current user in the aspx page,the page with the html definitions? 有没有一种方法可以在aspx页面(具有html定义的页面)中获取当前用户? (i know how to get it in the aspx.cs page) (我知道如何在aspx.cs页面中获取它)

This should work: 这应该工作:

<%= Page.User.Identity.Name %>

Page.User Property Page.User属性

Use the following code block in the aspx where you want it to show up. 在希望显示的aspx中使用以下代码块。

<%= System.Environment.UserName %>

See ASP.NET "special" tags for more info. 有关更多信息,请参见ASP.NET“特殊”标签

使用代码标签

<%= YourMethodToGetTheCurrentUser() %>

You can access any public or protected variable from the code-behind file in it's .aspx file by wrapping your code in these characters: 通过将代码包装在以下字符中,可以从其.aspx文件中的代码隐藏文件访问任何publicprotected变量:

<% if(PublicObject.Property > 0) { %>
    <p>You can write normal HTML, or write strings like this: <%= PublicObject.Property %></p>
<% } %>

<% %> let's you add logic or commands into a page. <% %>让我们在页面中添加逻辑或命令。 You can use this to add for loops or if statements. 您可以使用它来添加for循环或if语句。 <%= %> is used to write content directly to the page. <%= %>用于直接将内容写入页面。 This is used to print the contents of a variable. 这用于打印变量的内容。

<%= System.Web.HttpContext.Current.User.Identity.Name%>

还有一个:

<%= HttpContext.Current.User.Identity.Name %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM