Show / Hide Table of Contents

Class CorsHandler

Handler to enable CORS. Policies are read from the appsettings.json file.

Inheritance
System.Object
CorsHandler
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Celerik.NetCore.Web
Assembly: cs.temp.dll.dll
Syntax
public static class CorsHandler
Examples

appsettings.json, enabling CORS for specific origins: "Cors": { "PolicyName": "AllowSpecificOrigins", "Origins": "https://origin1.com,https://origin2.com," }

appsettings.json, enabling CORS for any origin: "Cors": { "PolicyName": "AllowAnyOrigin" }

Methods

AddCors(IServiceCollection, IConfiguration, ILogger)

Adds cross-origin resource sharing services to this IServiceCollection.

By convention, CORS configuration properties are get from the IConfiguration object in the following way:

  • Cors:PolicyName
  • Cors:Origins
Declaration
public static void AddCors(this IServiceCollection services, IConfiguration config, ILogger logSvc)
Parameters
Type Name Description
IServiceCollection services

The IServiceCollection to add services to.

IConfiguration config

Object to access application configuration properties.

ILogger logSvc

Reference to the current ILogService instance.

UseCors(IApplicationBuilder, IConfiguration, ILogger)

Adds a CORS middleware to the web application pipeline to allow cross domain requests.

By convention, CORS configuration properties are get from the IConfiguration object in the following way:

  • Cors:PolicyName
  • Cors:Origins
Declaration
public static void UseCors(this IApplicationBuilder app, IConfiguration config, ILogger logSvc)
Parameters
Type Name Description
IApplicationBuilder app

Object to configure the application's request pipeline.

IConfiguration config

Object to access application configuration properties.

ILogger logSvc

Reference to the current ILogService instance.

In This Article
Back to top Generated by DocFX