작동하지 CORS 수 있도록 나는 클라이언트 측에서 다음 요청했다 :낸시 + .NET 코어
Is it possible to enable CORS using NancyFX?
나는 또한 시도 : 나는 백엔드에서 다음을 시도
$.get(getUrl)
을 이 네 가지 접근 방식 (별도로 주석 처리 됨) :
// protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
// {
// pipelines.AfterRequest += ctx =>
// {
// ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
// ctx.Response.Headers.Add("Access-Control-Allow-Headers", "*");
// ctx.Response.Headers.Add("Access-Control-Allow-Methods", "*");
// };
// }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
pipelines.AfterRequest += (ctx) =>
{
ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
};
}
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context)
{
base.RequestStartup(container, pipelines, context);
// pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
// {
// ctx.Response.WithHeader("Access-Control-Allow-Origin", "*")
// .WithHeader("Access-Control-Allow-Methods", "*")
// .WithHeader("Access-Control-Allow-Headers", "*");
// });
// pipelines.AfterRequest += (ctx) =>
// {
// ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
// ctx.Response.Headers.Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
// };
나는 이브를 가지고있다. 모두가 동일하게 산출
After += (Context) =>
{
Context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
Context.Response.Headers.Add("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
Context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, x-requested-with, Authorization, Accept, Origin");
};
: 내가 기대하는 사용자 정의 헤더를 전달하고 있지 않다 때문에
XMLHttpRequest cannot load http://localhost:5000/registration/signup. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5001' is therefore not allowed access. The response had HTTP status code 401.
401이고, n은 같은 내 모듈 뭔가를 시도했다. CORS 문제를 해결하기 위해 노력하고 있습니다.
이 게시물 http://antupload.com/questions/26171749/getting-cors-to-work-with-nancy 해결책은 Nancy 모듈을 사용하는 것이 었습니다. 파이프 라인 끝에서로드하십시오. – Woot
[CORS와 낸시 작업 방법] (http://stackoverflow.com/questions/26171749/getting-cors-to-work-with-nancy) – Woot