.CSHTML

CSHTML File

ASP.NET Razor Web Page
Ask a question
QUICK ANSWER

A .cshtml file is an ASP.NET Razor view - a server-side template that mixes C# code and HTML. The web server compiles it and sends rendered HTML to the browser; end users never see the file itself. Developers open it in Visual Studio or VS Code with the C# Dev Kit extension. To see the rendered page, run the ASP.NET project with F5 in Visual Studio or dotnet run from the command line.

Developer: Microsoft Category: Web Files MIME: text/html
OPENS ON Windows macOS Linux

On this page

19k+ extensions indexed
Last reviewed Jul 9, 2026

Not sure what your file is?

Drop any file into our identifier - we read just the first bytes to name the format.

Identify a file

What is the CSHTML file format?

A .cshtml file is an ASP.NET Razor server-side web template that combines C# code and HTML markup in a single source file. The format was introduced in January 2011 with ASP.NET MVC 3 as part of Microsoft's Razor view engine.

The @ character is the core syntactic marker: wherever it appears, the Razor parser switches from HTML rendering mode into C# execution mode. A view may include @model declarations, @using namespace imports, @functions blocks, tag helpers, HTML helpers, and @section slots for a shared _Layout.cshtml page. The Razor engine compiles the file server-side to C#, then to .NET intermediate language (IL); only the rendered HTML is ever sent to the browser - the .cshtml source is never exposed to clients.

The cs prefix distinguishes these files from .vbhtml Razor views that use Visual Basic instead of C#. ASP.NET Core 2.0 introduced Razor Pages, which also use .cshtml but add an @page directive at the top, making the file act as its own self-contained controller and view. For single-page application patterns, Blazor components use the .razor extension and largely replace .cshtml in new ASP.NET Core projects.

.cshtml files are edited in Visual Studio or Visual Studio Code with the C# Dev Kit. Opening one directly in a browser displays raw source code rather than rendered HTML.

Security & safety

RISK: LOW

.cshtml is a plain text source file - opening it in a text editor or IDE is harmless. Servers should be configured to block direct HTTP access to .cshtml files (IIS and Kestrel do this by default). A misconfigured server that serves .cshtml as raw text could leak application logic and connection strings - a security risk for the server operator, not for the person reading the file locally.

Format details

