ASP.NET Presentation

Preview:

DESCRIPTION

This is asp.net ppt presentaion !!

Citation preview

JATIYA KABI KAZI NAZRUL ISLAM UNIVERSITY

Presentation On

Submitted to Submitted By

Mr. Tushar Kanti Saha Rasel khan

Lecturer Deprt of CSE, Roll: 11102027

JKKNIU Session: 2010-2011

Dept Of CSE

ASP.NET OVERVIEWIntroduction & History

Why use ASP.NET, Some characteristics & with

Component

Steps for developing a web based application and how

to work request with response.

Working with ASP.NET MVC Framework.

How to work HTTP Fundamentals.

ASP.NET web application Routing.

ASP.NET IIS & how to create virtual directory.

INTRODUCTION

ASP.NET mean is Active Server Pages . It 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 • Web services

ASP.NET

• The latest version of ASP is known as ASP.NET• Visual Studio .NET is a developer application used to

create ASP.NET Web applications• There are two main types of Web resources created

with ASP.NET applications– Web Forms are ASP.NET pages within an ASP.NET

application– Web Services are ASP.NET Web pages that contain

publicly exposed code so that other applications can interact with them

– Web Services are identified with the file extension .asmx

HISTORYASP.NET 1.0 was released on January 5, 2002 as part of version 1.0 of the .NET Framework.

Scott Guthrie became the product unit manager for ASP.NET, and development continued apace, with version 1.1 being released on April 24, 2003 as a part of Windows Server 2003. This release focused on improving ASP.NET's support for mobile devices.

WHY USE ASP.NET Improved Performance and Scalability. Compiled Execution, Rich Output Caching, Web Farm Session State.

Enhanced Reliability. Memory Leak, Dead Lock, and Crash Protection

Easy Deployment. No Touch" Application Deployment, Dynamic Update of Running Application,

Easy Migration Path

New Application Models. XML Web Services

Developer Productivity. Easy Programming Model, Flexible Language Options, Rich Class Framework.

CHARACTERISTICS Code-behind model It is recommended by Microsoft for dealing with dynamic program code to use the

code-behind model, which places this code in a separate file or in a specially designated script tag

User controls ASP.NET supports creating reusable components through the creation of User Controls

Rendering technique  ASP.NET uses a visited composites rendering technique. During compilation, the

template (.aspx) file is compiled into initialization code which builds a control tree (the composite) representing the original template

CHARACTERISTICS• Compiled code Code written in ASP.NET is compile and not interpreted.

• Enriched tool support ASP.NET applications using visual studio

• Power and flexibility ASP.NET applications are based on the CLR

• Simplicity ASP.NET enables you to build user interfaces that separate application logic from

presentation content

• Manageability ASP.NET provides a number of options in providing the above facilities

Server control Respond to users events by running event procedures on

the server. HTML control

Represent the standard visual elements provided in HTMLData control

Provide a way to connect to perform commands on and retrieve data from SQL , OL ,databases and XML data files System components

Provide access to various system level events that occur on the server

COMPONENTS

STEPS FOR DEVELOPING A WEB BASED APPLICATION Step 1 – Create Local Folders for Your Web

ProjectStep 2 – Create a Blank SolutionStep 3 – Add a Web Site to Your SolutionStep 4 – Add a Class Library (Optional)Step 5 – Check Your Solution StructureStep 6 – Check Your Local Folder StructureStep 7 – Add Your Solution to Source Control

REQUEST AND RESPONSE

Web Server

Server response with pages

1. Client Initiates2. Communications With page request

1. Process request2. Execute server slide

code3. Store session data4. Send result response

Web Browser

Display page

Get default.aspx

PROCESS OF WEB BROWSER

ASP.NET MVC

Model View Controller (MVC) applications by using the ASP.NET framework

WHAT IS ASP.NET MVC?

Saying simply, ASP.NET MVC is a new framework from Microsoft that sits over standard ASP.NET engine.

ASP.NET

ASP.NET MVC

ASP.NET MVC Features

1. Clear separation of logic: Model, View, Controller

2. Test-Driven Development (TDD)

3. Full control over HTML and JavaScript

4. Friendly URLs

MODEL + VIEW + CONTROLLER = MVCASP.NET MVC provides an alternative to the ASP.NET “Web Forms” pattern for creating MVC-based Web applications.

Model

ControllerView

Model objects implement the logic for the application's data domain. Often, model objects retrieve and store the app state in a database.

Controllers handle user interaction, work with the model, and select a view to render that displays UI

Views display the application's user interface (UI). Typically, this UI is created from the model data.

Test-Driven Development (TDD)

Since the UI is completely separated from the business logic, it’s now easy to write Unit Tests for the ASP.NET MVC application.

Controller

Unit Tests that cover User Actions and Data Model

User Interface Data Objects

Full control over HTML & JS

