domain使用跨站点请求添加提交时,我无法设置cookie .我试图通过jquery ajax调用请求来实现这一点.
是否有可能让它在除Firefox之外的其他浏览器中工作?
一些请求标题:
Accept:application/json, text/javascript, */*; q=0.01
Content-Length:55
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost:53862
Origin:http://localhost:54265
Referer:http://localhost:54265/
Run Code Online (Sandbox Code Playgroud)
响应标题:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:x-requested-with, origin, content-type, accept, Proxy-Connection
Access-Control-Allow-Methods:GET,POST,PUT,OPTIONS, DELETE
Access-Control-Allow-Origin:http://localhost:54265
Set-Cookie:Auth=l_hash=123456&user=xyzl&remember_me=false; expires=Fri, 18 Jan 2013 13:42:10 GMT; domain=localhost; path=/
Run Code Online (Sandbox Code Playgroud)
码:
$.ajax({
type: "PUT",
url: apiHost + "api/account/login/",
data: $("#loginBarForm").serialize(),
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
crossDomain: true,
xhrFields: {
withCredentials: true
},
});
Run Code Online (Sandbox Code Playgroud)
在Firefox中一切都很好.Chrome未设置Cookie.仅当域字段被删除时,所有浏览器都在运行.我可以看到在下一个请求中(在设置cookie之后)cookie出现在标题中.响应设置cookie后的firefox请求示例(当响应有域字段时):
Cookie: Auth=l_hash=123456&user=xyz&remember_me=false
Run Code Online (Sandbox Code Playgroud) public ActionResult _Upload(HttpPostedFileBase file, GaleriesViewModel galeriesViewModel)
{
Images image = new Images();
if (file.ContentLength > 0)
{
try
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/Galeries/Galery_" + galeriesViewModel.sno), fileName);
var smallImagePath = Path.Combine(Server.MapPath("~/Images/Galeries/Small/Galery_" + galeriesViewModel.sno), fileName);
var db_file_url = "Images/Galeries/Galery_" + galeriesViewModel.sno + "/" + fileName;
var db_small_image_url = "Images/Galeries/Small/Galery_" + galeriesViewModel.sno + "/" + fileName;
//exception thrown in this line
file.SaveAs(path);
Image smallImage = Image.FromFile(path);
Size size = new Size();
size.Height = 128;
size.Width = 128;
smallImage = …Run Code Online (Sandbox Code Playgroud) ajax ×1
asp.net-mvc ×1
cookies ×1
cors ×1
dispose ×1
file-upload ×1
image ×1
jquery ×1
process ×1