Make sure that you have added namespace using to use CORS. Public class DefaultController : ApiController Namespace APIServiceApplication.Controllers Before that make sure you have added the preceding code in your WebApiConfig.cs fileĪnd in the API controller you need to set the origins,headers,methods as preceding. Here we are going to apply CORS for particular controller, which means it will be applied for all the actions in the controller. ![]() You can also try the same as below in the Register function. Here we pass * to all the three parameters to make everything to be allowable. Public EnableCorsAttribute(string origins, string headers, string methods) Īs it is mentioned, it accepts the parameters origins, headers, methods. Comma-separated list of methods that are supported by the resource. Comma-separated list of headers that are supported by the resource. Comma-separated list of origins that are allowed to access the resource. Initializes a new instance of the .EnableCorsAttribute class. Now if you want to see the metadata of EnableCorsAttribute, you can see find it below. IF you do this, the CORS will be applied globally for all the Web API controller you have. Var cors = new EnableCorsAttribute(“*”, “*”, “*”) Then you can add the preceding codes in the static function Register. To work with this fix, you must include the package By using from Manage Nuget window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |