VSB
VSB

Reputation: 10415

Can CSHTML files run directly?

I'm just started asp.net using Razor V2 syntax. While I'm developing in Visual Studio, everything is fine however when i try to run .CSHTML files directly from browser, they do not work.
I want to know are .CSHTML files are intended to run directly or they must be used in other segments of web applications which can not be called by browser directly?

Upvotes: 2

Views: 24331

Answers (2)

Mike Brind
Mike Brind

Reputation: 30120

Yes - cshtml pages can be run directly. If you build an ASP.NET Web Pages (Razor) site, you can request .cshtml pages directly and they will be served (unless the file name starts with an underscore).

You can build a Razor Web Pages site by going to File » New » Web Site. You can get more information about ASP.NET Web Pages from here: http://www.asp.net/web-pages. It is the recommended starting point for people who are new to ASP.NET development.

[UPDATE] They can also be run directly when used as part of a Razor Pages site which was introduced in ASP.NET Core 2.0.

Upvotes: 5

tulde23
tulde23

Reputation: 408

By default mvc blocks access to views using an http handler in web.config.

Upvotes: 1

Related Questions