[RESOLVED]The extension '.cshtml' doesn't work on subdirectory

cshtml pages don’t work only in a sub-directory of a subdomain. We have a main domain where cshtml works on ‘X’ subdirectory folder, but we have a sub-domain where the root directory is a sub-directory of the main domain and cshtml doesn’t work there. On
IIS, main domain and sub-domain have their own application pool. The ‘X’ sub directory of the main domain has been converted to application and cshtml pages are working. We tried to accomplish the same process, but we have the following error :

This type of page is not served. Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension ‘.cshtml’ may be incorrect. Please review the URL below and make sure that it is spelled correctly.

Requested URL: /test/test.cshtml

This a simple test file, which works on the main domain sub-directory, but not on the sub-domain sub-directory. I think it is the parent domain that blocks, "it has been explicitly forbidden."

On Handler Mappings the extension is active. (Windows Server 2012 R2, IIS 8.5)

The server has the .NET Framework 4 installed. Also the application is running in an application pool that’s configured to use that version of the.NET Framework.

/home/main_domain/X_subdirectory (works cshtml)

/home/main_domain/sub_domain/subdirectory (doesn’t work cshtml)

Do you have any ideas ?

The following code gives to me an Internal error :

<system.webServer>
   <security>
    <requestFiltering>
       <fileExtensions>
          <remove fileExtension=".cshtml" />
          <add fileExtension=".cshtml" allowed="true" />
       </fileExtensions>
     </requestFiltering>
   </security>
 </system.webServer>

Ref : http://www.asp.net/web-pages/overview/more-resources/aspnet-web-pages-%28razor%29-troubleshooting-guide

Adding this to my web.config doesn’t work neither.

<configuration>
  <appSettings>
    <add key="webpages:Enabled" value="true" />
  </appSettings>
</configuration>

The sub directory where it works is configured as a Web Application :

  1. On IIS manager (Win + R and copy %systemroot%system32inetsrviis.msc)

  2. On the directory in the tree on the left (SitesMain_domainsub_directory

  3. List item Right click on it and I chose "Convert to Application"

If you directly put cshtml in browser it will not work. You need to put your valid URL which you have configured through routing.

When I put directly the cshtml on the browser works for the other subdirectory. It is a simple .cshtml page.

Hi coronadouglass,

According to your description, it works fine if you convert it to the application. So I think it is the independent project and you let it in the main project.

If that is the case, since they are independent, you need to convert it to the application.

Best Regards

Starain Chen

Leave a Reply