Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET MVC 4 application and StaticFile / ExtensionlessUrl handlers #37

Closed
LordBenjamin opened this issue Dec 10, 2015 · 11 comments
Closed
Milestone

Comments

@LordBenjamin
Copy link

My ASP.NET MVC 4 application breaks when moving the StaticFile handler above ExtensionlessUrl handler.

However, with the handlers the other way round, the ACME answer file is not served (as documented in letsencrypt-win-simple error message).

Suggest modifying the web.config file in the .well-known/acme-challenge directory as follows:

<?xml version = "1.0" encoding="UTF-8"?>
 <configuration>
     <system.webServer>
         <staticContent>
             <mimeMap fileExtension = ".*" mimeType="text/json" />
         </staticContent>

         <handlers>
           <clear />
           <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule" 
               resourceType="Either" requireAccess="Read" />  
         </handlers>
     </system.webServer>
 </configuration>

By removing all handler mappings except the StaticFileHandler from the acme-challenge directory, we can ensure that the file gets served.

@rkerber
Copy link
Collaborator

rkerber commented Dec 11, 2015

That's what I ended up having to do to get MVC 5 apps to work. I have a pull request #33 that moves the content for the web.config file to the app.config file. Then anyone can update the setting in the letsencrypt.exe.config file with whatever they their web.config file to contain and it will use that content and you won't have to edit the source code and recompile it yourself.

@LordBenjamin
Copy link
Author

Sounds good.

I don't see a problem in making the web.config use the above by default - since the only thing in that directory should be the ACME answer file anyway, so no other handlers are needed.

Correct me if I'm wrong!

@LBegnaud
Copy link
Collaborator

One thing I would point out is that if your IIS site already has those settings applied, the configuration will fail. What I have done to reliably let the web.config apply is to set the removal of those options in the .well-known directory (since this tool only applies a web.config into the acme-challenge directory) as follows:

    <staticContent>
       <remove fileExtension=".*" />
   </staticContent>

@rkerber
Copy link
Collaborator

rkerber commented Dec 16, 2015

I don't think there will end up being a single web.config file that will work for everyone even if it is just under the .well-known directory. That's why I think anyone should be able to update it without recompiling the app from source if they needed to change it. It could be defaulted for what works for the majority of people, and if it doesn't work for someone they can change it easily.

@anemitoff
Copy link

Since the acme-challenge folder is only used for one purpose... why not have the web.config file in that folder use <clear/> as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <clear/>
            <mimeMap fileExtension = ".*" mimeType="text/json" />
        </staticContent>
        <handlers>
            <clear />
            <add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
        </handlers>
    </system.webServer>
</configuration>

@LBegnaud
Copy link
Collaborator

I second this idea. Didn't know enough about IIS config to put it so elegantly, but if this works that is a much cleaner solution.

@LordBenjamin
Copy link
Author

Thanks @anemitoff, your suggested config is exactly what I was aiming for!

@GioviQ
Copy link

GioviQ commented Jan 12, 2016

Thanks @anemitoff I rebuilded with your web.config and now it works.

@rkerber
Copy link
Collaborator

rkerber commented Jan 14, 2016

Partially added in pull #33. I had issues with testing new handler, that only worked on stock IIS on Server 2008 R2 for me. So I went without it as it can now be easily changed, and I went with the method that worked on the most IIS version.
Included web.config has been tested with stock IIS on Server 2012, Server 2012 R2, Server 2016, Win 7, and Win 8.1. If anyone needs to make changes to the web.config file, you can update the web_config.xml file in the root of the app.That is copied instead of using text hard coded in the app. So no more need to recompile to change the web.config.

@rkerber
Copy link
Collaborator

rkerber commented Jan 14, 2016

Added in pull #33.
Included web.config has been tested with stock IIS on Server 2012, Server 2012 R2, Server 2016, Win 7, and Win 8.1. If anyone needs to make changes to the web.config file, you can update the web_config.xml file in the root of the app.That is copied instead of using text hard coded in the app. So no more need to recompile to change the web.config.

@rkerber
Copy link
Collaborator

rkerber commented Feb 1, 2016

Version 1.8 has been released and should fix this for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants