Question

The Problem When I try to get to my ASP.NET Web Page Razor pages using the cshtml extension, they work fine. If I remove the extension, WordPress tries to look up the URL as if it were a blog post and I can't get to the page or use "pretty" URLs via Razor.

I am hosting with Winhost. I have WordPress installed in my root application directory. That directory contains the following Web.cofig file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <add value="index.php"/>
      </files>
    </defaultDocument>
    <rewrite>
      <rules>
                <rule name="wordpress" patternSyntax="Wildcard">
                    <match url="*"/>
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                        </conditions>
                    <action type="Rewrite" url="index.php"/>
                </rule>
        </rules>
    </rewrite>
  </system.webServer>
</configuration>

My application is in the sub-folder "/app". You can test out the problem yourself by going here:

http://www.cutrategamer.com/app/game-deals-chart.cshtml

Then try going here:

http://www.cutrategamer.com/app/game-deals-chart/

The page works fine without the cshtml extension on my local machine.

Does anyone know how to resolve this?

Was it helpful?

Solution

Before the wordpress rule, add a rule to catch the /app traffic and stop processing rules, something like this:

<rule name="razorapp" stopProcessing="true">
    <match url="^app/*"/>
    <action type="None" />
</rule>

Not sure if that is exactly correct, but you should get the idea. You need to short circuit the rewrite module before it processes the wordpress rule in your config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top