.CSHTML pages will not be displayed

I am trying to get my server to run .cshtml files. Using WebMatrix 3, I can view the pages by right-clicking and selecting “view in browser”, but this is viewing through the local port. If I try to access pages from the Internet, I get 500 errors.

Here is what I did:

  • I made sure that MVC 3 was installed (but I continue to read that MVC is not needed for .cshtml ... I made sure anyway.
  • I made the whole "go back to parent" / "go back to inherited" thing that is found on many blogs.
  • I was getting 404 error for a while, so I added the "text / html" MIME type to the .cshtml extension. This solved this problem, but only led to my 500 error.

I suspect this is due to my web.config file, because if I delete the file, the page will show, but it reads as text. For example (on the most basic page that I could think of):

@{ var currentTime = dateTime.Now; } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Testing</title> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> </head> <body> The current time is @currentTime . </body> </html> 

The page will look like this:

@{ var currentTime = dateTime.Now;} Current time @currentTime .

However, I do not know what should or should not be in the web.config file. For a month now I have been deceiving my brain ...

Here is what is in the web.config file:

 <configuration> <system.data> <DbProviderFactories> <remove invariant="System.Data.SqlServerCe.4.0" /> <add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" /> </DbProviderFactories> </system.data> <appSettings> <add key="webPages:Version" value="2.0"/> <add key="webpages:Enabled" value="true" /> </appSettings> <system.webServer> <httpErrors errorMode="Detailed" /> </system.webServer> </configuration> 

Thank you very much in advance.

+4
source share
2 answers

It seems that I had an older version ... the answer was given:

Only CSHTML rendering text - static page?

0
source

If you correctly understood that you are having problems running this in IIS (Internet Information Services - Embedded Web Server on Windows). It appears that the directory you are serving is not configured as a web application (but it is configured as a virtual directory). To fix this:

  • Open IIS Manager (Win + R and copy% systemroot% \ system32 \ inetsrv \ iis.msc to the launch window)
  • Go to your directory in the tree on the left (probably \ Sites \ Default Web Site \ something
  • Right-click on it and select "Convert to Application"

These steps should make IIS at least try to display .cshtml.

In a separate note .cshtml (i.e. ASP.NET MVC) is much easier to learn and understand than .asp (i.e. just ASP.NET)

0
source

Source: https://habr.com/ru/post/1496648/


All Articles