ASP. NET Web Pages (Razor) FAQ
by Tom Fitzmacken| February 7,Print
This article lists some frequently asked questions about ASP. NET Web Pages (Razor) and WebMatrix.
Software versions used in the tutorial
- What ' s the difference between ASP. NET Web Pages, ASP. NET Web Forms, and ASP.
- What ' s the difference between Web Pages and WebMatrix?
- Do I need WebMatrix in order to work with Web Pages?
- Can I use ASP. Web Forms controls on a Web Pages page?
- Can I Deploy an ASP. Web Pages site without using WebMatrix?
- Does I have a to use the Websecurity helper logins?
- Does ASP. NET Web Pages support HTML5?
- Can I use JavaScript and jQuery with Web Pages?
- Additional Resources
For questions on errors and other issues, see the ASP. NET Web Pages (Razor) Troubleshooting guide.
What ' s the difference between ASP. NET Web Pages, ASP. NET Web Forms, and ASP.
All three is ASP. Technologies for creating dynamic Web applications:
ASP. NET Web Pages focuses on adding dynamic (server-side) code and database access to HTML Pages, and features simple and Lightweight syntax.
ASP. NET Web Forms is based on a Page object model and traditional Window-type controls (buttons, lists, etc). Web Forms uses an event-based model that's familiar to those who's ve worked with client-based (Windows Forms) development.
ASP. NET MVC implements the Model-view-controller pattern for ASP. The emphasis is on "separation of concerns" (processing, data, and UI layers).
All three frameworks is fully supported and continue to being developed by the ASP. In general, the choice of which framework to use depends on your background and experience with ASP.
ASP. NET Web Pages in particular is designed to make it easy for people who already know HTML to add server processing to Their pages. It's a good choice for students, hobbyists, people in general who is new to programming. It can also is a good choice for developers who has experience with non-asp.net web technologies.
What ' s the difference between Web Pages and WebMatrix?
ASP. NET Web Pages are a programming framework for creating Pages this run on the server. (see previous question.)
Microsoft WebMatrix is a tool set (an integrated development environment, or IDE) for developing many kinds of web Applica tions. WebMatrix includes tools that is useful for web development, such as a database management tool for SQL Server Compact an d MySQL databases. WebMatrix includes a local Web server (IIS Express) that lets your test pages, and it lets you analyze pages for SEO and fo R errors. It also includes a facility for publishing sites to a hosting provider.
When you install the WebMatrix, you also install ASP. NET Web Pages and other technologies like IIS Express and SQL Server Comp Act. Although these products is included in the WebMatrix installation process, they is also separate products.
The need WebMatrix in order to create ASP. NET Web Pages applications. You can use the also Visual Studio, or use a in the text editor to create pages. (see next question.) However, the tools in WebMatrix make it easier to create and test your pages.
Conversely, you can use WebMatrix to create websites and other than ASP. NET Web Pages applications. For example, you can create applications based on Open-source frameworks like PHP, WordPress, DotNetNuke, joomla!, and Dru Pal.
Do I need WebMatrix in order to work with Web Pages?
No. You can use Visual Studio for work with ASP. NET Web Pages sites. Visual Studio gives many of the features of WebMatrix, plus additional ones like debugging.
If you don ' t want-either WebMatrix or Visual Studio, you can install the component products individually Usingmicro Soft Web Platform Installer. Need the following products:
- Microsoft. NET Framework 4.5
- ASP. NET MVC 5 (which installs the ASP. NET Web Pages framework as well)
- IIS Express (the Web server)
- Microsoft SQL Server Compact 4.0 (the database)
You can use a text editor to edit . cshtml (or . vbhtml) pages.
Managing SQL Server Compact Databases (. SDF files) without a tool is a bit harder. WebMatrix and Visual Studio contain tools for managing . SDF databases. You can also run SQL commands in code to perform many SQL Server management tasks.
To test . cshtml pages without using WebMatrix, you can deploy them to a live server. (See Can I-Deploy an ASP. Web Pages site without using WebMatrix?)
Running IIS Express without using WebMatrix
If you installed WebMatrix, you had IIS Express installed on your computer as a Web server and you can use that to test T He pages. You can run IIS Express from the command line and associate it with a specific port number. You then specify this port when you request the . cshtml files in your browser.
In Windows, the open a command prompt with administrator privileges and the change to C:\Program files\iis Express. (For 64-bit systems, use the folder C:\Program Files (x86) \iis Express.) Then enter the following command, using the actual path to your site:
iisexpress.exe /port:35896 /path:C:\BasicWebSite
You can use any of the port number that isn ' t already reserved by some other process. (Port numbers above 1024x768 is typically free.) path
for the value, use the path of the website folder where the . cshtml files is.
After you run the This command to the set up IIS Express to serve your pages, you can open a browser and browse to a. cshtml file. Use a URLs like the following:
Http://localhost:35896/default.cshtml
For help with IIS Express command line options, enter on the iisexpress.exe /?
command line.
Can I use ASP. Web Forms controls on a Web Pages page?
No. Web Forms controls like the CheckBox control, the validation controls, and the GridView control only work in Web Forms pag ES (. aspx files). These controls require the Web Forms page framework.
Can I Deploy an ASP. Web Pages site without using WebMatrix?
Yes. You can manually copy website files to a server (typically by using FTP). If you are perform a manual copy, you also has to copy the files, which is the support SQL Server Compact (the database). For details, see the blog entry deploying Web Pages applications without a tool.
Does I have a to use the Websecurity helper logins?
No. The provider is part of the SimpleMembership
ASP. NET Web Pages is one option. The security providers that is part of the ASP (that is, might is used to working with Web Forms) is also available. For example, you can use the Forms authentication in ASP. Web Pages just as you would in Web Forms. For one example by use Forms authentication, see the Microsoft support article how to Implement forms-based authent Ication in Your ASP. Application by Using C#.net. To download a simple example, see ASP. NET version of "Login & Password.
For information what to do with Windows authentication, see the blog post Using a Windows authentication in ASP. Es.
Does ASP. NET Web Pages support HTML5?
Yes. The pages you create with ASP. cshtml or . vbhtml pages) is essentially HTML pages that a LSO contain code that runs on the server, before the page is rendered. As long as the user ' s browser supports HTML5, you can use HTML5 elements in a . cshtml or . vbhtml page.
Can I use JavaScript and jQuery with Web Pages?
Absolutely. The pages you create with ASP. cshtml or . vbhtml pages) is just HTML pages with server C Ode in them. Therefore, anything you can does in a normal HTML page by using JavaScript or jQuery can also does in a . cshtml o R . vbhtml page.
The Starter Site template in WebMatrix contains a number of jQuery libraries. If you create a site by using that template, the Scripts folder contains a jQuery core library (jquery-1.6.2. JS) and libraries for jQuery validation (jquery.validate.js, etc).
ASP. NET Web Pages (Razor) FAQ