I have a MVC project in which I have a couple of JSON controller methods I want to expose cross domain. Not the entire site, just these two methods.
I basically want to to the exact thing stated in this post for cors:
http://enable-cors.org/server_aspnet.html
However, the problem is that I have a regular MVC project and not a WEB API, meaning, that I cannot follow the steps regaring the register
public static void Register(HttpConfiguration config)
{
// New code
config.EnableCors();
}
method since it is not present in my MVC project.
Is there a way to use this library although it is a MVC project?
I'm aware of that I can config this through web.config using:
<httpProtocol>
<customHeaders>
<clear />
<add name="Access-Control-Allow-Origin" value="http://www.domain.com" />
</customHeaders>
</httpProtocol>
But I don't want to expose all methods, and I want to specify more than one domain (2 domains) to have access to my methods...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…