Posted on 26/08/2025 16:53:27
Hi Theodor
>>I've tried with the standard way in a .net application, but it doesnt seem to work
You can do that when you take over the program.cs - which requires you to host Dynamicweb your self as that is not supported in the cloud. Be aware that cors has to be registered very early - otherwise it will not work.
Dynamicweb supports iPipeline for adding stuff to the pipeline using custom addins - see this one: https://doc.dynamicweb.dev/documentation/extending/middleware/index.html
using Dynamicweb.Host.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace CustomCode;
public class CorsPipeline : IPipeline
{
public int Rank => -1; // Ensure CORS runs early enough
private const string CorsPolicyName = "DefaultCors";
public void RegisterServices(IServiceCollection services, IMvcCoreBuilder mvcBuilder)
{
services.AddCors(options =>
{
options.AddPolicy(CorsPolicyName, policy =>
{
policy.WithOrigins(
"https://www.dynamicweb.dk",
"https://partner.yourdomain.com")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
}
public void RegisterApplicationComponents(IApplicationBuilder app)
{
app.UseCors(CorsPolicyName);
}
public void RunInitializers()
{
// No initializers needed for CORS
}
}
I believe this should work - but have not tested it. It might not be early enough in the pipeline....
Good luck getting the headers correct :-).
BR Nicolai