Home > Net >  Questions about cross domain asp.net
Questions about cross domain asp.net

Time:09-24

I create websites, so write interface is done with ashx inside, if two programs to access interface each other how to implement the cross-domain problem, request interface with js

CodePudding user response:

The ajax?

CodePudding user response:

reference 1st floor andy_wanhl response:
is ajax?
yes

CodePudding user response:

Ajax try using json, this is an ajax cross-domain mode, with possible before, but didn't pay attention to,

CodePudding user response:

I am such a

 
//get the context object
Var context=listerner. EndGetContext (ar);
Var request=context. The request;
Var response=context. The response;
//tell the client return the ContentType type is pure text format, encoding to utf-8
The context. The Response. ContentType="text/plain; Charset=utf-8 ";
//add response header information
Context. The Response. AddHeader (" the content-type ", "text/plain");
The context. The Response. AddHeader (" Access - Control - Allow - Origin ", "*");
Context. The Response. AddHeader (" Access - Control - Allow - Credentials ", "true");
Context. The Response. AddHeader (" Access - Control - Allow - the Methods ", "the Get and Post, the OPTIONS");
Context. The Response. AddHeader (" Access - Control - Request - Headers ", "X - Custom - the Header");
The context. The Response. ContentEncoding=Encoding. UTF8;


Then the returned JSON

 
//set the client returns the information encoding
Var returnByteArr.=Encoding UTF8. GetBytes (" cardResult (" + json + ") ");//set the client returns the information encoding

CodePudding user response:

reference 4 floor andy_wanhl response:
I am such a

 
//get the context object
Var context=listerner. EndGetContext (ar);
Var request=context. The request;
Var response=context. The response;
//tell the client return the ContentType type is pure text format, encoding to utf-8
The context. The Response. ContentType="text/plain; Charset=utf-8 ";
//add response header information
Context. The Response. AddHeader (" the content-type ", "text/plain");
The context. The Response. AddHeader (" Access - Control - Allow - Origin ", "*");
Context. The Response. AddHeader (" Access - Control - Allow - Credentials ", "true");
Context. The Response. AddHeader (" Access - Control - Allow - the Methods ", "the Get and Post, the OPTIONS");
Context. The Response. AddHeader (" Access - Control - Request - Headers ", "X - Custom - the Header");
The context. The Response. ContentEncoding=Encoding. UTF8;


Then the returned JSON

 
//set the client returns the information encoding
Var returnByteArr.=Encoding UTF8. GetBytes (" cardResult (" + json + ") ");//set the client returns the information encoding
is set to * so not safe, and set to * session also seems to be able to pass

CodePudding user response:

C # lets cross-domain code




Json, and then out to put on a layer of cardResult

This 2 points is the key, the other at random

CodePudding user response:

references a sugar packets boy reply: 3/f
ajax try using json, this is an ajax cross-domain mode, with possible before, but not have too to note that
I feel cross domain should be the back-end processing

CodePudding user response:

reference 5 floor spy0505 reply:


Ok, received

CodePudding user response:

refer to 6th floor andy_wanhl response:

allow cross-domain c # code



Json, and then out to put on a layer of cardResult

This 2 points is the key, other optional
cardResult what is this

CodePudding user response:

Is a function, take, at first you use normal, can't get to the value, remember more than one layer, MD, what principle, I haven't understand, but I see the two places,

CodePudding user response:

refer to 7th floor spy0505 response:
Quote: references a sugar packets boy reply: 3/f

Ajax try using json, this is an ajax cross-domain mode, with possible before, but not have too to note that
I feel cross domain should be the back-end processing


Yes, yes, I am is a server-side,
1, to declare the cross-domain, that is, the previous code
2, return json to the client, to add a function name, the name of the termination of the service, the same
3, this is the get method, post not to do it

CodePudding user response:

reference 5 floor spy0505 reply:
Quote: refer to 4th floor andy_wanhl response:

I am such a

 
//get the context object
Var context=listerner. EndGetContext (ar);
Var request=context. The request;
Var response=context. The response;
//tell the client return the ContentType type is pure text format, encoding to utf-8
The context. The Response. ContentType="text/plain; Charset=utf-8 ";
//add response header information
Context. The Response. AddHeader (" the content-type ", "text/plain");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related