In ASP.NET MVC, designed HTML & JS pages are not more messed up with “postbacks” and “ViewStates”, which is specific for “Web-forms” pattern.

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPaA8FDzhjYjBhZjA0ODYyMTM2NBgGBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAQUhY3RsMDAkaGVhZGVyJHVjTWFpbk1lbnUkc2VhcmNoQnRuBTdjdGwwMCRNYWluQ29udGVudCRycHRWaWRlbyRjdGwwMyRwcmVzZW50YXRpb25DYXJkJG11bHRp" />

<script type="text/javascript">//<![CDATA[var theForm = document.forms['aspnetForm'];function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}//]]></script>

Friendly URLs

MVC binds web paths to the logical URLs rather than to the physical files.

C:\Inetpub\wwwroot\WebSite\Products.aspx

http://www.website.com/Products.aspx?name=Meat

http://www.website.com/Products/Meat

Physical location:

ASP.NET style:

MVC style:

HOW DOES ASP.NET MVC LOOKS LIKE? ASP.NET MVC installs a new type of web project into VS2008.

How does ASP.NET MVC looks like?

A newly created project has an ASP.NET MVC specific directory structure. App_Data folder is the physical store for data.

Content folder keeps files such as scripts, CSS, images, and so on.

Controllers folder is the location for controllers. The MVC framework requires the names of all controllers to end with "Controller"—for example, HomeController, LoginController, or ProductController.

Models stores classes that handle application business logic.

Scripts folder is for script files that support the application. By default, this folder contains AJAX script files and the JQuery library.

Views is the recommended location for views. Views use .aspx, .ascx, and .master files, in addition to any other files that are related to rendering views.

ASP.NET MVC supports pure MVC pattern, the same development pattern Rails are based on. The advantages of ASP.NET MVC applications:

1. It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.

2. It does not use view state or server-based forms. 3. It uses a Front Controller pattern that processes Web application

requests through a single controller. This enables you to design an application that supports a rich routing infrastructure with friendly URLs.

4. It provides better support for test-driven development (TDD).5. It works well for Web applications that are supported by large teams of

developers and Web designers who need a high degree of control over the application behavior.

http://www.asp.net/mvc - official site

http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx - development basics on ASP.NET MVC

http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx - URL routing used in ASP.NET MVC

http://weblogs.asp.net/scottgu/archive/2007/12/06/asp-net-mvc-framework-part-3-passing-viewdata-from-controllers-to-views.aspx - interaction between Controllers and Views

http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-mvc-framework-part-4-handling-form-edit-and-post-scenarios.aspx - managing form input data

Web Links to Additional Resources

ASP.NET Web API and HTTP Fundamentals

CRAMMING YOUR BRAINS WITH HTTP & ASP.NET WEB API

• HTTP Fundamentals via Web API

• HTTP Messages

• URIs

• Routing

• Verbs

• Controllers and Actions

• Status Codes

• HttpRequestMessage\HttpResponseMessage

• Error Handling

• Content Negotiation

• Media Type Formatters

• OData

• Validations

• Dependency Resolver

• Hosting

• HTTP.SYS

• IIS 101

• HTTP compression

• Persisted Connections

• Web API Self Hosting

• More HTTP and Web API

• Caching

• Concurrency

• Security

• Streaming

• WebSockets & SignalR

26

WHY IS HTTP IMPORTANT?

HTTP is a first class application layer protocol

Unlike other protocols it was created to support a

single information system

That system happened to be the largest and main

information system of the human race:

27

WWW

NO REALLY, WHY?

Today's systems face new challenges: Broader reach of clients

What About ASP.NET Web API?

• The .NET platform never had a first class framework for HTTP-based services

• WCF was created as a SOAP-based framework and never really matured to support HTTP

29

THE HISTORY OF ASP.NET WEB API

30

ASP.NET isOpen Source

ASP.NET Web API (Beta)

WCF Web API on CodePlex

6 Preview Versions

WCF WebHttp Binding (.NET 4)

Sep. 2013April2010

October2010

Feb.2012

March2012

August2012

ASP.NET Web API 4 Release

ASP.NET Web API 2 Release Candidate

HTTP Messages 101

HTTP is a first class application protocol: Widely supported across platforms and

devices Scalable Simple

Uses the request-response messaging pattern

Define resource-based semantics and not RPC (Remote Procedure Call) or methods

31

HTTP REQUEST MESSAGES

32

GET http://localhost:2300/api/agents/Bond HTTP/1.1Accept: text/html, application/xhtml+xml, */*Accept-Language: en-US,en;q=0.7,he;q=0.3User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)Accept-Encoding: gzip, deflateHost: localhost:2300DNT: 1Connection: Keep-Alive

HTTP RESPONSE MESSAGES

33

HTTP/1.1 200 OKCache-Control: public, max-age=300Content-Type: application/json; charset=utf-8ETag: "1"Server: Microsoft-IIS/8.0X-AspNet-Version: 4.0.30319Date: Mon, 19 Nov 2012 17:49:40 GMTContent-Length: 142

