【发布时间】:2016-01-26 20:26:14
【问题描述】:
我需要从/到各种 Sharepoint 域进行 CORS,当然还要处理 OPTIONS 预检请求。 经过大量研究,我发现this 解决方案(几乎)是最适合我的需求。 修改 global.asax 让您可以处理多个域并传递凭据,以及 OPTIONS 预检请求。
不好的一面是,按照建议应用后,您无法再登录Sharepoint Designer。
我修改 global.asax 如下,CORS 可以,但是 Sharepoint Designer 没有。
public void Application_BeginRequest(object sender, EventArgs e)
{
string httpOrigin = Request.Params["HTTP_ORIGIN"];
if (httpOrigin != null)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", httpOrigin);
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-RequestDigest");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");
if (Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.StatusCode = 200;
var httpApplication = sender as HttpApplication;
httpApplication.CompleteRequest();
}
}
}
我与 Fiddler 一起阅读了 Sharepoint Designer 所做的请求,并且没有标题“Origin”,所以我不知道它在哪里失败。 当我尝试登录 Sharepoint Designer 时,我总是收到 401 作为响应。
有人知道如何解决吗?谢谢
【问题讨论】:
标签: javascript sharepoint cors sharepoint-designer global-asax