-1

I need to restrict direct URL to view file for example : https://[mywebsite]/js/jquery.js well show like this as below enter image description here and the other directory file like this https://[mywebsite]/mail/notify.xml

georgetovrea
  • 537
  • 1
  • 8
  • 28
  • 1
    If you know a little about how web apps work inside a browser, you should know that blocking JavaScript from end users is impossible. Blocking such files immediately cripples your web apps. But if you want to block other kinds of files like the XML files, use URL Rewrite rules. – Lex Li Mar 15 '23 at 03:02

1 Answers1

0

You can deny unauthenticated users direct access to JS files by setting the web.config configuration file.

Please refer to this thread: restrict access to js file if not logged in

In addition, you can try setting Hidden Segments in the "Request Filtering" module of IIS Manager.

Please refer to this thread: Disable direct URL access to the files in ASP.NET MVC 5 on IIS 10

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
YurongDai
  • 1,362
  • 1
  • 2
  • 7
  • I have tried to set hidden segment to prevent direct url access js code from browser ,but it's will cause js function cannot work – georgetovrea Mar 20 '23 at 01:43
  • You can modify your JavaScript code to use relative paths instead of absolute paths. This means that instead of specifying the full URL (including hidden segments), you only need to specify the relative path to the resource you want to access. This way, your JavaScript code will continue to work even if the hidden segment changes the URL structure. – YurongDai Mar 20 '23 at 07:27