我正在嘗試設置WebAPI Web服務和將在我們公司Intranet上運行的網站。我使用IIS來託管Web服務(A)以及我的網站(B)。在我的網站上的網頁,使到正是如此Web服務的請求:Firefox NTLM憑證到本地主機
var URL = 'http://MachineName:80/AWebService/api/GetGuid';
var request = new XMLHttpRequest();
request.open("GET", URL, false);
request.withCredentials = "true";
request.send();
var response = request.responseText;
return response;
WebService的代碼如下所示:
[EnableCors(origins: "http://localhost", headers: "*", methods: "*")]
public class StoneSoupController : ApiController
{
[ActionName("GetGuid")]
public HttpResponseMessage GetGuid()
{
var indenty = this.User.Identity;
Guid g = Guid.NewGuid();
HttpResponseMessage msg = new HttpResponseMessage();
msg.Content = new StringContent(g.ToString());
msg.Headers.Add("Access-Control-Allow-Origin", "http://localhost"); //tried with and without this
msg.Headers.Add("Access-Control-Allow-Credentials", "true"); //tried with and without this
return msg;
}
}
如果我設置身份驗證模式在IIS的Web服務,以匿名身份驗證那麼Web服務按預期返回guid字符串。不過,我需要控制哪些用戶能夠訪問Web服務上的某些方法,並希望使用他們的Windows憑據來執行此操作。
我的問題是,我似乎無法讓Firefox發送Windows憑據。我試過在Firefox中使用about-config
在network.automatic-ntlm-auth.trusted-uris
中包含http://localhost
,但這似乎沒有任何效果。
我已經啓用日誌記錄在IIS中,這是它記錄了請求
2013-08-01 21:36:05 136.203.40.232 GET /AWebService/api/GetGuid - 80 - 136.203.40.232 Mozilla/5.0+(Windows+NT+6.1;+WOW64;+rv:17.0)+Gecko/20100101+Firefox/17.0 200 0 0 965
正如你可以看到有在交易中沒有用戶ID。
任何人都可以幫助我嗎?
嗨Giridhar,對不起了這麼久,我回應。使用HTTPfox,我能夠看到響應頭「WWW-Authenticate」最初具有「NegotiateNTLM」的值。 Firefox彈出一個詢問用戶名/密碼的彈出窗口。當我輸入用戶名/密碼時,它立即再次彈出,它將永久地執行。在第一個請求之後,我看到我有一個「Authorization」的請求標題,其值爲「NTLM TlRMTVNTUAAB ...」,現在有一個「NTLM TIRMTVNTUAAC ...」的響應標題。任何想法我做錯了什麼? – nickvans