origin resource sharing with MVC 3?

I want to submit a form using AJAX to a MVC 3 Controller.

The form and the controller are on two different domains, which is why i want to use CORS.

I have read that the following code should do the trick in ASP.NET:

Response.AppendHeader("Access-Control-Allow-Origin", "*");

from http://enable-cors.org/#how-asp.net

Should this code go directly in the controller that takes the form data? As far as i know, there has to be some exchange of data between the client posting data and the server, to determine wether CORS is enabled/supported or not, so i figure that the one line of code has to go somewhere else?

Thanks


This could go in the controller. Actually I would probably externalize it in a custom action filter to avoid repeating it in every controller action that needs to be invoked from a cross domain AJAX call. There are no additional steps necessary. Just make sure that your browser supports CORS because if it doesn't adding this line will have strictly no effect whatsoever.

链接地址: http://www.djcxy.com/p/10760.html

上一篇: 用while循环+堆栈创建

下一篇: 与MVC 3共享来源资源?