title: Blazor WebAssembly - how to add a "http to https" URL rewrite rule in auto-generated web.config
body: <p>I have a Blazor WebAssembly app which I want to automatically redirect to https if the user is attempting to access the web page via http.</p>
  <p>For other non-WASM sites, I would do this within IIS Configuration, using &quot;URL Rewrite&quot; to redirect any such calls to the https equivalent. These rules are directly stored in a web.config file in the web folder.</p>
  <p><a href="https://i.stack.imgur.com/9zqcP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9zqcP.png" alt="IIS - URL Rewrite" /></a></p>
  <p>However, when publishing a Blazor WebAssembly app to IIS, Visual Studio creates its own web.config file
  which contains other url rewrite rules required for the SPA to run/route correctly:</p>
  <p><a href="https://i.stack.imgur.com/GGube.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GGube.png" alt="Auto-generated web.config file" /></a></p>
  <p><a href="https://i.stack.imgur.com/fdnGp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fdnGp.png" alt="Contents of auto-generated web.config file" /></a></p>
  <p>After publishing to IIS, I can go in and create my &quot;http -&gt; https&quot; rule, which then gets added to the previously-generated web.config file.</p>
  <p><a href="https://i.stack.imgur.com/h4q7U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h4q7U.png" alt="Adding my new redirection rule" /></a></p>
  <p>The redirection from http to https then works a treat.</p>
  <p>However, each time I publish the app to IIS, this web.config file will be overwritten, and my http to https rule lost.</p>
  <p>Is there a way of defining this redirection rule somewhere within the Visual Studio Blazor WebAssembly project, such that it will automatically be included in the auto-generated web.config?</p>
  <p>Any guidance would be greatly appreciated.</p>