简体   繁体   English

是否可以在C#中动态启用和禁用CORS?

[英]Is it Possible to Enable and disable CORS dynamically in C#?

I have a api method, where it will give some result based on that result I have to conclude whether i have to send the response to the request or not. 我有一个api方法,其中它将根据该结果给出一些结果,我必须得出结论,是否必须将响应发送给请求。 For that i need to enable CORS at runtime in c#. 为此,我需要在C#的运行时启用CORS。 For each request it should enable or disable CORS . 对于每个请求,应启用或禁用CORS。 Is this scenario possible in c#? 在C#中是否可能出现这种情况?

This seems to be something that needs more work then just some standard configuration using EnableCors attributes as you would normally do. 这似乎需要做更多的工作,然后像通常那样使用EnableCors属性进行一些标准配置。

I would advize to implement a custom CORS policy provider or factory, so you can filter requests on a one-by-one basis. 我建议实施自定义CORS策略提供程序或工厂,以便您可以一对一地过滤请求。 (You just return another policy on the HTTP request.) (您只需在HTTP请求上返回另一个策略。)

More information on implementing such provider or factory can be found in the documentation . 有关实施此类提供者或工厂的更多信息,请参见文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM