I've got a C# Web-API and at Application_Start() i configure the routes, formatters and cors domains. My problem is, that based on the request-origin, I have to add more domains to the cors-domains. (e.g. if the request comes from 123.com there are mor cors domains than from asd.com) I thought of adding the additional cors-domains in Application_BeginRequest:
void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication app = (HttpApplication)source;
HttpContext context = app.Context;
// Attempt to peform first request initialization
FirstRequestInitialization.Initialize(context);
var corsDomains = Settings.Default.CORS_Domains;
if (originheader.equals("somevalue"))
{
corsDomains += ", " + Settings.Default.CORS_SomeValue_Domains;
}
var cors = new EnableCorsAttribute(corsDomains, "*", "*")
{
SupportsCredentials = true
};
HttpConfiguration config = //where to get config?
config.EnableCors(cors);
}
Is there a way to retrieve and change the config? Thank you very much for your help.
Edit: Maybe an example can clarify what I need:
request comes from asdf.org: cors-domains should be: base.com, home.org, jkl.net (but NOT qwer.com)
request comes from test.com: cors-domains should be: base.com, home.org, qwer.com (but NOT jkl.net)
in the Settings.Default, I have multiple lists:
CORS_BASE: base.com, home.org
CORS_ASDF: jkl.net
CORS_TEST: qwer.com
how can I add the additional list to the cors domains, according to the origin of the request?