Reputation: 68780
My server has a javascript file, I only want to allow a certain web sites from being able to run it. I know the few sites that may use it.
In ASP.NET MVC, or ASP.NET Core, how can I restrict the javascript from being sent to a rogue web site?
Upvotes: 4
Views: 346
Reputation: 190976
you can't 100% avoid it, but you could check window.location
to see if the origin matches.
if (location.origin.toLowerCase() !== 'http://example.com') {
// you can't use me
}
Upvotes: 6