在Web.Api剑道上传跨域问题 [英] kendo uploader Cross domain issue in Web.Api
本文介绍了在Web.Api剑道上传跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经启用CORS广告在我的Web API项目!在API控制器内部所有其他方法可以从其他项目中访问!
但剑术上传请求不能达到给控制器方法
$(#文件)。kendoUpload({
异步:{
xhrFields:{
withCredentials:真
},
saveUrl:HTTP://本地主机:23618 / API /测试/ UploadAttachment', removeUrl:HTTP://本地主机:23618 / API /测试/ RemoveAttachment',
autoUpload:真
}, 上传:功能(E){
e.data = {的ContactID:5};
}, 错误:onerror的 });
错误
通配符*不能在使用访问控制允许来源头文件时的凭据标志是真实的。原产地的http://本地主机:23617,因此没有允许访问。
这是我的CORS
VAR CORS =新EnableCorsAttribute(*,*,*);
config.EnableCors(CORS);
解决方案
尝试这种方式为我工作..
的http://docs.telerik.com/KENDO-UI/api/javascript/ui/upload#configuration-async.withCredentials
\r
\r\r
\r $(#文件)。kendoUpload({\r
多:假的,\r
异步:{\r
withCredentials:假的,\r
saveUrl:URL,\r
autoUpload:真\r
},\r
成功:的onSuccess\r
});
\r
i already enable the Cors in my WEB API project ! all other methods inside the API controller can access from the other project !
but kendo uploader request can not reach to the controller method
$("#files").kendoUpload({
async: {
xhrFields: {
withCredentials: true
},
saveUrl: 'http://localhost:23618/API/test/UploadAttachment',
removeUrl: 'http://localhost:23618/API/test/RemoveAttachment',
autoUpload: true
},
upload: function (e) {
e.data = { contactID: 5 };
},
error: onError
});
error
A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:23617' is therefore not allowed access.
here is my cors
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
解决方案
Trying it this way worked for me.. http://docs.telerik.com/KENDO-UI/api/javascript/ui/upload#configuration-async.withCredentials
$("#files").kendoUpload({
multiple: false,
async: {
withCredentials: false,
saveUrl: "url",
autoUpload: true
},
success: onSuccess
});
这篇关于在Web.Api剑道上传跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文