我正在尝试设置将在我们公司内部网上运行的 WebAPI Web 服务和网站。我正在使用 IIS 来托管 web 服务 (A) 以及我的网站 (B)。我网站上的一个页面因此向网络服务发出请求:
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 中包含in http://localhost
,但这似乎没有任何效果。network.automatic-ntlm-auth.trusted-uris
about-config
我已启用登录 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。
谁能帮我这个?