TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Paw Uio
NA
54
0
CORS problem making ajax call to a web service
Oct 26 2018 7:20 AM
Hello
I have a problem with CORS.
I need to call a web service from 2 domains. In my web.config I added headers:
CORS works well, but I don't like * in the Origin. I try do do the same in Application_BeginRequest:
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:3312");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Accepts, Content-Type, Origin, X-My-Header");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "60");
HttpContext.Current.Response.End();
}
My idea was to put request host in the Origin as I'm allowed to have only 1 Origin domain.
When I check headers in the browser they looks the same but I have CORS error " The Same Origin Policy disallows reading the remote resource..." What to do to get it working?
Reply
Answers (
1
)
How to add form data and update the same in gridview in MVC
what is best mvc or mvc core