I have the following request on the clientside:
$.get(getUrl)
I have tried the following on the backend:
Is it possible to enable CORS using NancyFX?
I have also tried these four approaches (separately, hence commented out):
// 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");
// };
I have even tried for my module something like:
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");
};
All yield the same:
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.
The 401 is because I am not passing in a custom header that is expected. I am just trying to work around the CORS issue first