in a nutshell
FULL NAMEASP.NET Razor Web Pageaka Razor view file, C# HTML view
DEVELOPERMicrosoftsince 2011 (ASP.NET MVC 3 / Razor syntax v1)
CATEGORYWeb Files
MIME TYPEtext/html
TYPEServer-side web template (text, C# + HTML)

Programs that open CSHTML files

Windows4 apps
Visual Studio Freemium Open the .cshtml file; provides full Razor IntelliSense, syntax highlighting, and F5 local debugging. The primary IDE for ASP.NET development.
Windows Notepad Built-in Open for basic text reading; no syntax highlighting.
Notepad Open-source Open the file to read/edit raw source; no Razor-specific IntelliSense but syntax highlighting available with ASP.NET plugin.
Visual Studio Code (with C# Dev Kit) Open-source Install the 'C# Dev Kit' extension; open the .cshtml for syntax highlighting and Razor IntelliSense.
macOS2 apps
TextEdit Built-in Open as plain text (switch to plain text mode); useful only for quick inspection.
Visual Studio Code (with C# Dev Kit) Open-source Primary Razor editor on macOS; install C# Dev Kit extension for IntelliSense and project support.
Linux2 apps
gedit Open-source Open for plain-text viewing/editing; no Razor IntelliSense.
Visual Studio Code (with C# Dev Kit) Open-source Install C# Dev Kit extension for full Razor support on Linux.

Technical details

deep spec
EncodingUTF-8 text (default in Visual Studio; other encodings supported)
ContainerPlain text - interleaved C# code and HTML markup; no binary wrapper
MIME typetext/html (rendered output to browser); text/plain for the source file in editors
Razor syntax marker@ character switches from HTML rendering mode into C# execution mode
CompilationCompiled server-side by the Razor engine to C#, then to .NET IL; source file never delivered to the browser
Key directives@model, @using, @functions, @section, @page (Razor Pages), @inject
Razor syntax versionv1 (MVC 3, 2011) → v2 (MVC 4) → v3 (MVC 5/Core 1) → Razor 8 (ASP.NET Core 8, 2023)
Tag helpersSupported from ASP.NET Core 1.0; replace HTML helpers for server-rendered attribute generation
Layout system_Layout.cshtml defines shared page chrome; views use @section blocks to inject content
Associated OSWindows (IIS/IIS Express), Linux and macOS (Kestrel, Docker)
Razor Pages variant@page directive makes a .cshtml file a self-contained controller+view (ASP.NET Core 2.0+)
Client exposureSource file never served to the browser; direct access returns raw text or an HTTP error
VB counterpart.vbhtml (identical Razor syntax using Visual Basic instead of C#)
Modern successor pattern.razor (Blazor components) for SPA-style applications in ASP.NET Core
Released2011 (ASP.NET MVC 3 / Razor syntax v1)
Latest versionRazor 8 (ASP.NET Core 8.0, November 2023)
Specificationlearn.microsoft.com

CSHTML conversions

Community Q&A

asked by users
Ask a quick question
Get help from people who work with CSHTML files. Be specific - include your system and software version.
No account needed · answers usually within a day

No questions yet - be the first to ask about CSHTML files.

Frequently asked questions

What is a .cshtml file?
An ASP.NET Razor view template - a mix of C# server-side code and HTML markup. The web server compiles and executes it to produce HTML; end users only see the rendered output, never the .cshtml file itself.
How do I open a .cshtml file?
In a text editor like VS Code (with C# Dev Kit for IntelliSense) or Notepad++. To see the rendered output, run the ASP.NET project with Visual Studio (F5) or the dotnet CLI ('dotnet run').
Why can't I open a .cshtml file in my browser?
Browsers cannot execute server-side Razor code. Opening the file locally shows raw source. To see the page it produces, run it through an ASP.NET web server.
What is the difference between .cshtml and .aspx?
.aspx is the older ASP.NET Web Forms view syntax; .cshtml is the newer Razor syntax introduced in 2011. Razor (.cshtml) is cleaner, more concise, and is the recommended approach for all new ASP.NET projects.
What is the difference between .cshtml and .razor?
.cshtml is an ASP.NET MVC/Razor Pages view; .razor is a Blazor component file. Both use Razor syntax, but .razor is for component-based SPAs. They are not interchangeable.
Can I convert a .cshtml file to HTML?
Not as a simple file conversion - the .cshtml needs a live ASP.NET host with data from a controller to render. You can run the project locally and save the browser's HTML output (Ctrl+S), but it won't include dynamic/AJAX content.

References

1Microsoft Docs - Razor syntax reference for ASP.NET Corelearn.microsoft.com
2Microsoft Docs - Views in ASP.NET Core MVClearn.microsoft.com

Keep exploring

across the database

Top extensions this week

1.AQQAQQ Instant Messenger File
2.BINCD/DVD Disc Image (BIN/CUE)
3.MDMarkdown Document
4.PARTPartial Download File
5.RPMSGRestricted Permission Message
6.CRDOWNLOADChrome Partial Download File
7.NOMEDIAAndroid No-Media Marker File
8.PRDXSoftMaker Presentations Document
9.PRO6XProPresenter 6 Bundle File
10.SWFSmall Web Format (Shockwave Flash)

Related extensions

.CRDOWNLOADChrome Partial Download File
.JNLPJava Network Launch Protocol file
.WEBARCHIVESafari Web Archive
.PARTPartial Download File
.DOWNLOADPartial / Incomplete Download File
.ASPXActive Server Page Extended (ASP.NET Web Form)

Free file tools

An in-browser file identifier and image converter - everything runs on your device.

Open the toolbox

Browse file extensions A-Z