0

Yes, this is a newbie question and might be ridiculous, but I'm apparently having tremendous difficulty finding an answer to get up and running.

I've created an ASP.NET Razor (v3) web site using the Visual Studio template. That's fine and I can see everything locally. However, when I try to view the Default.cshtml page on the server I get this error:

Server Error in '/' Application. 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: /4.6.1Razor/Default.cshtml

My server administrator says this: You are not supposed to access a cshtml file directly on a production server, it’s blocked by default. Please access an html, htm, asp or aspx file and use that to get the data from the cshtml.

Okay ... so how exactly do I access a cshtml file via an aspx file? Or can someone point me to a working sample that I can look at?

The default files that Visual Studio created did not include an html, htm, asp, or aspx file so I'm a little confused as to how to start that. Also, the samples that Visual Studio points to are of course broken: http://www.asp.net/aspnet/samples/aspnet-web-pages.

A little help pointing me to the right direction would be appreciated. Thanks.

Maybe the question should be ... What kind of page / file (.asp or .aspx or what) do I need to render a .cshtml file and how do I do that. I've tried a .aspx file with the code: @RenderPage("Default.cshtml") but when I view the file in a browser it just echoes @RenderPage("Default.cshtml") instead of rendering anything.

testing123
  • 761
  • 6
  • 13
  • 37
  • Render the CSHTML page as partial view using javascript. – J Santosh Mar 21 '16 at 14:44
  • Is this an Asp.Net MVC project, or a web forms project with the razor view engine? – Crowcoder Mar 21 '16 at 14:51
  • I was going for Web Pages with Razor and avoiding the MVC. – testing123 Mar 21 '16 at 15:13
  • You'll have to figure out from your admin what your server actually supports (framework version, application pools) based on that response. ASP.net _handles_ a "mixture" of "files" (`aspx`, `cshtml`, `vbhtml`, `ashx`, etc. etc.). Also check that when you publish your WebPages site, that all the dlls in `/bin` are included (which could be part of the issue). – EdSF Mar 21 '16 at 15:15
  • @user5753132, Then your administrator has to allow that extension or you have to give up razor and use aspx. – Crowcoder Mar 21 '16 at 15:16
  • Sigh. OK. Web Forms it is. Thanks for the info. – testing123 Mar 22 '16 at 12:38
  • So if I change my project to an Asp.Net MVC project. How would I render the Index.cshtml page? – testing123 Mar 22 '16 at 13:26

2 Answers2

0

This answer suggests you need to enable WebPages in the <appSettings> section of web.config:

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

If this is not enough, check this question for server software requirements to process WebPages.

For IIS application configuration, have a look at this description.

Community
  • 1
  • 1
devio
  • 36,858
  • 7
  • 80
  • 143
-1

If that doesn't work. Go to IIS --> MIME Types --> Check if the extension .cshtml exists, if not add it.

Erick Kamamba
  • 268
  • 1
  • 4
  • With Default.html I get this error: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. I can view the Default.cshtml page fine locally ... – testing123 Mar 21 '16 at 14:35
  • Changing the Default.cshtml to Default.html makes the page lose all formatting. – testing123 Mar 21 '16 at 14:59
  • @Kamamba, If you edit the question I will un-downvote, just don't say you can just change the file extension to html – Crowcoder Mar 21 '16 at 15:09
  • @Kamamba `cshtml` is server-side code. Changing the extension to `html` makes no sense, it will send the server-side code to the client. – Panagiotis Kanavos Mar 21 '16 at 15:14
  • @Crowcoder, I have edited. I didn't mean to have him to html for permanently. I wanted him to test if the server can process the page. That was for testing purposed only. – Erick Kamamba Mar 21 '16 at 19:37
  • @PanagiotisKanavos, I know that, but you can comment the code and test to see if the server process the file. The intention was to find the root cause – Erick Kamamba Mar 21 '16 at 19:39