2013-06-20 46 views
0

我不知道是否有可能的官方方式或黑客檢索用戶當前登錄的ASP網頁上的選項「允許匿名用戶」的Windows登錄?或者使用導入的Windows DLL也許?如何在asp網頁上獲取windows登錄用戶?

我知道,通常與「拒絕匿名用戶」,我可以輕鬆地檢索登錄窗口。但由於某些特殊原因,我想檢索Windows登錄並接受匿名用戶。所以,如果Windows登錄是我的數據庫中的用戶,我將重定向到另一個網頁。

我已經ckecked是:(但windowsLogin ==總是空)

ASP的C#

string windowsLogin = System.Security.Principal.WindowsPrincipal.Current.Identity.Name; 
string windowsLogin = System.Threading.Thread.CurrentPrincipal.Identity.Name; 
string windowsLogin = System.Net.CredentialCache.DefaultCredentials.ToString(); 
string windowsLogin = Request.ServerVariables["LOGON_USER"].ToString(); 

的Web.config

<authorization> 
     <deny users ="?" /><!-- Deny acces to anonymous users--> 
     <allow users ="*" /><!-- Allow acces to every users--> 
    </authorization> 
    <identity impersonate="true"/> 
    <authentication mode="Forms"> 
     <forms loginUrl="./WebLogin.aspx" defaultUrl="./default.aspx" timeout="12" path="/" name=".ASPXFORMSAUTH" slidingExpiration="true" /> 
    </authentication> 
+0

這有什麼做與經典ASP - 它是一個.NET的問題 – John

+0

感謝您對我加了標籤的評論淨。 –

回答

0

你需要允許匿名用戶,看起來,你可能想嘗試Windows身份驗證。

<authorization> 
    <allow users ="*" /><!-- Allow acces to every user and do not deny anonymous --> 
</authorization> 
<authentication mode="Windows" /> 

在某些情況下,似乎ServerVariables已折舊C#。

如果是這樣,你需要做的是這樣的:

string login = System.Security.Principal.WindowsIdentity.GetCurrent().Name; 

如果你真的想用ServerVariables,記住他們是區分大小寫在C#。正確的外殼幾乎總是UPPER,這裏是他們的列表:

List of ServerVariables

相關問題