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
Ajay Gupta
NA
330
59.2k
How to enable cors in asp.net web Method
May 20 2017 9:26 AM
Below code sample which i have implemented.
Global.asax
protected
void
Application_BeginRequest(
object
sender, EventArgs e)
{
var context = HttpContext.Current;
var response = context.Response;
// enable CORS
response.AddHeader(
"Access-Control-Allow-Origin"
,
"*"
);
if
(context.Request.HttpMethod ==
"OPTIONS"
)
{
response.AddHeader(
"Access-Control-Allow-Methods"
,
"GET, POST, OPTIONS"
);
response.AddHeader(
"Access-Control-Allow-Headers"
,
"Content-Type, Accept"
);
response.End();
}
}
Web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name=
"Access-Control-Allow-Headers"
value=
"accept, content-type"
/>
<add name=
"Access-Control-Allow-Origin"
value=
"*"
/>
<add name=
"Access-Control-Allow-Methods"
value=
"POST, GET, OPTIONS"
/>
</customHeaders>
</httpProtocol>
</system.webServer>
Reply
Answers (
3
)
how to use latest version visual studio 2017
why ActionResult method parameter is null in asp.net MVC?