Site not recognizing .cshtml extension, but routing works

Discussion in 'ASP.NET / ASP.NET Core' started by mikepope, Jun 1, 2011.

  1. I recently deployed/published a WebMatrix site, so it has .cshtml files. The site works fine -- as long as I do not use .cshtml extensions on the request. For example, this works:

    http://mikepope.com/testmembership/home

    But this gets a 404.7 error:

    http://mikepope.com/testmembership/home.cshtml

    Apparently IIS is configured on the server not to recognize the .cshtml extension. Is there something that needs to be done to get IIS to recognized .cshtml extensions and not throw on those?

    Thx!
     
  2. See Bruce's reply below.
     
  3. Bruce

    Bruce DiscountASP.NET Staff

    by default, cshtml is blocked by Request filtering (not our setting but it was inserted by MSFT).

    You can override this setting with IIS manager.

    We will talk about removing this restriction server wide.
     
  4. Hi, thanks for your reply. In IIS Manager (which I'm using remotely), I'm not seeing the app for request filtering. To be precise, I see it for my local IIS server (localhost, basically), but not for the server on the domain that I have here on Discountasp.net. My intent was to following the instructions here: Request Filtering <requestFiltering>
     
  5. Sorry about the confusion, its not delegated. Its ok though its prob easier to just add the following to your web.config:

    Code:
            <security>
                <requestFiltering>
                    <fileExtensions>
                        <remove fileExtension=".cshtml" />
                        <add fileExtension=".cshtml" allowed="true" />
                    </fileExtensions>
                </requestFiltering>
            </security>
     
  6. Just checking to make sure everything worked.
     
  7. Yes! Worked. Sorry for the delay. I did have to look up that the parent element needed to be <system.webServer>, but that was easy enough. :)

    Thanks for your help.
     
  8. Hi, guys. I talked to some folks on the ASP.NET team at Microsoft, and they were curious about this part of our discussion. One of the PMs said this:

    "We don't put anything in config that would block .cshtml. So I want to know what config they had and where it was that they had to put that workaround for you. I really doubt we block anything but I would want to fix our product if we do."

    Can you help clarify where the issue is and what the team might do to help make sure this isn't a blocker for the site?

    Thx,

    Mike
     
  9. Bruce

    Bruce DiscountASP.NET Staff

    The rules are in the request filtering (.cshtm, .cshtml) are listed as denied extensions.

    I have no idea when this configuration got in there.

    These entries exist in server deployed long before razor came out and I am almost certain that we didn't manually put these entries in.
     
  10. Where?

    I didn't have a web.config file, but when I added it, it had the following code in it:

    Code:
    <?xml version="1.0"?>
    
    <configuration>
        <system.web>
            <compilation debug="false" targetFramework="4.0" />
        </system.web>
    </configuration>
    
    Does it go inside or outside, or before or after the 'configuration'? Does it go inside or outside, or before or after the 'system.web'?

    Thanks.
     
  11. Under Configuration. So something like:

    <configuration>
    <system.webServer>
    <security>
    <requestFiltering>

    </requestFiltering>
    </security>
    </system.webServer>

    <system.web>
    <compilation debug="false" targetFramework="4.0" />
    </system.web>
    </configuration>
     
  12. Thank you Chuck.

    Now I am getting a "HTTP Error 500.19 - Internal Server Error":

    The requested page cannot be accessed because the related configuration data for the page is invalid.

    It doesn't like
    Code:
    <compilation debug="false" targetFramework="4.0" />
     
  13. mjp

    mjp

    Make sure the ASP.NET Version for your site is set to 4.0 in Control Panel.
     
  14. YES! YES! YES!

    We now be digging on James Brown...I feel good.:D

    Thank you, thank you, thank you.:)
     
  15. mjp

    mjp

    Cool, glad it's working for you now.
     

Share This Page