aspnet / BasicMiddleware

[Archived] Basic middleware components for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
169 stars 84 forks source link

Is the rewrite middleware required even if hosting .NET Core in IIS? #221

Closed pjmagee closed 7 years ago

pjmagee commented 7 years ago

I'm getting .NET Core runtime exceptions when I enable my rewrite rule in the web.config. However when I disable the rewrite rule (force http to https) the application works fine.

I am also behind an ELB and so I had to modify a generic rule a little to support being behind an ELB.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout" forwardWindowsAuthToken="false" />
    <rewrite>
      <rules>
        <clear />
        <rule name="Redirect to https" stopProcessing="true" enabled="false">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
          </conditions>
          <action type="Redirect" url="https://{SERVER_NAME}{URL}" redirectType="Found" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>  
</configuration>

The rewrite "happens" but then I get a runtime exception in .NET core about a missing URL. So I just wanted to know if I do need to use this middlware. If I disable the rewrite rule, the application works fine.

Tratcher commented 7 years ago

What was the actual runtime exception? Type, message, stack trace, etc?

There are a few scenarios where you need to use the middleware instead of the web.config. E.g. the IsFile condition does not work in web.config because it assumes a different file layout than our projects use.

pjmagee commented 7 years ago

@Tratcher I will post the stacktrace tomorrow.

muratg commented 7 years ago

We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have.