2010-12-03 232 views
2

我在設置Web服務的基本身份驗證時遇到問題。 我正在寫使用.NET 4.0Web服務的基本身份驗證

在web.config標準的Web服務(不WCF)我有以下設置:

<configuration> 
    <system.web> 
     <identity impresionate="true" /> 
     <authentication mode="Windows" /> 
    </system.web> 
... 
</configuration> 

Web服務有一個方法:

[WebMethod(Description = "Returns currently logged in user.")] 
public string WhoAmI() 
{ 
    return "You are logged in as: " + System.Threading.Thread.CurrentPrincipal.Identity.Name; 
} 

測試服務器是位於與我的計算機相同的域中的虛擬機。當我訪問它時,我沒有爲CurrentPrincipal.Identity.Name獲取任何內容。

我也嘗試使用soapUI訪問Web服務。我輸入了我的用戶名,密碼和域名,但仍然無法使用。

任何幫助,將不勝感激。

回答

1

在IIS(INETMGR)你可以找到Authendication法窗口。(WebService1->屬性 - >目錄安全性 - > Authendication控制 - >編輯按鈕)

您可以選擇Authendicated訪問。 (Diggest,Basic,Integrated Authendication) 改變你的方法後,你會想要的。

+0

出於一些奇怪的原因,我無法通過編輯web.config文件來設置基本身份驗證。我只能從IIS中完成。 – 2010-12-04 10:20:30

0

如果將impresionate更改爲impersonate,它會工作嗎?