Applications What We Use Day To Day Are Divided Into Different Categories Like
Applications What We Use Day To Day Are Divided Into Different Categories Like
NET
ASP.NET is an Open-Source Web Framework, created by Microsoft, for building Modern Web Apps and
Services with .NET using C# or VB.NET or F# languages. ASP.NET extends the .NET platform with tools and libraries
specifically for building Web Apps.
.NET is Platform Independent i.e., applications that are developed by using .NET can run on multiple
Platform’s and to run .NET Applications on a machine that machine should be 1st installed with a software i.e., .NET
Runtime. Microsoft provided us 3 different .NET Runtimes that came over a period, like:
.NET Framework Runtime
.NET Core Runtime
.NET Runtime
.NET Framework Runtime was launched in the year 2002 and this is available only for Windows Platforms.
The first version of this Runtime is 1.0 and the last version is 4.8.
.NET Core Runtime was launched in the year 2016 and this is available for multiple platforms like Windows,
Linux, and Mac. The first version of this Runtime is 1.0 and the last version is 3.1.
.NET Runtime is also same as .NET Core Runtime which was launched in the year 2020 and this is also
available for multiple platforms like Windows, Linux, and Mac. This is a combination of .NET Framework and .NET
Core and evolved as “One .NET”. The first version of .NET Runtime started with 5.0 and we call this as .NET 5 and the
latest is .NET 6.
In .NET Framework we have been provided with ASP.NET Framework for building Web Applications and
under this we have different options like:
ASP.NET Web Forms
ASP.NET MVC
ASP.NET Web API
In .NET CORE, .NET 5, and so on, we have been provided with ASP.NET Core Framework for building Web
Applications and under this also we have different options again, like:
ASP.NET Core Web App (Razor Pages)
ASP.NET Core Web App (Model-View-Controller)
ASP.NET Core Web API
Note: ASP.NET Core is the open-source version of ASP.NET that can be developed and run-on Windows, Linux,
macOS, and Docker. This was first released in 2016 and is a re-design of earlier Windows-Only versions of ASP.NET.
Performance is a key focus of ASP.NET Core which is faster than other popular web frameworks as per independent
TechEmpower benchmarks. Like the rest of .NET, ASP.NET is also open source on GitHub which has over 100,000
contributions and 3,700 companies have already contributed.
Applications what we use day to day are divided into different categories like:
Desktop Applications
Web Applications
Mobile Applications
1
Desktop Applications means, these applications must be installed on our computer first to consume them.
Example: MS Office, Skype Messenger, Zoom, Browsers, Visual Studio, SQL Server Management Studio, etc.
Web Applications means, we install these applications on a centralized machine or server known as Web Server and
then clients all over the World can access these application by connecting to the Web Server thru Internet.
Example: Facebook, Gmail, Amazon, Flipkart, etc.
Mobile Applications are also like Desktop Applications only i.e., we need to install them on our Mobiles or Tablets
to consume, but they work with the help of Internet like a Web Application.
Example: WhatsApp, Swiggy, Zomato, Uber, Ola, etc.
2
What is Internet?
Ans: Internet is a global system of interconnected computer networks that use the standard Internet protocol suite
(TCP/IP) to link several billion devices worldwide. It is a network of networks that consists of millions of private,
public, academic, business, and government networks, of local to global scope, that are linked by a broad array of
electronic, wireless, and optical networking technologies. Internet carries an extensive range of information,
resources, and services, such as the inter-linked hypertext documents and applications of the World Wide Web
(WWW), the infrastructure to support email, and peer-to-peer networks for file sharing and telephony.
3
How does a Browser Display a Web Page?
All Web Pages contain instructions for display and the Web Browser displays the page by reading those
instructions.
The most common display instructions are called HTML.
Summary:
If you want other people to view your Web Site or Application, you must copy your Site to a Public Server.
Even if you can use your own PC as a Web Server but it is very common to let an ISP host your Site.
Included in Web Hosting solution you can also expect Domain Name Registration and standard Email Services.
Hosting your Site or Application on your own Server is always an option and here are some points to consider:
1. Hardware Expenses: To run a “real” Web Site or Web Application, you will have to buy some powerful Server
hardware. Don’t expect that a low-cost PC will do the job. You will also need a permanent (24 hours a day) high-
speed internet connection.
2. Software Expenses: Remember that Server-Licenses often are higher than Client-Licenses. Also note that
Server-Licenses might have limit on number of users.
3. Labour Expenses: Don’t expect low labour expenses. You must install your own hardware and software. You
also must deal with bugs and viruses and keep your server constantly running.
Benefits of using an Internet Service Provider (Public Server): renting a Web Server from an ISP is a very common
option and most small companies store their Web Site or Web Application on a Server provided by an ISP only. Here
are some advantages:
1. Connection Speed: Most ISPs have very fast connections to the Internet.
2. Security and Stability: ISPs are specialists on Web Hosting. Expect their Servers to have more than 99% up time,
the latest software patches, and the best Virus Protection.
3. Powerful Hardware: ISPs often have powerful Web Servers that can be shared by several companies. You can
also expect them to have an effective Load Balancing, and necessary Backup Servers.
4
2. Daily Backup: Make sure your ISP runs a daily backup routine; otherwise, you may lose valuable data.
3. Traffic Volume: Study the ISP’s traffic volume restrictions. Make sure that you don’t have to pay a fortune for
unexpected high traffic if your Site becomes popular.
4. Content Restrictions: Study the ISP’s content restrictions if you plan to publish pictures or broadcast video or
sound and make sure that you can do it.
5. E-mail Capabilities: Make sure your ISP supports the Email capabilities you need.
6. Database Access: If you plan to use data from Databases in your Site, make sure your ISP supports the Database
access you need.
What is TCP/IP?
Ans: TCP/IP stands for Transmission Control Protocol / Internet Protocol, is a family of protocols for communication
between computers. It defines how electronic devices should be connected over the network, and how data should
be transmitted between them.
TCP: is responsible for breaking down data into small packets before they can be sent over a network, and for
assembling the packets again when they arrive.
IP: takes care of the communication between computers. It is responsible for addressing, sending, and receiving
the data packets over the Internet.
TCP/IP Protocols for the Web: web browsers and servers use TCP/IP protocols to connect to the Internet. Common
TCP/IP protocols are:
1. HTTP: Hyper Text Transfer Protocol takes care of the communication between a Web Server and a Web Browser.
HTTP is used for sending requests from a Web Client (Browser) to a Web Server, returning Web Content (Web
Pages) from the Server back to the Client.
2. HTTPS: Secure HTTP, takes care of secure communication between a Web Server and a Web Browser. HTTPS
typically handles Credit Card transactions and other sensitive data.
3. FTP: File Transfer Protocol, takes care of transmission of files between Computers.
4. SMTP: Simple Mail Transfer Protocol, used to send or receive Emails between Senders and Receivers.
IP is Connection-Less:
IP is a “connection-less” communication protocol.
IP does not occupy the communication line between two computers. This reduces the need for network lines.
Each line can be used for communication between many different computers at the same time.
With IP, messages are broken up into small independent “packets” and sent between computers via the
Internet. IP is responsible for “routing” each packet to the correct destination.
IP Routers:
When an IP Packet is sent from a computer, it arrives at an IP Router.
IP Router is now responsible for “routing” the packet to the correct destination, directly or via another Router.
Communicating via IP is like sending a long letter as many small postcards, each finding its own way to the
receiver.
IP Addresses:
This is a unique identification for every device in the network.
IP uses 32 bits or four bytes numeric value where each number should be ranging between 0 to 255.
5
IP addresses are normally written as four numbers separated by a period, like this: 31.13.65.36.
Each device must have a unique IP address before it can connect to the Internet.
Each IP packet must have an address before it can be sent to another computer.
This is an IP address: 31.13.65.36. This might be the same address: www.facebook.com
Domain Names:
A name is much easier to remember than a 12-digit number.
Names used for IP addresses are called Domain Names; for example, “www.facebook.com” is a domain name.
When you address a web site, like “www.facebook.com”, the name is translated to a number by a Domain Name
Server (DNS).
All over the world, DNS Servers are connected to the Internet. DNS servers are responsible for translating
Domain Names into IP Addresses.
When a new Domain Name is registered together with an IP Address, DNS Servers all over the world are updated
with this information.
What is a DNS?
DNS stands for Domain Name System.
A DNS Server is responsible for informing all other computers on the Internet about the Domain Name and the
Web Site address.
Registering a Domain:
Domains can be registered from Domain Name registration companies.
These companies provide an interface to search for available Domain Names, and they offer a variety of Domain
Name extensions that can be registered at the same time.
1. Short - People don’t like to type! So, a short Domain Name is always easier to type, read, and remember.
2. Meaningful - A short domain is nothing without meaning, “34i4nh.com” is not easy to enter or to remember.
Select a domain that relates to your site in a way that people will understand about your site.
3. Clear - Clarity is important when selecting a Domain Name. Avoid a name that is difficult to spell or pronounce.
4. Exposure - Names that are short and easy to remember are an asset. In addition to visitors, also consider
search engines. Search engines index your site and rank it for relevance against terms people search for your
sites, consider including a relevant search term in your domain.
6
What is web hosting?
Ans: Web hosting is a service provided by companies that sell or lease space on a server where you can store the
files that make your website accessible on the internet. This typically requires that you own a domain, and these
companies may help you in purchase one.
Domain Name Servers (DNS): it is the Internet’s equivalent of a phone book. They maintain a directory of Domain
Names and translate them to IP Addresses. This is necessary because, although Domain Names are easy for people
to remember, computers or machines, access websites based on IP Addresses only. Information from all the Domain
Name Servers across the Internet are gathered and housed at the Central Registry. Host companies and Internet
Service Providers interact with the Central Registry on a regular schedule to get updated DNS information.
The Internet Assigned Numbers Authority (IANA): manages IP address space allocations globally and delegates five
Regional Internet Registries (RIRs) to allocate IP address blocks to local Internet Registries like ISP’s and other
entities. A Regional Internet Registry (RIR) is an organization that manages the allocation and registration of Internet
number resources within a particular region of the world. The Regional Internet Registry system eventually dividing
the world into 5 RIR’s:
African Network Information Center (AFRINIC) for Africa.
American Registry for Internet Numbers (ARIN) for the United States, Canada, several parts of the Caribbean
region, and Antarctica.
Asia-Pacific Network Information Centre (APNIC) for Asia, Australia, New Zealand, and neighboring countries.
Latin America and Caribbean Network Information Centre (LACNIC) for Latin America and parts of the Caribbean
region.
Reseaux IP European’s Network Coordination Centre (RIPE NCC) for Europe, Russia, Middle East, and Central
Asia.
Till now you might have created some Web Pages by using HTML, Java Script, and CSS, and are able to access those
pages from your local machines by using their physical path or address in the browser; but how can we access
those Web Pages from remote machines within a network?
Ans: If we want to provide access to the Web Pages, we have developed to remote machines we need to take the
help of a Server Software known as “Web Server”.
What is a Server?
Ans: It is software which works on 2 principles like request and response. There are so many Servers software’s in
the industry, like Server Operating Systems (Windows Servers, Linux, Solaris, etc.) Database Servers (Oracle, SQL
Server, and My SQL etc.), Application Servers, Web Servers, etc., and for us what we need is a Web Server to provide
access to our Web Pages to Remote Clients.
7
What Web Server software’s are available for us to consume?
Ans: There are so many Webservers software’s that are available in the market like Apache Web Server from Apache,
Nginx Web Server from NGINX, IIS Web Server from Microsoft, GWS Web Server from Google, LiteSpeed Web Server
from LiteSpeed Technologies, but the most compatible Web Server for ASP.NET Applications is IIS Web Server from
Microsoft.
Note: If IIS is not installed on your machine, we get the below error:
“HTTP Error 404. The requested resource is not found.”
Installing IIS on our machine if not installed already: Go to Control Panel => click on Programs and Features => In
the window opened, click on “Turn Windows features on or off”, which opens another window called “Windows
Features” => in the new window opened select the CheckBox “Internet Information Services” and also select each
and every Sub-Item (Checkbox’s) under it and click on the Ok button which will install IIS on your machine, then
restart your machine. Once IIS is installed on your machine re-verify whether it is working or not by using the above
URL.
8
To access Web Pages thru IIS Web Server, do the following:
Step 1: Create a folder on your PC in any drive naming it as “ASP”.
Step 2: Create an HTML Page with the name “Login.html” with the below code and save it into the “ASP” folder.
<!DOCTYPE html>
<html>
<head><title>Login Form</title></head>
<body>
<form>
<table align="center">
<caption>Login Form</caption>
<tr>
<td>User Name:</td>
<td><input type="text" id="txtName" name="txtName" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" id="txtPwd" name="txtPwd" /></td>
</tr>
<tr>
<td align="center" colspan=2>
<input type="submit" value="Login" />
<input type="reset" value="Reset" />
</td>
</tr>
</table>
</form>
</body>
</html>
If we want to access Web Pages thru Web Server, we are provided with 3 different options:
Option 1: Accessing thru “Default Web Site”, because this Website is already created under IIS Web Server we can
access our Web Pages thru the Site and to do that we need to copy our Web Pages to a folder that is linked with this
Website i.e., “<OS Drive>:\inetpub\wwwroot” and if we copy our Web Pages into this folder we can access them
thru IIS using their “Virtual Path” either from a local or a remote machine also. To test this let’s copy our “Login.html”
file into this folder and then access it thru the Virtual Path of the file as following:
Note: for every Web Site that is created on IIS, there will be 1 associated folder on the Hard Disk and all the Web
Pages of that Site should be placed into that folder, right now “Default Web Site” is mapped with the “wwwroot”
folder and that is the reason why we placed our “Login.html” Page into that folder. To view the mapping folder of
“Default Web Site”, right click on the “Default Web Site” in “IIS Manager” Window => select “Manage Website” and
under that select “Advanced Settings” which opens a window and in that we find “Physical Path” property and beside
that we find the folder that is mapped to this Web Site.
9
Option 2: Accessing them thru an Application or Virtual Directory created under Default Web Site, in this case
without copying all the Web Pages into “inetpub/wwwroot” folder as we did in the previous case, we can create an
“Application or Virtual Directory” under “Default Web Site” and map them to our physical folder where we have
saved our Web Pages i.e., “ASP” Folder.
To create an Application or Virtual Directory, Right Click on “Default Web Site” in “IIS Manager”, select the
option “Add Application” or “Add Virtual Directory” which opens a Window and in that, in “Alias” TextBox enter a
name of your choice and under “Physical Path” TextBox enter the physical path of your folder i.e., "<drive>:\ASP".
Now following the above process, create 1 Application with the name “Site1” and create 1 Virtual Directory
with the name “Site2” and map both to our physical folder i.e., “ASP”. From now we can access the page of this
folder in any of the following ways:
Option 3: Accessing the Web Pages by creating a Site. In this case we create a new Site under IIS just like the existing
site i.e., Default Web Site and map it to a physical folder, but the difference is; in this case we can give our own Host
Name or Domain Name just like “localhost” which is the Host Name or Domain Name for “Default Web Site” or we
can use the same Host Name i.e., “localhost” and change the Port No.
Creating a new Site by changing Port No: right click on “Sites” node in “Connections” panel and select the option
“Add Website”, which opens a new window and in that window under “Site name” Textbox specify a name to the
site for example: “NitSite1” and under “Physical path” TextBox specify location of our folder i.e., “<drive>:\ASP”,
now under “Port” Textbox the default Port will be shown as “80”, change to any new value like “90” and click on the
“Ok” button which will create the new site under IIS. Now we can access the Web Pages in our folder using the below
URL:
Creating a new Site by changing Host or Domain Name: right click on “Sites” node in “Connections” panel and select
the option “Add Website”, which opens a new window and in that window under “Site name” Textbox specify a
name to the site for example: “NitSite2” and under “Physical path” TextBox specify location of our folder i.e.,
“<drive>:\ASP”, now under “Host Name” TextBox specify a Host Name or Domain Name, for example “nitsite.com”
and click on the “Ok” button, which will create a new Site under Sites.
Note: To use this Web Site we need to specify the Host Name under a file, “hosts” which is in the following folder:
“C:\Windows\System32\drivers\etc”. To do that first copy the file into a different location (because it can’t be edited
in the current location), add the below code in it in the last line, save and again copy the file back to
“C:\Windows\System32\drivers\etc” folder.
127.0.0.1 nitsite.com
10
Now we can access the Web Pages in our folder using the following URL:
Local Machine => http://nitsite.com/Login.html
Remote Machine => http://nitsite.com/Login.html
Note: till now we have created 1 Application and 1 Virtual Directory under “Default Web Site” and 2 Sites under the
Server with the name “MySite1” and “MySite2” so all these 4 will be present under “IIS Manager” under Connections
panel as below:
Creating Dynamic Web Pages: These are pages that are created based on a client’s request, and the content of these
pages will change based on the request i.e., the output of the page will change time to time. For example, a
transaction report in a Bank's Web Site.
Every Server-Side Technology uses some programming Language for implementing the logic, for example:
ColdFusion => CFML
Perl => Perl Script
PHP => PHP Script
Classical ASP => VB Script or JScript
JSP and Servlets => Java
ASP.NET & ASP.NET Core => .NET Languages
DJango => Python
11
Under ASP.NET we again have 2 options available for developing Dynamic Web Pages:
1. ASP.Net Web Forms
2. ASP.Net MVC
Language attribute is to specify in which language we want to implement the logic and it can either be VB
or CS, but the default is VB. Runat attribute is to specify that this logic should be processed by the Web Server.
Note: in-case we are implementing the logic by using second approach we don’t require to specify runat attribute
and the default language will be VB.
The extension of a Web Page plays a very crucial role while creating dynamic web pages i.e., if the extension
of Web Page is “.html”, Web Server will not process the logic that we have implemented by ASP.NET and to test that,
write the below code in a notepad, save it as “Test.html” and access it thru Web Server.
<!DOCTYPE html>
<html>
<head>
<title>First Dynamic Web Page</title>
12
</head>
<body>
<h1 style="text-align:center;color:red;background-color:yellow">Naresh I Technologies</h1>
Server Date: <% Response.Write(DateTime.Now.ToShortDateString()) %> <br />
Server Time: <% Response.Write(DateTime.Now.ToLongTimeString()) %>
</body>
</html>
Note: save the above page in our “ASP” folder and access it from browser in any of the following ways:
http://localhost/Site1/Test.html //Accessing thru Application created.
http://localhost/Site2/Test.html //Accessing thru Virtual Directory created.
http://localhost:90/Test.html //Accessing thru Site created with different Port No. 90
http://nitsite.com/Test.html //Accessing thru Site created with Domain Name.
In the above case even if the Web Page contains ASPX Code in it, Web Server will not process that code
because of the page extension, so it will send the content of page “as is” to the Browser for publishing. When we
send a request from any Browser to Web Server for any “.html” page, Web Server will immediately send content of
that page as Response to the Browser without checking what is present in the file, so the ASPX Code we implemented
in the file is not processed by the server but displayed directly (“as is”) on the Browser.
Now use “Save As” option in notepad and save “Test.html” as “Test.aspx” in our folder i.e., “ASP”, and when
we access the Page from Browser, we don’t see the logic, but what we see is the result when accessed:
http://localhost/Site1/Test.aspx //Accessing thru Application created.
http://localhost/Site2/Test.aspx //Accessing thru Virtual Directory created.
http://localhost:90/Test.aspx //Accessing thru Site created with different Port No. 90
http://nitsite.com/Test.aspx //Accessing thru Site created with Domain Name.
When we send request from a Web Browser to Web Server for any “.aspx” page, Web Server will open the
file, reads line by line from the file and writes the HTML Code “as is” into the Output Stream, whereas if it finds any
ASPX Code, it will process that logic and writes the results that are obtained from processing, into the Output Stream
as Text (HTML), so that after processing the whole page, content in the Output Stream will be sent to Browser as
Response.
ASP.NET Renders HTML: Unfortunately, internet still has bandwidth limitations and not every person is running on
the same OS, same Web Browser or same Device, and these issues make it necessary to stick with HTML as our mark-
up language of choice. So, in all the Server-Side technologies including ASP.NET; Web Server will process all the logic
implemented by us using any technology and converts the result into Text (HTML) which we call it as Rendering and
then that HTML will be sent to Clients as Response.
13
What is the default language used in the creation of ASPX Pages?
Ans: The default language that is used in the creation of ASPX Pages is VB (VB.NET).
To test this, write the above statement on the top of our “Test.aspx” file we have created earlier and
immediately we get an error when we run the page stating that “;” is expected and to resolve the problem end the
below 2 statements with “;”:
Note: a directive is an instruction that we give to the Web Server. By using Page directive, we are telling the Web
Server that the content in this page is implemented by using the specified language i.e., “C#” so that Web Server will
use the appropriate language compiler to process the page.
Coding Techniques in ASP.NET: ASP.NET offers 2 different coding techniques for creating Dynamic Web Pages, those
are:
1. Inline coding technique
2. Code behind technique
Inline Coding: in this case HTML, Java Script, CSS, Input Controls and Business Logic (implemented by C# or VB) will
be present in 1 file that is saved with “.aspx” extension. The “Test.aspx” page we have created above is an example
for “Inline Coding”.
Code Behind: in this case HTML, Java Script, CSS, and Input Controls will be present under 1 file that is saved with
“.aspx” extension and Business Logic (implemented by C# or VB) will be present in a separate file that is saved with
“.aspx.cs” or “.aspx.vb” based on the language in which we are implementing the Business Logic.
14
Developing Web Pages using Visual Studio: Open Visual Studio => select “Create a new project” option => now
under the Window opened, choose C# under “All_Languages DropDownList”, choose Windows under “All_Platforms
DropDownList”, choose Web under “All Project_Types DropDownList” and now in the below choose “ASP.NET Web
Application (.NET Framework)” and click Next, which launches a new Window, enter Project name as “FirstWebApp”,
Location as “<drive>:\ASP”, under Framework option choose the latest Framework Version in the Dropdown and
click on the Create button which launches a new Window and in that choose Empty Project Template and in the RHS
select Web Forms CheckBox and make sure all the other Checkbox’s are un-checked and click on Create Button which
will create and opens the new project.
Right now, the project which is opened is empty which doesn’t contain any Web Pages in it and if we open
the Solution Explorer and watch, we will find 2 empty folders here with the names App_Data & Models which can
either be deleted or leave them as is, and under the project we will also find 3 files with the names “Global.asax”,
“Packages.config” and “Web.config” which are required under every ASP.NET Web Application.
Note: Every “ASP.NET Web Application” project is a collection of Web Pages and we call them here as Web Forms.
Adding a Web Form in our project: right now our project doesn't contain any Web Form’s in it, and if we want to
add a new Web Form, open Solution Explorer right click on the project and select Add => “New Item” which opens
the “Add New Item” window, choose Web Form in it, which will ask for a name, default will be “WebForm1.aspx”,
change it as “First.aspx” and click on the Add button.
By default, the page “First.aspx” contains “Page Directive” on top of the page with few attributes like:
“Language”, “AutoEventWireup”, “Code Behind” and “Inherits”, below that we find some HTML Code containing
Head and Body sections.
To view the Code Behind file associated with this Web Form right click on the Web Form in document
window and select View Code option which will launch the file “First.aspx.cs” that contain a class in it with the name
First inheriting from the Page class and notice that class First is a partial class i.e., it is defined on more than one
source files.
1. First.aspx.cs
2. First.aspx.designer.cs
Note: by default, “First.aspx.cs” file is only visible to us and if we want to view “First.aspx.designer.cs” file, open
Solution Explorer and expand “First.aspx” node and under that we find both the files. “Designer.cs” files are used by
Visual Studio to auto-generate code i.e., the code in these files will be generated by Visual Studio, so never edit the
content of this files.
Writing code in a Web Form: because our page is created in Code Behind model, we can implement our logic either
in “.aspx” file or “.aspx.cs” file also. For example, if we want to implement logic in “First.aspx”, then write the below
code under “<div>” tag which we find under the “<body>” tag:
15
Server Date: <% Response.Write(DateTime.Now.ToShortDateString()); %>
<br />
Server Time: <% Response.Write(DateTime.Now.ToLongTimeString()); %>
Note: to run the Web Page hit F5 and it executes the page and displays the output on browser.
If we want to implement logic in “aspx.cs” file, then add another new Web Form in the project naming it as
“Second.aspx”, go to its Code View and write the below code under the method “Page_Load” which we find in the
file “Second.aspx.cs”:
Visual Studio will add each Web Application to IIS Express as a Site by allocating a random Port to each Web
Application, which will be different from Project to Project and Machine to Machine. To view the Port that is
allocated for your Web Application run any Web Form in our project and watch the URL in browsers address bar
which will be as following:
http://localhost:YourPort/First.aspx http://localhost:YourPort/Second.aspx
Note: IIS Express is provided for testing our Web Applications at the time of development and we call this as a
“Development Web Server” also and once the Application development is completed, we can host our Web
Application either on the “Local IIS” of our machine or “IIS” on remote machines or on some Public Server also.
Now in the DropDownList select “Local IIS” option which will change the Project URL as following:
http://localhost/FirstWebApp, and beside the Project URL Textbox we find a button “Create Virtual Directory” click
on it, which will create an Application under the “Default Web Site” of “Local IIS”, now click on the Save button in
“Visual Studio Standard Toolbar” and from now our Web Application will be running thru Local IIS and the URL when
we run our Web Forms will be as following:
http://localhost/FirstWebApp/First.aspx
http://localhost/FirstWebApp/Second.aspx
16
Working with Web Forms: every Web Form in an ASP.NET Web Application project will be having 3 places to work
with, those are:
1. Source View
2. Design View
3. Code View
Source View: when a new Web Form is added by default its display’s the Source View only, which is nothing but the
“.aspx” file of the Web Form and we use this for writing HTML, CSS, Java Script as well as all the logic for creation of
Input Controls.
Design View: This is a visual representation of Source View i.e., whatever we write in Source View will be displayed
as output in Design View just like how output is displayed on Browser and because of this feature Visual Studio IDE
is known as WYSIWYG (What You See Is What You Get) IDE. We can also use this for designing the UI’s, by a feature
called “Drag and Dr