0

A small introduction about the app's deployment & app in general:

We use .Net Core 6 MVC and is hosted in IIS. Additionally the application uses a domain which the actual website is hosted e.g. www.ExampleHost.com/ExampleApp. Also we use Cloudflare to direct requests to a new domain for the website e.g. www.ExampleHost.com/ExampleApp -> www.Example-App.eu

Here is the problem, while the app works fine at www.ExampleHost.com/ExampleApp, if we enter www.Example-App.eu the directory of the app appears in the Url like www.Example-App.eu/ExampleApp in every request. That creates problem everywhere from returning Views to submitting Forms etc.

So an idea was to solve part of this problem by creating a web.config to configure URL Rewrite rules.

web.config

<rewrite>
            <rules>
                <rule name="RemoveExampleApp">
                    <match url=".*ExampleApp/(.*)" />
                    <conditions>
                        <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{R:1}"/>
                </rule>
                <rule name="RemoveExampleAppPost">
                    <match url=".*ExampleApp/(.*)" />
                    <conditions>
                        <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" />
                    </conditions>
                    <action type="Rewrite" url="{R:1}" />
                </rule>
            </rules>
</rewrite>

But we still unable to perform POST requests.

Additionally, I read to another Stack Overflow post that it is possible to configure/fix that by of using routing instead of rewrite rules but we had no luck with that.

IIS URL Rewrite and .NET Core

We are open to any suggestions.

Thanks for your time.

Michalis
  • 1
  • 4
  • Can't u use url rewrite middleware – Gauravsa Oct 12 '22 at 11:45
  • Hey Gauravsa, is there any major difference between configuring rewrite rules with web.config and rewrite middleware? – Michalis Oct 12 '22 at 12:02
  • This document explains the difference between rewrite rules and rewrite middleware and how to use URL rewrite middleware in ASP.NET Core applications https://learn.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-3.0 – YurongDai Oct 13 '22 at 01:58
  • I don't know about Cloudflare, but I wonder why you use Cloudflare to direct requests to a new domain for the website instead of using rewrite rules in IIS directly? – YurongDai Oct 13 '22 at 02:05
  • Well about the Cloudflare unfortunately that's the requirements, and the bad thing is that it adds extra complexity to the system. – Michalis Oct 13 '22 at 06:41
  • When you type `www.Example-App.eu` in your browser, does the URL jump directly to `www.Example-App.eu/ExampleApp`? Do you see the 302 redirect code in the network of the browser console? – YurongDai Oct 13 '22 at 09:31
  • Well initially no but when I wanted to redirect myself to another page e.g. About , the URL would be www.Example-App.eu/ExampleApp/About/Index and would show Not Found Error, that's why we tried to use URL Rewrite rules in web.config to solve this problem. – Michalis Oct 13 '22 at 09:54
  • You mean when you want to redirect the page to www.Example-App.eu/About/Index, but it will actually be redirected to www.Example-App.eu/ExampleApp/About/Index, right? – YurongDai Oct 14 '22 at 09:41
  • Please correct me if I misunderstood what you meant. If I understand correctly, I would like to know how you redirect the page to www.Example-App.eu/About/Index, what kind of rules are used? – YurongDai Oct 14 '22 at 09:45
  • Exactly, the rules we use are the above I show in the web.config, sorry if I overcomplicated the topic. – Michalis Oct 14 '22 at 13:08
  • Please try to use FRT to trace rewrite rules, you can see how the rules are used internally. https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules – YurongDai Oct 17 '22 at 07:06

0 Answers0