Can CSHTML files run directly?

2020-07-23 09:32发布

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?

标签: c# asp.net razor
2条回答
爷的心禁止访问
2楼-- · 2020-07-23 09:42

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

查看更多
聊天终结者
3楼-- · 2020-07-23 09:53

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.

查看更多
登录 后发表回答