3

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
  • I believe VB's named parameter syntax is: ParameterName := value (use colon-equals, not just equals). Commented Sep 25, 2018 at 5:22

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is logical, but it does not work for me. The error message saying the attribute is not valid on this declaration type. Please provide further help.
1

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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.