Вы находитесь на странице: 1из 7

Introduction to ASP.

NET
(Lab Manual 11)

Contents

Total (170 minutes) o Introduction to ASP.NET o ASP.NET application architecture o Practice Exercise (30 minutes) (40 minutes) (100 minutes)

Database Systems

Page 1

Introduction to ASP.NET
(Lab Manual 11) The purpose of this lab is to give you introduction to ASP.Net. We will also see the architecture of asp.net application by looking into the sample asp.net project. ASP.NET What is CSS? ASP stands for Active Server Pages. ASP "pages" are actually scripts that are run, or executed, on the web server. The script is interpreted from top to bottom to create HTML pages that are sent to the browser for display. When should I use ASP?

ASP is appropriate whenever you want your pages to be created dynamically when the browser requests the page. For example, displaying data that is relevant on a certain date, or storing user data collected from a form. Often, the ASP scripts will query a database and format the data retrieved for display in a HTML page. Difference between ASP and html
HTML is a client-side language that is developed and outputted like a "website" by a browser - not a server. It consists of tags to create elements and objects. ASP is a server-side language that outputs other languages (or just pure text) dynamically - depending on how functions and queries turn out, how variables are compared to one another, and etc.
ASP page request process

Read the request coming from the browser. 2. Find out that webpage.

Database Systems

Page 2

Introduction to ASP.NET
(Lab Manual 11)
3. Execute the ASP code from web page. 4. Send that page through internet.
Built in ASP Objects

Active server pages supplies the following six built-in objects for request and response processing as well as for creating and managing a web application: Application - stores application wide state information. Session New Team maintains information on a per-user basis in this object. A session is the personal storage of each user visiting your site. Request - consists of all information that is passed to the server from the browser. Allows access to data that has been sent with forms. Response - writes HTML and various other information, including cookies and header, back to the client. Server- provides server functionally for use in active server pages. Object context- allows you to commit or abort transactions, which are managed by transaction server. These objects are available immediately in all your ASP pages, with no need to create them before they can be used. How can you access these objects? You can do so by adding code to your ASP pages written in a scripting language.

Database Systems

Page 3

Introduction to ASP.NET
(Lab Manual 11)

ASP.Net Page Life Cycle

Database Systems

Page 4

Introduction to ASP.NET
(Lab Manual 11)

Practical Database Tips The following list provides some practical tips on working with databases: Because the database is often at the heart of a web site, you need to carefully consider its design. Its especially important to think of a good design up front, before you start building your site on top of it. When you have a number of pages that access your database, it will become harder to make changes such as removing tables or renaming columns to the data model. Always consider the primary key for your table. I prefer to give each table a column called Id. The underlying data type is then an int and an identity, which gives each record a unique ID automatically. Instead of an int, you can also consider the unique identifier data type, which ensures uniqueness even across database or application boundaries. Give your database objects such as tables and columns logical names. Avoid characters such as spaces, underscores, and dashes. A name like GenreId is much easier to read than colGen_ID_3. Dont use SELECT * to get all columns from a database. By using SELECT * you may be selecting more columns that you actually need. By explicitly defining the columns you want to retrieve, you make your intentions to others clearer and increase the performance of your queries at the same time. Always create relationships between tables when appropriate. Although querying for the reviews and genres you saw in this chapter without a relationship between the two tables works just fine, relationships help you enforce the quality of your data. With proper relationships, you minimize the chance of ending up with orphaned or incorrect data.

Database Systems

Page 5

Introduction to ASP.NET
(Lab Manual 11) Three tier Architecture In sample website, 1. We have implemented Business Logic in code behind pages (aspx.cs). 2. Business Objects encapsulate data to be communicated between Business and Data layer. 3. Data Access Layer retrieves data from database through connection established. Exercise Create a login page in ASP.NET using three tier architecture. Material Required Companydb For reference, ASP.Net sample web site Instructions
1. Create a new database companydb and run database_creation_script.sql file to create tables. Or Run this sql command to create database directly. sp_attach_single_file_db @dbname='companydb',@physname='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Backup\companydb.mdf' Note: Make sure you have placed .mdf file at a location accessible for SQ L Server like above, otherwise you will get access denied error. 2. Open VS 2010 and create a new website and use ASP.Net Empty Web site template. Create Login.aspx web form and Business and Data Access Layer classes as mentioned in project folder. 3. Storing Your Connection Strings in web.config Write this entry in web config after <configuration> and before</configuration>. <connectionStrings> <add name="StartDial" connectionString="Data Source=farrah;Initial Catalog=companydb;Integrated Security=True; " providerName="System.Data.SqlClient"/> </connectionStrings>

Database Systems

Page 6

Introduction to ASP.NET
(Lab Manual 11)
You can get your connection string from Server explorer >Add Connection.Create a connection to your database and then from connection properties, get connection string.

Good Reference:
Beginning-asp-net-4-in-c-and-vb-wrox-programmer-to-programmer.9780470502211.52112.pdf http://www.w3schools.com

Database Systems

Page 7

Вам также может понравиться