projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.12k stars 652 forks source link

Url rewrite rules not being applied when set in applicationHost.xdt #2598

Closed xt0rted closed 6 years ago

xt0rted commented 7 years ago

I moved my url rewrite rule that forced HTTPS from my web.config over to an applicationHost.xdt. The rule is an exact copy of the one from the Xdt transform samples wiki page. When the rule was in my web.config it worked as expected, once this was moved to the applicationHost.xdt it stopped being applied.

I've restarted the site a number of times now, I've even verified the applicationHost.config by running

D:\home\site> type c:\dwasfiles\sites\#1standard\config\applicationHost.config > myAppHostConfig.config
D:\home\site> type D:\local\config\applicationHost.config > myAppHostConfig.config

When I copy the rewrite contents from the applicationHost.config to my web.config the rule is applied, but only when it's in this file does that happen.

I have other things in my applicationHost.xdt such as the custom & server header removal which are being applied, so I know the transform worked. It's just this rewrite rule that's not.

The site in question is on the account with dummy1326 and is the site with the word portal in it. The rule right now is set to Temporary while debugging this, but prior to this it was set to Permanent.

davidebbo commented 7 years ago

See https://github.com/projectkudu/kudu/wiki/Azure-Site-Extensions#understanding-what-could-go-wrong-with-xdt-transforms. It sounds like you're in the 3rd category in the Understanding what could go wrong with xdt transforms section, right? If so, it's more of an IIS issue than xdt, as xdt has done its job as well as it can.

xt0rted commented 7 years ago

There's a site extension that does this, plus the example on the wiki page. Does this mean neither of those actually work and we should be putting our rewrite rules in the web.config only?

xt0rted commented 7 years ago

I'm not sure what's happened but there's other reports of the site extension no longer working at https://github.com/gregjhogan/redirect-http-to-https-site-extension/issues/9#issuecomment-333919642. In my tests my own applicationHost.xdt didn't work, and the site extension doesn't either. For now I've moved my url rewrite rules back into my web.config since they work fine in there.

davidebbo commented 7 years ago

I was looking to confirm whether you were in the 2nd or the 3rd category described in that page, as saying the site extension no longer working can potentially mean either. Can you confirm which it is?

But note that I just tried the exact sample Redirect http traffic to https in a test app and it works fine for me. Can you try it on a clean empty app to help isolate?

xt0rted commented 7 years ago

Just installed that extension onto my test site and it's working. http://dummy1326.azurewebsites.net

davidebbo commented 7 years ago

Ok, so it may be something specific to your other site prevents it from working for some reason? At least that gives you something to try isolating.

xt0rted commented 7 years ago

Comparing the applicationHost.config between my two sites shows almost everything is the same, the main differences being the site extensions (installed all but app insights) and the site bindings section.

In the test site I have

<configuration>
  <system.applicationHost>
    <sites>
      <site name="dummy1326" id="360704197">
        <bindings>
          <binding protocol="http" bindingInformation="*:80:dummy1326.azurewebsites.net" />
          <binding protocol="https" bindingInformation="*:443:dummy1326.azurewebsites.net" />
        </bindings>
      </site>
    </sites>
  </system.applicationHost>
</configuration>

In my other site I have the following where ****** is the site's name

<configuration>
  <system.applicationHost>
    <sites>
      <site name="******" id="1492821249">
        <bindings>
          <binding protocol="http" bindingInformation="*:80:******" />
          <binding protocol="https" bindingInformation="*:443:******" />
        </bindings>
      </site>
    </sites>
  </system.applicationHost>
</configuration>
davidebbo commented 7 years ago

It would be an interesting test to temporarily replace the wwwroot content of your site with a trivial site (static index.html) to see if that makes it work. If it does, then it's something about the content that's throwing it off.

xt0rted commented 7 years ago

I added an index.html and basic web.config that matches my other site as much as it can. The applicationHost.xdt is also the same one that wasn't fully working on my other site. The url rewrite rule is still being applied on the test site though.

davidebbo commented 7 years ago

Sorry, I don't follow. Did it work or not after changing wwwroot to have only those two files?

And if it didn't work, did you check whether you were in the 2nd or the 3rd category described in that page? This is really key information.

xt0rted commented 7 years ago

It continues to work after adding the index.html & web.config to wwwroot.

I think I'm in the 3rd category. The applicationHost.config does show the changes from the applicationHost.xdt but they aren't being applied even after multiple restarts of the site.

I have two more instances of the site in question on another account that I think had the same issue but I didn't confirm before rolling out the web.config updates. I won't be able to look into those until this coming weekend probably. If I can repo on one of those then that'll be much easier to work with since they aren't production instances.

xt0rted commented 6 years ago

I'm no longer using this approach for some of my url rewriting so I'm closing this.