2014-09-25 31 views
0

我試圖尋找在這裏如何讓ASP的用戶名,但它總是返回500錯誤代碼:用戶名在ASP網頁

<% 
Response.Write("User: " & HttpContext.Current.User.Identity.Name) 'User.Identity.Name) 
%> 

它的IIS 8.5 Windows服務器上運行的2012

待辦事項我需要導入一個類才能訪問用戶名?

+1

你能試着去'Request.ServerVariables( 「LOGON_USER」)',看看是否讓你什麼嗎? – 2014-09-25 12:58:23

+0

Try @ j.f。建議,看起來像你試圖使用[標籤:asp.net]代碼,如果你在一個經典的asp環境中將失敗。 – Lankymart 2014-09-25 14:37:33

回答

1

要回答你的問題,沒有

您的代碼錯誤的原因是因爲您正在將方法混合到您的中。爲了解決這個問題,建議@J.f在他們的評論中提出了建議;

Suggested通過@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")) 
%> 

重要:如果您正在使用「匿名身份驗證」訪問此頁面Request.ServerVariables("LOGON_USER")將是空的,它是隻填入其他身份驗證方法(如「Windows身份驗證」)。

+0

在.NET中的'Request.ServerVariables [「LOGON_USER」]' – 2014-09-25 15:18:04

+0

@ZeeTee這是做另一種方式是使用'HttpContext',馬的課程。 – Lankymart 2014-09-25 16:32:28

+0

另外,你不需要'Call'一個'Response.Write'或使用'()'要麼 – 2014-09-25 16:48:36