Class CorsHandler
Handler to enable CORS. Policies are read from the appsettings.json file.
Inheritance
Inherited Members
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. |