使用SharePoint中嵌入的Jquery调用WCF服务时的Windows身份验证 [英] Windows Authentication when calling a WCF service using Jquery embedded in SharePoint

查看:68
本文介绍了使用SharePoint中嵌入的Jquery调用WCF服务时的Windows身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jquery文件,该文件嵌入在本地环境中的SharePoint2013中.我想调用启用了Windows身份验证的WCF服务.我已启用CORS,并添加了诸如("Access-Control-Allow-Origin"","Access-Control-Allow-Origin", 域")(访问控制允许凭据",真")(缓存控制",无缓存").

I am having a jquery file which is embedded inside SharePoint2013 on premise environment. I want to call a WCF service which has windows authentication enabled. I have enabled CORS and added the headers like ("Access-Control-Allow-Origin","requested domain"),("Access-Control-Allow-Credentials", "true") ("Cache-Control", "no-cache").

ajax调用如下:-

The ajax call is as below:-

$.ajax({
    url: url,
    type: "POST",
    data: data,
    success: successCallback,
    contentType: "application/json",
crossDomain: true,
   xhrFields: {
        withCredentials: true
    },
    error: errorCallback,
    dataType: "json"
})
}

但是拨打服务电话会显示未经授权:由于凭据无效,访问被拒绝.我正在使用IE11浏览器.

But making a service call is giving Unauthorized: Access is denied due to invalid credentials. I am using IE11 browser.

当我直接在浏览器中运行服务网址时,它运行正常.

When I run the service Url directly in browser it is working fine.

能否请您帮我如何为自定义WCF服务使用jquery文件执行身份验证.

Can you please help me how can I perform the authentication using jquery file for the custom WCF service.

推荐答案

WCF服务是否使用用于登录Sharepoint的相同Windows凭据?您是否检查了Fiddler/Network嗅探器,jQuery ajax是否将cookie发送到WCF?另外请注意以下注意事项 带有凭据的请求部分:

does WCF service uses the same Windows credentials which are used for login in to Sharepoint? did you check in Fiddler/Network sniffer does jQuery ajax sends cookies to WCF? Also pay attention on the following note from Requests with credentials section:

"第三方Cookie
请注意,在CORS响应中设置的Cookie受正常的第三方Cookie政策的约束.在上面的示例中,该页面是从foo.example加载的,但是第22行的cookie是由bar.other发送的,因此如果用户已配置其cookie,则将不会保存该cookie. 浏览器拒绝所有第三方cookie."

"Third-party cookies
Note that cookies set in CORS responses are subject to normal third-party cookie policies. In the example above, the page is loaded from foo.example, but the cookie on line 22 is sent by bar.other, and would thus not be saved if the user has configured their browser to reject all third-party cookies."


这篇关于使用SharePoint中嵌入的Jquery调用WCF服务时的Windows身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