the complete asp.net (iis) tutorial with code example in power point slide show
DESCRIPTION
SP.NET is a server-side Web application framework designed for Web development to produce dynamic Web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime (CLR), allowing programmers to write ASP.NET code using any supported .NET language. The ASP.NET SOAP extension framework allows ASP.NET components to process SOAP messages.TRANSCRIPT
Information Services (IIS) 6.0 is a powerful Web server that provides a highly reliable, manageable, and scalable Web application infrastructure for all versions of Windows ◦ Compatibility with Microsoft and Other Products◦ Rapid Installation and Configuration◦ Easy Service Management◦ Effortless Performance Monitoring◦ Easy to Implement Security◦ Foundation for ASP.NET◦ IIS pass the request from client to application
Web Server (IIS)Web Server (IIS)
Web ServerWeb Server
Server Machine
ASP (.Net)
Server Machine
ASP (.Net)
Web server (IIS)Web server (IIS)
Client Machine
Client Machine
Client Machine
Client Machine
Client Machine
Client Machine
http request http request http request
Web Server
IIS
Web
Server
IIS
Web
Server
8080
15251525
88998899
(Default Port)
Port Nos.
192.168.0.12Server IP
http://192.168.0.12/myfoler/WebForm1.aspx
http://192.168.0.12:8899/index.html
Is the platform that we use to create Web applications and Web services that run under IIS
At a high level, ASP.NET is a collection of .NET classes that collaborate to process an HTTP request and generate an HTTP response
It provides high level of consistency across web applications
We have components like web development tools,◦ System.web namespace◦ Server and HTML controls
ASP .Net
ASP.NET is a managed server-side framework ◦ For building applications based on HTTP, HTML, XML and SOAP◦ ASP.NET relies on IIS for an HTTP entry point
ASP.NET supports building HTML-based Web applications◦ Based on ASP.NET pages, Web forms and server-side controls
ASP.NET supports building Web services◦ Based on Web service classes and WebMethods
ASP.NET
CLR
Windows 2000 or Windows .NET Server
IIS
HTML over HTTP
XML/SOAP over HTTP
Web Application client
Web Service client
ASP .Net Frame Work
Executable portion of a web application are compiled Enriched tool support ASP.NET applications are based on CLR, so therefore
they are powerful and flexible. On the fly updates deployed without restarting server Better session management Integration with ADO.NET Built in features for caching XML Web services let you create distributed Web
applications Browser-independent Language-independent
ASP.NET programming model is based on applications◦Each application is based on IIS virtual directory
◦Each application is contained within a physical directory
◦Each application runs in its own isolated AppDomain
AssemblyInfo.cs◦ All the information about assembly including
version company name etc
Webform1.aspx◦ The visual description of a Web form.
Webform1.aspx.cs/vb◦ The code that responds to events on the Web
form
Global.asax ◦ The global events that occur in web application
are here
Web.config◦ It is a XML file that web server uses when
processing this application
References ◦ System◦ System.Data◦ System.Drawing◦ System.XML
Webform Views ◦ Design view
The design View represents the user interface.
◦ HTML view. Represents ASP.NET syntax for the webpage
System. Object
System.Web.UI
System.Web.UI.Control
System.Web.UI.Web Controls System.Web.UI.HTMLControls
Component Examples Description
Server controlsServer controls
TextBoxLabelButtonListBoxDropDownListDataGrid
These controls respond to user events by running event procedures on the server. Server controls have built-in features for saving data that the user enters between page displays.
HTML controlsHTML controls
Text AreaTableImageSubmit ButtonReset Button
These represent the standard visual elements provided in HTML. HTML controls are useful when the more complete feature set provided by server controls is not needed.
Data controlsData controls
SqlConnectionSqlCommand,OleDbConnection,OleDbCommandDataSet
Data controls provide a way to connect to, perform commands on, and retrieve data from SQL and OLE databases and XML data files.
ASP.NET stores items added to a page’s ViewState property as hidden fields managed by the ASP.NET page framework.
As soon as form is submitted for processing, all information relevant to the view state of the page is stored within this hidden form field.
View state is enabled for every page by default.
Hidden ViewState control of name-value pairs stored in the Web Form
Adjustable at Web Form and control level
<%@ Page EnableViewState="False" %>
<asp:ListBox id="ListName" EnableViewState="true" runat="server">
</asp:ListBox>
<input type="hidden" name="__VIEWSTATE" value="dDwtMTA4MzE0MjEwNTs7Pg==" />
The validation controls check the validity of data entered in associated server controls on the client before the page is posted back to the server.
Supports validation on client and server Client-side validation is provided by a JScript
library named WebUIValidation.js Can force down-level option
<% @ Page Language="c#" ClientTarget="DownLevel" %>
Validation control Description
RequiredFieldValidator Check whether a control contains data
CompareValidatorCheck whether an entered item matches an entry in another control
RangeValidatorCheck whether an entered item is between two values
ValidationSummaryDisplay validation errors in a central location or display a general validation error description
Validation control Description
RegularExpressionValidator Check whether an entered item matches a specified format
CustomValidator Check the validity of an entered item using a client-side script or a server-side code, or both
HTTP is a stateless protocol, which means that it does not automatically indicate whether a sequence of requests is all from the same client or even whether a single browser instance is still actively viewing a page or site. As a result, building Web applications that need to maintain some cross-request state information (shopping carts, data scrolling, and so on) can be extremely challenging without additional infrastructure help.ASP.NET provides the following support for sessions:
•A session-state facility that is easy to use, familiar to ASP developers, and consistent with other .NET Framework APIs.
•A reliable session-state facility that can survive Internet Information Services (IIS) restarts and worker-process restarts without losing session data.
•A scalable session-state facility that can be used in both Web farm (multicomputer) and Web garden (multiprocess) scenarios and that enables administrators to allocate more processors to a Web application to improve its scalability.
•A session-state facility that works with browsers that do not support HTTP cookies.
•A throughput equivalent to that of ASP (or better) for core session-state scenarios (50/50 read/write when putting items into shopping carts, modifying last page visited, validating credit card details, and so on).
Session State
Session
Server Machine
ASP.Net Progs.
Server Machine
ASP.Net Progs.
Create Session
Session Name “XX”
Session Value “cmc”
Client Machine
“XX” Session with “cmc”
Client Machine
“XX” Session with “cmc”
Client Machine
“XX” Session with “cmc”
Client Machine
“XX” Session with “cmc”
Client Machine
“XX” Session with “cmc”
Client Machine
“XX” Session with “cmc”
Session “XX” is available till the browser is open, delete automatically when the browser is closed
Web page 1(Creating Session)(Creating Session)
Session.Add(“session_name", “session_value”)
Web page 1(Creating Session)(Creating Session)
Session.Add(“session_name", “session_value”)
Web page 2
(Accessing Session)(Accessing Session)
variable = Session(“session_name")
Web page 2
(Accessing Session)(Accessing Session)
variable = Session(“session_name")
Session
User Id
Password LoginLogin
TextBox1
Session.Add(“user_session", TextBox1.Text)
Login ID
stud1
******
stud1Label1
Label1.Text=Session.Add(“user_session")
Web Page 1
Web Page 2
Session
•A cookie is a small piece of information stored by the browser at local disk.
• Each cookie is stored in a name =value; pair called a crumb(that is, if the cookie name is "id" and you want to save the id's value as "this", the cookie would be saved as id=this)
•In a cookie up to 20 name=value pairs can be stored
•Cookie is always returned as a string of all the cookies that apply to the page.
•It stores information in cookie folder.
•It expires when browser is closed if expired time is not set.
Cookie
Cookie
Server Machine
ASP.Net Progs.
Server Machine
ASP.Net Progs.
Create Cookie
Cookie Name “CC”
Cookie Value “edu”
Create Cookie
Cookie Name “CC”
Cookie Value “edu”
Client Machine
Create “CC” Cookie
Client Machine
Create “CC” Cookie
Client Machine
Create “CC” Cookie
Client Machine
Create “CC” Cookie
Client Machine
Create “CC” Cookie
Client Machine
Create “CC” Cookie
[CC] edu
[CC] edu
[CC] edu
Local Disk
Dim MyCookie As New HttpCookie("CMCcookie")
Dim now As DateTime = DateTime.Now
MyCookie.Value = TextBox1.Text
MyCookie.Expires = now.AddSeconds(100)
Response.Cookies.Add(MyCookie)
Dim MyCookie As New HttpCookie("CMCcookie")
Dim now As DateTime = DateTime.Now
MyCookie.Value = TextBox1.Text
MyCookie.Expires = now.AddSeconds(100)
Response.Cookies.Add(MyCookie)
Cookie
Dim ck As HttpCookieck = Request.Cookies("CMCcookie")If ck Is Nothing Then Exit SubEnd If TextBox1.Text = ck.Name TextBox2.Text = ck.Value
Dim ck As HttpCookieck = Request.Cookies("CMCcookie")If ck Is Nothing Then Exit SubEnd If TextBox1.Text = ck.Name TextBox2.Text = ck.Value
studentstudent
Set CookieSet Cookie
TextBox1
CMCcookieCMCcookie
studentstudent TextBox2
TextBox1
Show CookieShow Cookie
Cookie
Dim i, j As Integer
Dim arr1() As String
Dim MyCookieColl As HttpCookieCollection
Dim MyCookie As HttpCookie
MyCookieColl = Request.Cookies
' Capture all cookie names into a string array.
arr1 = MyCookieColl.AllKeys
For i = 0 To arr1.GetUpperBound(0)
MyCookie = MyCookieColl(arr1(i))
Response.Write("Cookie: " & MyCookie.Name & "<br>")
Response.Write("Value " & MyCookie.Value & "<br>")
Response.Write("Expires: " & MyCookie.Expires & "<br>")
Response.Write("Secure:" & MyCookie.Secure & "<br>")
Next i
Display All Cookies From Local
Machine
Display All Cookies From Local
Machine
Application
•Application variables are, in effect, global variables for a given ASP.NET application.
•Client-side application developers, ASP.NET programmers should always consider the impact of storing anything as a global variable.
•Share information throughout the application by using the Application class
•This class exposes a key-value dictionary of objects that you can use to store both .NET Framework objects and scalar values related to multiple Web requests from multiple clients.
•The memory impact of storing something in application state. The memory occupied by variables stored in application state is not released until the value is either removed or replaced.
Application
Server Machine
ASP.Net Progs.
Server Machine
ASP.Net Progs.
Create Application
Session Name “My_App”
Session Value “India”
Create Application
Session Name “My_App”
Session Value “India”
Client Machine
Accessing “My_App” with value “India”
Client Machine
Accessing “My_App” with value “India”
Client Machine
Accessing “My_App” with value “India”
Client Machine
Accessing “My_App” with value “India”
Client Machine
Accessing “My_App” with value “India”
Client Machine
Accessing “My_App” with value “India”
Application
Server MachineServer Machine
Application(“My_App") = “India”
Server MachineServer Machine
Application(“My_App") = “India”
Client 1Client 1
x=Application(“My_App")
TextBox1.Text=x
IndiaIndia
Client 2Client 2
y=Application(“My_App")
TextBox1.Text=y
IndiaIndia
Client 3Client 3
z=Application(“My_App")
TextBox1.Text=z
IndiaIndia
Caching
•Caching, use to create high-performance Web applications.
•Caching are Output Caching and Data Caching
•Output Caching allows to store dynamic page and user control responses
•On subsequent requests, the page or user control code is not executed.
•The cached output is used to satisfy the request.
•Data Caching can use to programmatically store arbitrary objects, such as data sets, to server memory so that your application can save the time and resources it takes to recreate them.
Caching (Output Cache)
<%@ OutputCache Duration="30" VaryByParam="location;count" %><%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="cacheing.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<BODY>
-------------------------------------------------
-------------------------------------------------
</BODY>
</HTML>
WebForm1.aspx (Html View)
Response.Write("<font size=6>The Page was executed " & DateTime.Now.ToString + "</font>")
If RadioButton1.Checked = True Then
Label1.Text = "You have selected... Red color"
Else
Label1.Text = "You have selected... Blue color"
End If WebForm1.aspx.vb
Caching (Data Cache)
Dim flag As Integer source = Cache("MyDataCache") If source Is Nothing Then flag = 100 cmd = New OleDb.OleDbCommand("select * from dept ", conn) adp = New OleDbDataAdapter(cmd) ds = New DataSet() adp.Fill(ds, “deptX")
source = New DataView(ds.Tables("deptX "))
Cache.Insert("MyDataCache", source, New Caching.CacheDependency(Server.MapPath("datacache")), DateTime.Now.AddSeconds(20), Cache.NoSlidingExpiration) End If DataGrid1.DataSource = source DataGrid1.DataBind() If flag = 100 Then Label1.Text = "Data from Database" Else Label1.Text = "Data from Cache" End If
WebForm1.aspx.vb
Ad Rotator Control
•AdRotator control to display a randomly selected advertisement banner on the Web page.
•The displayed advertisement can change whenever the page refreshes.
•Advertisement information is stored in a separate XML file.
•The XML file allows you to maintain a list of advertisements and their associated attributes. Attributes include the path to an image to display, the URL to link to when the control is clicked, the alternate text to display when the image in not available, a keyword, and the frequency of the advertisement.
•AdRotator control to display a randomly selected advertisement banner on the Web page.
•The displayed advertisement can change whenever the page refreshes.
•Advertisement information is stored in a separate XML file.
•The XML file allows you to maintain a list of advertisements and their associated attributes. Attributes include the path to an image to display, the URL to link to when the control is clicked, the alternate text to display when the image in not available, a keyword, and the frequency of the advertisement.
Ad Rotator Control
<Advertisements> <Ad> <ImageUrl>image1.jpg</ImageUrl> <NavigateUrl>http://www.microsoft.com</NavigateUrl> <AlternateText>Microsoft Main Site</AlternateText> <Impressions>80</Impressions> <Keyword>Topic1</Keyword> </Ad> <Ad> <ImageUrl>image2.jpg</ImageUrl> <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl> <AlternateText>Wing Tip Toys</AlternateText> <Impressions>80</Impressions> <Keyword>Topic2</Keyword> </Ad></Advertisements>
<Advertisements> <Ad> <ImageUrl>image1.jpg</ImageUrl> <NavigateUrl>http://www.microsoft.com</NavigateUrl> <AlternateText>Microsoft Main Site</AlternateText> <Impressions>80</Impressions> <Keyword>Topic1</Keyword> </Ad> <Ad> <ImageUrl>image2.jpg</ImageUrl> <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl> <AlternateText>Wing Tip Toys</AlternateText> <Impressions>80</Impressions> <Keyword>Topic2</Keyword> </Ad></Advertisements>
WebForm1.aspx (Design View)
Ad Rotator ControAd Rotator Contro
Ads.xml
AdvertisementFile=“Ads.xml”
Image1.jpg, image2.jpg and other picture file
should be added to the current project
Ad Rotator Control
<Advertisements> <Ad> <ImageUrl>image1.jpg</ImageUrl> <NavigateUrl>http://www.microsoft.com</NavigateUrl> <AlternateText>Microsoft Main Site</AlternateText> <Impressions>80</Impressions> <Keyword>Topic1</Keyword> </Ad> <Ad> <ImageUrl>image2.jpg</ImageUrl> <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl> <AlternateText>Wing Tip Toys</AlternateText> <Impressions>80</Impressions> <Keyword>Topic2</Keyword> </Ad></Advertisements>
<Advertisements> <Ad> <ImageUrl>image1.jpg</ImageUrl> <NavigateUrl>http://www.microsoft.com</NavigateUrl> <AlternateText>Microsoft Main Site</AlternateText> <Impressions>80</Impressions> <Keyword>Topic1</Keyword> </Ad> <Ad> <ImageUrl>image2.jpg</ImageUrl> <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl> <AlternateText>Wing Tip Toys</AlternateText> <Impressions>80</Impressions> <Keyword>Topic2</Keyword> </Ad></Advertisements>
WebForm1.aspx (Design View)
Ad Rotator ControAd Rotator Contro
Ads.xml
AdvertisementFile=“Ads.xml”
Image1.jpg, image2.jpg and other picture file
should be added to the current project
There are some advanced list controls like Repeater, DataList, and DataGrid
They take collections of data and loop through them automatically.
They act as containers for other controls that actually display the data such as labels.
These controls are very powerful and save developers a lot of manual work.
Advanced List Controls
Provides simple output of a list of items Templates provide the visual form It iterates over the bound data, rendering its
ItemTemplate once for each item in the DataSource collection
Useful to have complete control over how data from a data source is rendered
No paging Can provide templates for separators Does not provide update data
Repeater Control
Standard templates for Repeater controls◦ HeaderTemplate: rendered once before all data
bound rows◦ ItemTemplate: rendered once for each row in the
data source◦ AlternatingItemTemplate: like ItemTemplate, but
when present is used for every other row◦ SeparatorTemplate: rendered between each row◦ FooterTemplate: rendered once, after all data
bound rows
Repeater Control
To bind embedded controls to the data source of the container control DataBinder.Eval() method is used
DataBinder.Eval() method is provided by .net to evaluate expression
Syntax◦ <%# DataBinder.Eval(Container.DataItem,“DataFieldname") %>◦ Container represents the container for data items ◦ DataField represents the name of data item field
Repeater Control
Provides list output with editing Default look is a table Customized via templates Directional rendering (horizontal or vertical) Alternate item Updateable No paging
DataList Control
Full-featured list output Default look is a grid Default is to show all columns, though you
can specify a subset of columns to display Columns can be formatted with templates Optional paging Updatable
DataGrid Control
ASP.NET supports tracing ◦ Easy way to include “debug” statements ◦ No more messy Response.Write() calls!
Great way to collect request details◦ Server control tree◦ Server variables, headers, cookies◦ Form/Query string parameters◦ Tracing provides a wealth of information about the
page Can be enabled at page- or application- level
Tracing
Methods◦Trace.Write: Writes category and text to trace◦Trace.Warn: Writes category and text to trace in
red Properties
◦Trace.IsEnabled: True if tracing is turned on for the application or just that page
◦ Tracemode = "[SortByTime | SortByCategory Trace.axd
◦ is an Http Handler( An Http Handler is a coding option that allows us to handle request/responses at the most basic level).
Tracing
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"
/>
Tracing
.NET Common Language Runtime provides structured Exception handling using try catch block.
ASP.NET provides declarative application custom error handling◦ Automatically redirect users to error page when
unhandled exceptions occur◦ Prevents ugly error messages from being sent to
users<customErrors mode="RemoteOnly"/>
Error Handling
Mode attribute is either set into On or RemoteOnly .
On◦ Error messages will be displayed in client and well as server where application is running
RemoteOnly◦ Error messages will be displayed only at client location
Error Handling
Custom Error Pages Can specify error pages for specific HTTP
status codes in web.config<configuration> <customerrors mode=“remoteonly” defaultredirect=“error.htm”> <error statuscode=“404” redirect=“adminmessage.htm”/> <error statuscode=“403” redirect=“noaccessallowed.htm”/> </customerrors> </configuration>
Error Handling
Subhas MalikSoftware Developer(R&D Web ERP).
Microsoft SQL Server , C# , Ajax , Jquery , WCF , WPF , Telerik , MVP, MVC.Kolkata, West Bengal, India.
Subhas Malik writes about a wide range of technology and products, but has a particular focus on internet technology, browsers, software development (both back end and font end), cyber security, mobile technology and many others related to Information Technology. He joined blog/tech forum/developer community since 2009 and has also covered blogger, Microsoft, codeplex, stackoverflow, slideshare, linkedin, codeproject, c-sharpcorner, youtube, quora, stackexchange, soundcloud, Google, Yahoo, servers, supercomputing, Linux, other open-source software, and science and many other tech community.follow in blogger, wordpress , google+, Facebook, twitter, rediff mypage and itimes.
Subhas MalikSoftware Developer(R&D Web ERP).
Microsoft SQL Server , C# , Ajax , Jquery , WCF , WPF , Telerik , MVP, MVC.Kolkata, West Bengal, India.
Subhas Malik writes about a wide range of technology and products, but has a particular focus on internet technology, browsers, software development (both back end and font end), cyber security, mobile technology and many others related to Information Technology. He joined blog/tech forum/developer community since 2009 and has also covered blogger, Microsoft, codeplex, stackoverflow, slideshare, linkedin, codeproject, c-sharpcorner, youtube, quora, stackexchange, soundcloud, Google, Yahoo, servers, supercomputing, Linux, other open-source software, and science and many other tech community.follow in blogger, wordpress , google+, Facebook, twitter, rediff mypage and itimes.
Thank You!