Search code examples
asp.net-coreiisweb-config

Angular routing 404 for js extension files (asp.net core IIS detailed error exposing physical directory)


I have an SPA (Angular) setup inside Startup.cs file of my Asp.net Core application which is hosted on IIS. In my application, there is a custom 404 error page for incorrect urls.

When navigated to incorrect urls like - https://myapplication.com/assets/js/mordernizer.min & https://myapplication.com/assets/js, i get a custorm error page.

But a route with a .js extension - https://myapplication.com/assets/js/mordernizer.min.js(this file doesn't exist) gives me 404 Not found IIS detailed error. This exposes the physical directory of my server which is the problem.

enter image description here

Is there a way in Angular I can handle the routes with requests to js extension files? My IIS configuration - httperrors errormode= custom is not working as well. Any solutions?


Solution

  • Issue resolved! I just had to set httpErrors configuration in web.config file at Angular level (dist folder). All this time I was modifying the Asp.net Core application web.config file. Anyway thanks!