How to, ASP.NET (Part1: Razor Page / Web Pages)
<p> The time is @DateTime.Now</p>
href
Builds a URL using the specified parameters.
RenderBody()
Renders the portion of a content page that is not within a named section (In layout pages)
RenderPage(page)
Renders the content of one page within another page.
RenderSection(section)
Renders the content of a named section (In layout pages).
Write(object)
Writes the object as an HTML-encoded string.
WriteLiteral
Writes an object without HTML-encoding it first.
IsPost
Returns true if the HTTP data transfer method used by the client is a POST request.
Layout
Gets or sets the path of a layout page.
Page (.Title, .Version)
Provides property-like access to data shared between pages and layout pages.
Request
Gets the HttpRequest object for the current HTTP request.
Server
Gets the HttpServerUtility object that provides web-page processing methods.
Database
For database operation.
WebMail
Performs mail functions.
Analytics
Generate difference type of analytic trackers.
Bing
Generate Microsoft search box.
Chart
Generate chart.
Crypto
Data encryption.
Facebook
Generate Facebook like button.
FileUpload
Renders UI for uploading files.
GamerCard
Renders the specified Xbox gamer tag.
Gravatar
Renders the Gravatar image for the specified email address.
Json
Json data manipulation
LinkShare
Renders social networking links using the specified title and optional URL.
ObjectInfo
Renders the properties and values of an object and any child objects.
Recaptcha
Renders the reCAPTCA verfication test.
ServerInfo
Renders status information about ASP.NET Web Pages.
Twitter Object Reference
Renders a Twitter stream.
Video
Renders a video object. (* Flash, MediaPlayer, Silverlight)
WebCache
Caching manipulate.
WebGrid
Renders data in table format.
WebImage
Image manipulate.
For Loop
<html>
<body>
@for(var i = 10; i < 21; i++)
{
<p>Line @i</p>
}
</body>
</html>
For Each
<html>
<body>
<ul>
@foreach (var x in Request.ServerVariables)
{<li>@x</li>}
</ul>
</body>
</html>
While Loop
<html>
<body>
@{
var i = 0;
while (i < 5)
{
i += 1;
<p>Line @i</p>
}
}
</body>
</html>
If .. Else
@{var price=20;}
<html>
<body>
if (price>30)
{
<p>The price is too high.</p>
}
else
{
<p>The price is OK.</p>
}
</body>
</html>
Template
<p>This is header text</p>
@RenderBody()
<p>© 2014 W3Schools. All rights reserved.</p>
Any web page
@{Layout=“Layout.cshtml”;}
<h1>Welcome to W3Schools</h1>
Preventing Files Direct Access
Files with a name that starts with an underscore cannot be browsed from the web.
e.g _Layout.cshtml
Account
Contains logon and security files
App_Data
Contains databases and data files
Images
Contains images
Scripts
Contains browser scripts
Shared
Contains common files
Virutal root
~
Physical path
Server.MapPath
Web browser known path
Href method ( e.g. href=“@Href(myStyleSheet)” )
_AppStart Page
Startup page for the application. If this page exists, ASP.NET runs it the first time any page in the site is requested.
_PageStart Page
Code that runs before any page in each folder.
WebGrid
Generate data in table form (* support paging and sorting)
Chart
Generate chart from arrays, databases or files.
WebMail
Provides functions for sending email messages using SMTP
WebImage
Manage images (* filp, rotate, resize, watermark)
This is a file extension of SQL Server Compact database.
A built in authorization (based on user account)
@{
WebSecurity.InitializeDatabaseConnection(“Users”, “UserProfile”, “UserId”, “Email”, true);
}
“Users” is the name of the WebSecurity database (Users.sdf).
“UserProfile” is the name of the database table that contains the user profile information.
“UserId” is the name of the column that contains the user IDs (primary key).
“Email” is the name of the column that contains user names.
(* The last parameter true is a boolean value indicating that the user profile and membership tables should be created automatically if they don’t exist, otherwise false. However, auto creation doesn’t include the database file itself.)
Additional setting on Web.config
<appSettings>
<add key=“enableSimpleMembership” value=“true” />
</appSettings>