2014-06-26 98 views
0

這裏是web配置:無法獲取用戶憑據(Windows身份驗證)

<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <authentication mode="Windows" /> 

    <authorization> 

    </authorization> 
    <identity impersonate="true" /> 



    </system.web> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
     <security> 
      <authentication> 
       <windowsAuthentication enabled="true" > 
        <providers> 
         <clear /> 
         <add value="NTLM" /> 
        </providers> 
       </windowsAuthentication> 
       <anonymousAuthentication enabled="false" /> 
      </authentication> 
     </security> 
    </system.webServer> 

在頁面的代碼(想看看是否有任何的這些都可以):

WindowsIdentity identity = HttpContext.Current.Request.LogonUserIdentity; 

      string sLoginID = identity.Name.ToString(); 
      sLoginID = sLoginID.Remove(0, sLoginID.IndexOf('\\') + 1); 
      alert.InnerText = User.Identity.Name + "////// " + sLoginID ; 

結果(期望是DOMAIN \ USERNAME):

Anonymous////// NETWORK SERVICE 

網站位於iis Server 6.0上,除身份模擬nd Windows身份驗證。

回答

0

我想你得到這個用戶由於身份模仿參數。 參數更改爲

identity impersonate=false 

,並檢查你有帳戶

+0

您好,我沒有你所說的話,但我仍然看到: 匿名////// NETWORK SERVICE – user2044754

+0

你有沒有重新啓動修改後的IIS服務?嘗試直接在IIS配置中設置參數,然後在獲得所有良好參數後,您將生成web.config –

+0

是的,仍然不行。 – user2044754

0

這爲我工作: 的web.config

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    <authentication mode="Windows" /> 
    <identity impersonate="false" /> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer> 
</configuration> 

的Page_Load

protected void Page_Load(object sender, EventArgs e) 
{ 
    WindowsIdentity identity = HttpContext.Current.Request.LogonUserIdentity; 

    string sLoginID = identity.Name.ToString(); 
    TextBox1.Text = sLoginID; 
} 

IIS設置:

  • 匿名身份驗證 - 禁用
  • ASP.NET Imprsonation - 禁用
  • 窗體身份驗證 - 禁用
  • Windows身份驗證-disabled

授予我運行7.5。

截圖(IIS上而不是通過VS運行):

enter image description here

+0

哦,並在每次更改後我重新啓動網站,以防萬一(它畢竟是微軟):) –

+0

我複製了所有的設置,我仍然收到相同的錯誤結果。 :( – user2044754

相關問題