Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 4: The Server Tier (18 Hrs

Similar presentations


Presentation on theme: "Unit 4: The Server Tier (18 Hrs"— Presentation transcript:

1 Unit 4: The Server Tier (18 Hrs
Unit 4: The Server Tier (18 Hrs.) Web Server Concept, Creating dynamic content, Using control flow to control dynamic content generation, Sessions and State, Error Handling, Architecting Web Application, Using tag libraries, Writing tag libraries

2 Web server In 1989 Tim Berners-Lee proposed a new project to his employer CERN, with the goal of easing the exchange of information between scientists by using a hypertext system. The project resulted in Berners-Lee writing two programs in 1990: A browser called WorldWideWeb. The world's first web server, later known as CERN httpd, which ran on NeXTSTEP. In 1994 Tim Berners-Lee decided to constitute the World Wide Web Consortium (W3C) to regulate the further development of the many technologies involved (HTTP, HTML, etc.) through a standardization process. Web servers are computers that deliver (serves up) Web pages. a program that uses HTTP to serve files that create web pages to users in response to their requests. Every Web server has an IP address and possibly a domain name. Every web server has a unique address so that other computers connected to the Internet know where to find it. Web hosts rent out space on their web servers to people or businesses to set up their own websites. Any computer can be turned into a Web server by installing server software and connecting the machine to the Internet.

3 Common features Virtual hosting to serve many web sites using one IP address Large file support to be able to serve files whose size is greater than 2 GB on 32 bit OS Bandwidth throttling to limit the speed of responses in order to not saturate the network and to be able to serve more clients Server-side scripting to generate dynamic web pages, still keeping web server and website implementations separate from each other

4 Kernel-mode and user-mode web servers
A web server can be either implemented into the OS kernel, or in user space (like other regular applications). Load limits A web server (program) has defined load limits, because it can handle only a limited number of concurrent client connections (usually between 2 and 80,000, by default between 500 and 1,000) per IP address (and TCP port) and it can serve only a certain maximum number of requests per second depending on: its own settings, the HTTP request type, whether the content is static or dynamic, whether the content is cached, and the hardware and software limitations of the OS of the computer on which the web server runs. When a web server is near to or over its limit, it becomes unresponsive.

5 Symptoms of overload The symptoms of an overloaded web server are:
Requests are served with (possibly long) delays (from 1 second to a few hundred seconds). The web server returns an HTTP error code, such as 500, 502, 503, 504, 408, or even 404, which is inappropriate for an overload condition. The web server refuses or resets (interrupts) TCP connections before it returns any content. In very rare cases, the web server returns only a part of the requested content. This behavior can be considered a bug, even if it usually arises as a symptom of overload.

6 Anti-overload techniques
To partially overcome above average load limits and to prevent overload, most popular web sites use common techniques like: Managing network traffic, by using: Firewalls to block unwanted traffic coming from bad IP sources or having bad patterns HTTP traffic managers to drop, redirect or rewrite requests having bad HTTP patterns Bandwidth management and traffic shaping, in order to smooth down peaks in network usage Deploying web cache techniques Using different domain names to serve different (static and dynamic) content by separate web servers, i.e.: Using different domain names and/or computers to separate big files from small and medium sized files; the idea is to be able to fully cache small and medium sized files and to efficiently serve big or huge (over MB) files by using different settings Using many web servers (programs) per computer, each one bound to its own network card and IP address Using many web servers (computers) that are grouped together behind a load balancer so that they act or are seen as one big web server Adding more hardware resources (i.e. RAM, disks) to each computer Tuning OS parameters for hardware capabilities and usage Using more efficient computer programs for web servers, etc. Using other workarounds, especially if dynamic content is involved

7 Web Servers Types Two leading Web servers are Apache, the most widely installed Web server, and Microsoft's Internet Information Server (IIS).

8 Apache HTTP Server (FREE & Open Source)
most popular web server on the web since 1996. developed and maintained by the Apache Software Foundation. Apache is available for a range of operating systems, including Unix, Linux, Windows, Mac OS X, Solaris. Microsoft Internet Information Services (IIS) ( Proprietary ) second most popular web server on the web. IIS comes as an optional component of most Windows operating systems. The major purpose of it was to provide their OS to control internet-services.

9 Other Web Servers Lighttpd: Sun Java System Web Server:
pronounced lighty is also a free web server that is distributed with the FreeBSD operating system. This open source web server is fast, secure and consumes much less CPU power. Lighttpd can also run on Windows, Mac OS X, Linux and Solaris operating systems. Sun Java System Web Server: web server from Sun Microsystems is suited for medium and large websites. the server is free it is not open source. runs on Windows, Linux and Unix platforms. supports various languages, scripts and technologies required for Web 2.0 such as JSP, Java Servlets, PHP, Perl, Python, Ruby on Rails, ASP and Coldfusion etc.

10 3. Jigsaw Server: comes from the World Wide Web Consortium (W3C's Server). It is open source and free and can run on various platforms like Linux, Unix, Windows, Mac OS X Free BSD etc. Jigsaw has been written in Java and can run CGI scripts and PHP programs.

11 Static Content Static content is published to regular files on your server and handled using the simplest methods available to the web server.   The advantages of static content are: it is the fastest and most efficient way to deliver content it does not require any code to execute or any databases to be accessed, which makes it the most secure way to deliver content it uses simple, clean URLs to address the content it takes best advantage of web caching systems, which further boosts performance it is compatible with every type of webserver technology

12 Disadvantages Of Static Content
it must be republished when it changes, or your viewers will not see the updates it cannot display differently to different viewers, depending on their login status or other factors

13 Dynamic Content Dynamic content is generated for you at the time you request the page.   The document you view exists only for you at that moment;  if viewed by someone else at the same time, or by you at a slightly different time, you could get something different. Dynamic content is good for: pages whose content changes too quickly to easily republish it pages that display viewer-specific content (eg. user profiles) pages that display content conditionally (ie. member-only pages)

14 Dynamic content has the following disadvantages:
it is resource-intensive compared to static pages.  That means the number of dynamic pages your server can display per second will generally be much less than the number of static pages.  This can be especially important if you are swamped with traffic, or generating thousands of dynamic page views for robots or other automated agents that you don't really care about. dynamic pages execute code on your server, and can read from and write to your database.  If your website has any security problems, dynamic pages is where those problems will be exposed. in many typical default webserving configurations, the index page of a website is presumed to be a static page (eg. "index.html").  That means there are some places where it is impractical or more difficult to use dynamic pages than others.

15 Server-Side Scripting
To generate dynamic pages we use a server-side scripting language. There are different types of server-side scripting languages such as PHP, ASP, ASP.NET, ColdFusion, Java Server Pages, Perl and others. Each scripting languages is being interpreted by an application. The application which interprets the server-side script is installed on the sever just like any other application. Server-side scripting languages are operating systems dependent.

16 .NET an Overview: ASP.net and VB.net
ASP.NET stands for Active Server Pages .NET & it is a technology used to render dynamic web content. VB.NET stands for Visual Basic.NET which is simply a Programming Language. An ASP.NET web site is typically made up of code written in either VB.NET or C# (C Sharp).

17 Microsoft .net Package of software that consists of clients, servers, and development tools. includes many other subcomponents that allow software that has been written in different languages to work together by establishing rules for language independence. Using it as a base, software development toolmakers can create development tools for different languages such as COBOL or C++. Microsoft itself used the .NET Framework to create VS, which is a development tool used to create software using the VB or C# programming languages. also provides many common functions that previously needed to be built by the developer. This includes access to the file system, access to the registry, and easier development when using the Windows Application Programming Interfaces (API) to access operating system–level functionality. This allows developer to concentrate more on business problems, instead of worrying how to access low-level windows functionality.

18 The Common Language Runtime
CLR is one of the components within the .NET Framework. provides runtime services, including loading and execution of code. essentially takes the language-specific code that was written and translates it Microsoft Intermediate Language (MSIL) code. This is what allows code written with VB to work with code written in C# (the most important aspect of the .NET Framework). A single program, written in multiple languages, works mainly because the framework contains a set of common data types that must be used by all languages building applications with the .NET Framework. This set of data types is the Common Type System (CTS), which defines how types are declared, used, and managed. To accommodate the CLR, some of the data types within languages such as VB needed to be changed so they could work better with data types from other languages such as C++.

19 Assemblies the main component of a .NET Framework application and is a collection of all of the functionality for the particular application. is created as either a .dll file for web sites or an .exe file for Windows applications, and it contains all of the MSIL code to be used by the framework. Without the assembly there is no application. .NET Framework Software Development Kit (SDK) is used to create the assemblies and perform other tasks, which are automatically done by VS.

20 How Web Servers Execute ASP Files

21 Server-Side Compilation and Delivery Process

22 The process of compiling and delivering ASP
The process of compiling and delivering ASP.NET pages goes through the following stages: IIS matches the URL in the request against a file on the physical file system (hard disk) by translating the virtual path (for example, /site/ index.aspx) into a path relative to the site’s Web root (for example, d:\domains\thisSite\wwwroot\site\index.aspx). Once the file is found, the file extension (.aspx) is matched against a list of known file types for either sending on to the visitor or for processing. If this is first visit to the page since the file was last changed, the ASP code is compiled into an assembly using the Common Language Runtime compiler, into MSIL, and then into machine- specific binary code for execution. The binary code is a .NET class .dll and is stored in a temporary location. Next time the page is requested the server will check to see if the code has changed. If the code is the same, then the compilation step is skipped and the previously compiled class code is executed; otherwise, the class is deleted and recompiled from the new source. The compiled code is executed and the request values are interpreted, such as form input fields or URL parameters. If the developer has used Web forms, then the server can detect what software the visitor is using and render pages that are tailored to the visitors’ requirements, for example, returning Netscape specific code, or Wireless Markup Language (WML) code for mobiles. Any results are delivered back to the visitor’s Web browser. Form elements are converted into client side markup and script, HTML and JavaScript for Web browsers, and WML and WMLScript for mobiles, for example.

23 Classic ASP and ASP.net Microsoft's previous server side scripting technology ASP (Active Server Pages) is now often called classic ASP (ASP 3.0 was the last version of classic ASP). ASP.NET is the next generation ASP, but it's not an upgraded version of ASP. ASP.NET is a server side scripting technology that enables scripts (embedded in web pages) to be executed by an Internet server. ASP.NET is a Microsoft Technology. ASP.NET is a program that runs inside IIS (Internet Information Services) is Microsoft's Internet server. IIS is also a part of Windows 2000 and XP Professional and comes as a free component with Windows servers

24 The .NET Framework consists of 3 main parts:
Programming languages: C# (Pronounced C sharp) Visual Basic (VB .NET) J# (Pronounced J sharp) Server technologies and client technologies: ASP .NET (Active Server Pages) Windows Forms (Windows desktop solutions) Compact Framework (PDA / Mobile solutions) Development environments: Visual Studio .NET (VS .NET) Visual Web Developer

25 Features of ASP.net: ASP.NET Controls: Event Aware Controls:
contains a large set of HTML controls. almost all HTML elements on a page can be defined as ASP.NET control objects that can be controlled by scripts. also contains a new set of object-oriented input controls, like programmable list-boxes and validation controls. A new data grid control supports sorting, data paging, and everything you can expect from a dataset control. Event Aware Controls: All ASP.NET objects on a Web page can expose events that can be processed by ASP.NET code. Load, Click and Change events handled by code makes coding much simpler and much better organized.

26 5. User Accounts and Roles:
3. ASP.NET Components: ASP.NET components are heavily based on XML. 4. User Authentication: ASP.NET supports form-based user authentication, cookie management, and automatic redirecting of unauthorized logins. 5. User Accounts and Roles: ASP.NET allows user accounts and roles, to give each user (with a given role) access to different server code and executables. 6. High Scalability: Server-to-server communication has been greatly enhanced, making it possible to scale an application over several servers. One example of this is the ability to run XML parsers, XSL transformations and even resource hungry session objects on other servers.

27 7. Compiled Code: 8. Easy Configuration: 9. Easy Deployment:
The first request for an ASP.NET page on the server will compile the ASP.NET code and keep a cached copy in memory which result in highperformance. 8. Easy Configuration: Configuration of ASP.NET is done with plain text files. Configuration files can be uploaded or changed while the application is running. No need to restart the server. No more metabase or registry puzzle. 9. Easy Deployment: No more server-restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code. 10. Compatibility: ASP.NET is not fully compatible with earlier versions of ASP, so most of the old ASP code will need some changes to run under ASP.NET. To overcome this problem, ASP.NET uses a new file extension ".aspx". This will make ASP.NET applications able to run side by side with standard ASP applications on the same server.

28 Creating ASP.NET Application
<html> <body bgcolor="yellow"> <center> <h2>Hello World!</h2> </center> </body> </html> The simplest way to convert an HTML page into an ASP.NET page is to copy the HTML file to a new file with an .aspx extension If a browser requests an HTML page from the server, the server sends the page to the browser without any modifications. If a browser requests an ASP.NET page, the server processes any executable code in the page, before the result is sent back to the browser.

29 Dynamic Page in Classic ASP
<html> <body bgcolor="yellow"> <center> <h2>Hello World!</h2> <p><%Response.Write(now())%></p> </center> </body> </html> The code inside the <% --%> tags is executed on the server. Response.Write is ASP code for writing something to the HTML output stream. Now() is a function returning the servers current date and time. The code above illustrates a limitation in Classic ASP: The code block has to be placed where the output has to appear. With Classic ASP it is impossible to separate executable code from the HTML itself. This makes the page difficult to read, and difficult to maintain.

30 ASP.NET - Server Controls
ASP.NET has solved the "spaghetti-code" problem described above with server controls. Server controls are tags that are understood by the server. There are three kinds of server controls: HTML Server Controls - Traditional HTML tags Web Server Controls - New ASP.NET tags Validation Server Controls - For input validation

31 1. HTML Server Controls HTML server controls are HTML tags understood by the server as HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id reference can be used to manipulate the server control at run time. All HTML server controls must be within a <form> tag with the runat="server" attribute.

32 <script runat="server">
Sub Page_Load link1.href=" End Sub </script> <html> <body> <form runat="server"> <a id="link1" runat="server">Visit XYZ!</a> </form> </body> Here HtmlAnchor server control is declared in an .aspx file. Then we manipulate the href attribute of the HtmlAnchor control in an event handler (an event handler is a subroutine that executes code for a given event). The Page_Load event is one of many events that ASP.NET understands.

33 2. Web Server Controls special ASP.NET tags understood by the server.
like HTML server controls, Web server controls are also created on the server and they require a runat="server" attribute to work. Web server controls do not necessarily map to any existing HTML elements and they may represent more complex elements. The syntax for creating a Web server control is: <asp:control_name id="some_id" runat="server" />

34 <script runat="server">
Sub submit(Source As Object, e As EventArgs) button1.Text="You clicked me!" End Sub </script> <html> <body> <form runat="server"> <asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit"/> </form> </body> </html> Here a Button server control is declared in an .aspx file. Then we create an event handler for the Click event which changes the text on the button.

35 3. Validation Server Controls
Used to validate user-input. If the user-input does not pass validation, it will display an error message to the user. Each validation control performs a specific type of validation (like validating against a specific value or a range of values). By default, page validation is performed when a Button, ImageButton, or LinkButton control is clicked. We can prevent validation when a button control is clicked by setting the Causes Validation property to false. The syntax for creating a Validation server control is: <asp:control_name id="some_id" runat="server" />

36 <html> <body> <form runat="server"> <p>Enter a number from 1 to 100: <asp:TextBox id="tbox1" runat="server" /> <br /><br /> <asp:Button Text="Submit" runat="server" /> </p> <p> <asp:RangeValidator ControlToValidate="tbox1" MinimumValue="1" MaximumValue="100" Type="Integer" Text="The value must be from 1 to 100!" runat="server" /> </p> </form> </body> </html> Here we declare one TextBox control, one Button control, and one RangeValidator control in an .aspx file. If validation fails, the text "The value must be from 1 to 100!" will be displayed in the RangeValidator control:

37 ASP.NET Web Forms All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts: <form runat="server"> ...HTML + server controls </form> The form is always submitted to the page itself. If specifed an action attribute, it is ignored. If omited the method attribute, it will be set to method="post" by default. An .aspx page can only contain ONE <form runat="server"> control.

38 If we select view source in an
If we select view source in an .aspx page containing a form with no name, method, action, or id attribute specified, ASP.NET adds these attributes to the form. It looks something like this: <form name="_ctl0" method="post" action="page.aspx" id="_ctl0"> ...some code </form>


Download ppt "Unit 4: The Server Tier (18 Hrs"

Similar presentations


Ads by Google