{ "Id": "Bond", "FullName": "James Bond", "Alias": "007", "Version": 1, "Image": "http://localhost:2300/api/agents/Bond.jpg"}

URIS

• HTTP is not an RPC protocol

• HTTP uses URIs to identify resources over the network

• An HTTP URI has the following basic structure:

34

Schema Host Port Absolute Path

Query

http://theagency.com:8080/agents?id=1

CLEAN URLS AND ASP.NET

Using clean URLs can be a problem with IIS

IIS needs extensions to map requests to handlers

Without extensions, IIS is lost

ASP.NET Routing to the rescue with UrlRoutingModule

It’s all about patterns… and mapping them to handlers

The starting point of MVC, Dynamic Data, and Web API

System.Web.Routing.RouteTable.Routes.MapHttpRoute

35

RouteTable.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional });

ASP.NET WEB API - ROUTING

36

Routing with attributes

Why attributes over convention?Child (sub) resourcesMultiple type of parameters or return

valuesVersioning of actions and controllers

Start by enabling attribute routingconfig.MapHttpAttributeRoutes();

[RoutePrefix("api/agents/{agentId}")]public class ObservationsController : ApiController { // GET api/agents/bond/observations [HttpGet("observations/{date}")] public Observation Get(string agentId, DateTime date) { ... }}

Verbs•HTTP defines a set of Methods or

Verbs that add an action-like semantics to requests

•Verbs are defined as the first segment of

• the request-line:

•There are eight verbs defined in HTTP 1.1:

38

GET http://localhost:4392/travelers/1 HTTP/1.1

GETPOSTPUTDELETE

HEADOPTIONSTRACECONNECT

3, 2, 1, Actions!

• Actions are matched by HTTP verb names and the existence of parameters

public class ProductsController : ApiController{    public IEnumerable<Product> GetProducts() {...}    public Product GetProductById(int id) {...}    public HttpResponseMessage PostProduct(Product product) {...}}

DELETE api/products/42

GET api/products

GET api/products/42

POST api/products

Status Codes

Status codes describe the result of the server’s effort to satisfy the request

Passed in the response's status-line as three digit alongside a textual description called reason phrase

HTTP has five different categories of status-codes:

1xx – Informational 2xx – Success 3xx – Redirection 4xx – Client Error 5xx – Server Error

(100 / 101)

(200 – 206)

(300 – 307)

(400 – 417)

(500 – 505)

41

Status Code examples

• 404?• 401?• 304?• 503?• 500?• 200?• 301?• 302?

Http Response Message

Returning an HttpResponseMessage allows more control over the response, including: Status code HTTP headers Entity body

42

public HttpResponseMessage CreateAgent(Agent agent){ agent = _repository.Add(agent); var response = Request.CreateResponse<Agent>(HttpStatusCode.Created, agent); response.Headers.Location = GetAgentLocation(agent.Id); return response;}

Error Handling• In HTTP services errors are handled by

▫Returning an appropriate status code▫Returning an entity body explaining the error

(when applicable)•Web API allows you to handle exceptions by

▫Return an HttpResponseMessage with appropriate status code (404, 500 …)

▫Throw an HttpResponseException▫Create a general exception handler by using

Filters43

Content Negotiation

HTTP defines a process to best match the server’s response to the client’s expectation

Negotiation can be done using: Headers:

Accept, Accept- Language, Accept- Charset, Accept-Encoding

URI:File extensions (.jpeg, .html), host-name: (com, org), path and query

44

ASP.NET, IIS & how to create virtual directory

SESSION OBJECTIVES• ASP.NET Benefit• How Does ASP.NET Work?• IIS• Creating a Virtual Directory• Web Sharing the Project Folder• Deleting a Web Project

HOW DOES ASP.NET WORK?

• Requests an HTML file, the server returns the file

• Requests an ASP.NET file, IIS passes the request to the ASP.NET engine on the server

• The ASP.NET engine reads the file, line by line, and executes the scripts in the file

• ASP.NET file is returned to the browser as plain HTML

Benefits of ASP.NET

Separation of Code from HTML Graphical Development Environment Update files while the server is

running! Support for compiled languages State management

IIS – Internet Information Services•Internet Information Service

•IIS (Internet Information Services) is Microsoft's Internet server

•IIS comes as a free component with Windows servers

•IIS is also a part of Windows 2000 and XP Professional

Creating a Virtual Directory

Start, Settings, Control Panel, Administrative Tools, Internet Services Manager

Expand node for computer and default Web site

Right-click Default Web site icon, select New, Virtual Directory

In Virtual Directory Creation Wizard enter your project folder name as the alias and enter the folder and path

Web Sharing the Project FolderSelect the Project folder in My ComputerRight-click, select Properties, Web Sharing,

activate Share This FolderIn Edit Alias dialog click OK

Deleting a Web Project

Project in IIS Virtual Directory Delete the directory

Project in Web Shared Folder “Unshare” it from Properties dialog Either Reboot Computer or Stop and Restart IIS Delete Folder

Thank You All

Recommended