Hi,
We have added Content-Security-Policy on web.config.
It is not working.
value="default-src 'self'; script-src 'self'; object-src 'none';" /> Regards, Pratik
Hi,
We have added Content-Security-Policy on web.config.
It is not working.
value="default-src 'self'; script-src 'self'; object-src 'none';" /> Regards, Pratik
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandhiya PriyaPosted Oct 27, 2025, 8:51 AM
Problem:
In classic ASP.NET (not ASP.NET Core), adding CSP headers using this syntax in
web.configoften doesn’t work:because:
IIS doesn’t always pass custom headers correctly when added under
in older framework versions.Certain middleware or modules (e.g., Forms Authentication or URL Rewrite) may overwrite or remove the header.
Correct Way (for ASP.NET Web Forms / MVC in web.config)
Add this inside:
Verify It Works
After saving
web.config, restart the app (or IIS), and then open the site in a browser.Check the response headers:
Open Developer Tools (F12) ? Network tab
Refresh your page
Select your main request and look under Response Headers
You should see:
If it’s missing, see the next step
If It Still Doesn’t Work
Add the header programmatically in Global.asax instead:
This method guarantees that the CSP header is sent for every request.
Summary
Cynthia SathuragiriPosted Sep 22, 2025, 6:16 AM
In your web.config, under