我试过在这里搜索如何在ASP中获取用户名,但它总是返回500错误代码:
<%
Response.Write("User: " & HttpContext.Current.User.Identity.Name ) 'User.Identity.Name )
%>
它在IIS 8.5 Windows Server 2012上运行
我是否需要导入一个类才能访问用户名?
答案 0 :(得分:1)
要回答您的问题,否。
您的代码错误的原因是因为您将asp.net方法混合到asp-classic中。要解决此问题,建议@J.f已在其评论中提出建议;
<% 'As has been pointed out Call is optional use or don't it's your choice. Call Response.Write("User: " & Request.ServerVariables("LOGON_USER")) %>
重要提示:如果您使用&#34;匿名身份验证&#34; 访问此页面,
Request.ServerVariables("LOGON_USER")
将为空,则仅填充其他身份验证方法(例如&#34; Windows身份验证&#34; )。