I started using ES6 javascript modules in my ASP.NET MVC application but IIS express is refusing to serve javascript file of type module in script tag. I'm getting 401 Unauthorized.
<script src="~/Scripts/index.js" type="module"></script>
When i remove type="module"
from script
tag then it works fine.
Are request filters involved? Can you please help me set them right?
I ran into the same issue in a pretty bare-bones Apache setup for personal use. I was pretty dumbfounded until I came across this.
Check out the small section titled "Server Considerations", which mentions the use of crossorigin="use-credentials"
in the <script>
tag. It sounded only vaguely relevant since I'm working exclusively on a local origin, but I had nothing else to go on so tried it on a whim and it worked.
I can't pretend to understand why, or speak to any unintended consequences, so I would suggest diving into those aspects before pasting this into deployment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With