EnableCors for VB.net

江枫思渺然 提交于 2021-02-10 09:41:48

问题


Does anyone know how to put the enableCors into the controller on vb.net. i am working along with a pluralsight course and tried a code translator with no luck. my attempt is below.

<EnableCors(origins:    "http://localhost:53080", headers: "*", methods: "*")>

回答1:


The correct syntax would be something like this:

<EnableCors("http://localhost:53080", "*","*")>

The C# example appears to use named parameters. VB.NET supports that too, however the EnableCorsAttributes has properties and contractor arguments that only differ by letter casing. This confuses the compiler as to whether you are attempting to set the named parameter or the property in the attribute. So, in this case we can just drop the named arguments all together.




回答2:


In Vb.net this <EnableCors("http://localhost:53080", "*","*")> will work, but, you have to add on NuGet the Microsoft.AspNet.WebApi.Cors and Microsoft.AspNet.Cors. You need to add Imports System.Web.Http.Cors on the class.




回答3:


Remove any empty line between the http://localhost:53080", "*","*")> and the declaration of the controller class.



来源:https://stackoverflow.com/questions/36270626/enablecors-for-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!