0

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%\system32\inetsrv\iis.msc)

  2. On the directory in the tree on the left (\Sites\Main_domain\sub_directory

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

nandoC
  • 119
  • 3
  • 11
  • Are you trying to access the raw `.cshtml` file over the network? Why? `.cshtml` files are supposed to be processed as part of the ASP.NET engine, the resulting content should then be served to the client. Since you've tagged this as MVC 4, that means you access the views by using the routes defined in your application at startup. Your request will hit a controller based on the requested path, which will serve the appropriate view. – mason Oct 01 '14 at 16:55
  • I tried that the ASP.NET engine will be able to process the code of a .cshtml file on the sub-directory. I don't use views. A simple code as you see in this page : http://www.w3schools.com/aspnet/showfile_c.asp?filename=try_razor_cs_004 – nandoC Oct 01 '14 at 20:44
  • The same code works on other sub-directory where this directory has been converted to application via IIS, but with the subdomain doesn't work – nandoC Oct 01 '14 at 20:48
  • If you are using .cshtml files, then you are using Views. You will need to configure routing as I described so that the .cshtml files get processed by the engine with the resulting HTML sent to the client. – mason Oct 01 '14 at 20:51
  • How exactly I do that ? web.conf ? – nandoC Oct 01 '14 at 21:00
  • 1
    No, not web.config. Go do any MVC tutorial, it's likely to cover the basics of controllers, views, and routing. – mason Oct 01 '14 at 21:06

1 Answers1

0

if you are trying to acces directly to the view try this

"This type of page is not served." error when trying to browse on *.cshtml files

or try to work with areas or make your own routing

ASP.NET MVC 2: View Subfolders?

Community
  • 1
  • 1