Skip to content

WebAPI - No 'Access-Control-Allow-Origin' header is present on the requested resource #2018

@tomerpeled

Description

@tomerpeled

I'm encountering an issue with CROS while using IAsyncResourceFilter implementation.
I want to be able to call my actions from other domains as well...

I've defined the CORS policy under my Startup file as the following:

services.AddCors(options =>
          {
              options.AddPolicy("AllowAllOrigins",
               builder =>
               {
                   builder.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
               });
          });

And under the Configure method:
app.UseCors("AllowAllOrigins");

It works fine without using a TypeFilterAttribute which use IAsyncResourceFilter.

For example:
Calling my API action without any TypeFilterAttribute attribute works:

public bool Get()
{
 return true;
}

But when adding my TypeFilterAttribute as follows it doesn't work and returns the error about the CROS:

[MyTypeFilterAttribute("test")]
public bool Get()
{
 return true;
}

Anything I'm missing? What should I add when using IAsyncResourceFilter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions