我的WebAPI部署在Intranet环境中.这意味着安全不是我关注的问题.
看起来CORS 对客户端更友好,更容易实现.
我可能错过了任何其他问题吗?
我写了一个返回JSON的web服务,我试图用这样的jQuery调用它:
$.ajax({
contentType: "application/json; charset=utf-8",
url: "http://examplewebsite.com/service.asmx/GetData",
data: { projectID: 1 },
dataType: "jsonp",
success: function () {alert("success");}
});
Run Code Online (Sandbox Code Playgroud)
但是,尽管使用Fiddler查看HTTP流量时web服务调用成功,但代码从不调用成功函数.我认为这是因为我的Web服务正在返回原始JSON而不是JSONP.
如何生成JSONP作为标准.NET Web服务方法的响应,如下所示:
[WebMethod(), ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public Project GetData(int projectID)
{
Project p = new Project();
p.Name = "foobar";
return p;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
这似乎是一个简单的操作.
我们的开发环境(在XP/IIS 5上运行)需要在每个到达我们应用程序的HttpRequest中添加一些头文件.(这是为了模拟我们在开发中没有的生产环境).乍一看,这看起来像一个简单的HttpModule,沿着这样的方向:
public class Dev_Sim: IHttpModule
{
public void Init(HttpApplication app)
{
app.BeginRequest += delegate { app.Context.Request.Headers.Add("UserName", "XYZZY"); };
}
public void Dispose(){}
}
Run Code Online (Sandbox Code Playgroud)
但是在尝试这样做时,我发现Request的Headers集合是只读的,Add方法失败并带有OperationNotSupported异常.
花了几个小时在Google上研究这个问题,我对于应该是一个相对直接的问题没有简单的回答.
有没有人有任何指针?
asp.net ×2
jsonp ×2
c# ×1
cors ×1
cross-domain ×1
http-headers ×1
httprequest ×1
iis ×1
jquery ×1