Webmatrix: Web Pages
Webmatrix: Web Pages
Web Pages
WebMatrix
Microsoft WebMatrix is a free tool (stack) from
Microsoft that developers can use to create, customize,
and publish websites to the Internet. WebMatrix
supports many different options to build sites.
Content Page
_Header.cshtml
<div id="header">
<h1>.: Bapatla Engineering
College::Bapatla :.</h1>
<hr />
</div>
_Footer.cshtml
<div id="footer">
<hr />
<p>Copyright © 2011 Bapatla
Engineering College | All Rights
Reserved</p>
</div>
Default.cshtml
@{
var PageTitle = "Branches Offered";
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@PageTitle</title>
</head>
<body>
<center>
@RenderPage("/Shared/_Header.cshtml")
<h2>@PageTitle</h2>
Default.cshtml
<ol style="list-style-type: none">
<li>CSE</li>
<li>IT</li>
<li>ECE</li>
<li>EIE</li>
<li>EEE</li>
<li>MECH</li>
<li>CIVIL</li>
<li>CHEMICAL</li>
</ol>
@RenderPage("/Shared/_Footer.cshtml")
</center>
</body>
</html>
OUTPUT
Razor C# - Layout template
To create a common web page design throughout the
website, Layout pages are used.
@ProductHelpers.ProductInfo(“PenDrive",
“USB 8 GB", 5.00)
Razor C# - Functions
Functions are static methods that can be called from
anywhere in the WebMatrix application.
Unlike helpers, which can return only a block of
HTML for rendering in the browser, a function can
return any valid C# type.
Razor C# - Functions
Razor C# - Functions
Razor C# - Session State
HTTP is a stateless protocol. This means that a Web
server treats each HTTP request for a page as an
independent request.
The server retains no knowledge of variable values
that were used during previous requests.
ASP.NET session state identifies requests from the
same browser during a limited time window as a
session, and provides a way to persist variable values
for the duration of that session
Razor C# - Session State
The ASP.NET session state facilitates to store and
retrieve data per user, as they browse the web
application.
A session is started when the user first visits a page in
the web site and ends either when the user closes the
browser, or when the session “times out” due to
inactivity after a predetermined period of time (set in
IIS as twenty minutes, by default).
Razor C# - Session Variables
Session variables are stored in a dictionary on the server,
and are unique to each visitor per session. Session
variables are exposed through the Session property of
the WebPage object
The Session variable collection is indexed by a string or an
integer index.
Session variables do not have to be explicitly added to the
collection, they can simply be added or retrieved by
referring to their name or index.
By default, session variables can hold any valid .NET data
type, including generic collections and custom objects.
Razor C# - Session Variables
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Session Variables</title>
</head>
<body> @if(Session["UserName"]!=null){
<p>Hello, @Session["UserName"]</p> }else{
<p>Visit Login Page</p>
}
</body>
</html>
Razor C# - Session Variables
@{
if(IsPost){
Session["UserName"]=Request["uname"];
Response.Redirect("~/Default.cshtml");
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Login Page</title>
</head>
Razor C# - Session Variables
<body>
<h1>Welcome</h1>
<h1> Bapatla Engineering College</h1> <form
action="" method="post" >
<input type="text" name="uname" id="uname"
/></br>
<input type="password" name="upass"
id="upass" /></br> <input
type="submit" value="login" </form> </body>
</html>
Razor C# - Session Identifier
All sessions created and maintained by the server are
given a unique identifier, which is stored in the
SessionID property of the page.
Each new request for a page is examined to see if it
already has a valid SessionID–if one is not present;
the server starts a new session and assigns a new
SessionID.
Razor C# - Cookies
Cookies provide a means in Web applications to store
user-specific information.
For example, when a user visits your site, you can use
cookies to store user preferences or other information.
When the user visits your Web site another time, the
application can retrieve the information it stored earlier.
A cookie is a small bit of text that accompanies requests
and pages as they go between the Web server and
browser. The cookie contains information the Web
application can read whenever the user visits the site.
Razor C# - Cookies
For example, if a user requests a page from your site and
your application sends not just a page, but also a cookie
containing the date and time, when the user's browser gets
the page, the browser also gets the cookie, which it stores in
a folder on the user's hard disk.
Later, if user requests a page from your site again, when the
user enters the URL the browser looks on the local hard disk
for a cookie associated with the URL. If the cookie exists, the
browser sends the cookie to your site along with the page
request. Your application can then determine the date and
time that the user last visited the site.
Razor C# - Cookies
Response.Cookies[“LastVisit"].Value =
"patrick";
Response.Cookies[“LastVisit"].Expires =
DateTime.Now.AddDays(1);