Ian Vink
Ian Vink

Reputation: 68780

Prevent my javascript running on another web site

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

Answers (1)

Daniel A. White
Daniel A. White

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

Related Questions