Chapter 26

22
Deploying ASP.NET Applications ASP.NET Applications and the Web Server How Web Servers Work The Virtual Directory Web Application URLs Internet Information Services (IIS) Managing Websites with IIS Manager Understanding Application Pools The ASP.NET Account Configuring a Website Deploying a Simple Site

description

 

Transcript of Chapter 26

Page 1: Chapter 26

Deploying ASP.NET Applications

• ASP.NET Applications and the Web Server

• How Web Servers Work

• The Virtual Directory

• Web Application URLs

• Internet Information Services (IIS)

• Managing Websites with IIS Manager

• Understanding Application Pools

• The ASP.NET Account

• Configuring a Website

• Deploying a Simple Site

Page 2: Chapter 26

What is a Web Server?

• A specialized piece of software that accepts requests over Hypertext Transport Protocol (HTTP) and serves content.

• When you’re running your web application in Visual Studio, you use the test web server that’s built in.

• When you deploy your website to a broader audience, you need a real web server, such as IIS.

• Web servers run special software to support mail exchange, FTP and HTTP access, and everything

• else clients need in order to access web content.

Page 3: Chapter 26

How Web Servers Work

• The easiest job a web server has is to provide ordinary HTML pages. When you request such a file, the web server simply reads it off the hard drive (or retrieves it from an in-memory cache) and sends the complete document to the browser.

• When you request the ASP.NET page, the web server sends the request over to the ASP.NET engine. The ASP.NET engine loads the requested page, runs the code it contains, and then creates the final HTML document, which it passes back to IIS. IIS then sends the HTML document to the client.

Page 4: Chapter 26

The Virtual Directory

When you deploy your web application to a web server, it’s exposed through something called a virtual directory.

A virtual directory is simply the public face of your website directory.

For example, your website might exist in a directory on the server named c:\MySite. To allow remote users to access this website through their browsers, you could expose it as a virtual directory say MySite.

When the user requests a page in a virtual directory (say,http://WebServer/MySite/Checkout.aspx), the web server looks for the corresponding file in the corresponding physical directory (c:\MySite\Checkout.aspx).

Page 5: Chapter 26

Web Application URLs

You can use ASP.NET applications in a variety of different environments, including local area networks (LANs) and over the Internet.

On an IP network, each computer is given a unique number called an IP address. IP addresses aren’t easy to remember web servers on the Internet usually register unique domain names such as www.microsoft.com.

Within an internal network computers can access your website using either the IP address of your machine the network computer name.

Page 7: Chapter 26

Web Farm

Instead of placing web application files on a single web server, you place a copy on several separate web servers.

When a request is received for your website, it’s directed to one of these web servers (based on which one has the lightest load).

if you decide to update your application, you need tomake sure you update each web server in the web farm with the same version to prevent discrepancies.

Page 8: Chapter 26

Internet Information Services (IIS)

IIS exists in several different versions. The version of IIS you use depends on the operating system you’re using:

• Windows Server 2003 uses IIS 6, which isn’t covered in this book.

• Windows Vista and Windows Server 2008 use IIS 7.

• Windows 7 and Windows Server 2008 R2 use IIS 7.5

Windows Vista and Windows 7, are fine for development testing, but they implement a connection limit to 10 users.

Page 9: Chapter 26

Managing Websites with IIS Manager

When IIS is installed, it automatically creates a directory named c:\inetpub\wwwroot. Any files in this directory will appear as though they’re in the root of your web server.

If you add the file TestFile.html to this directory, you canrequest it in a browser through the URL

http://localhost/TestFile.html.

You can even create subdirectories

c:\inetpub\wwwroot\ MySite\MyFile.html can be accessed as :

http://localhost/MySite/MyFile.html.

Page 10: Chapter 26

Creating a Virtual Directory

The easiest and most flexible way to create a virtual directory is to use the IIS Manager utility

1. To create a new virtual directory for an existing physical directory, expand the node for the current computer, and expand the Sites node underneath.

2. Right-click the Default Web Site item, and choose Add Application.

3. Supply the alias. For example, if your alias is MyApp and your computer is MyServer, you can request pages using URLs such as http://MyServer/MyApp/MyPage.aspx.

4. Next, you need to choose the physical path5. Next, you need to specify the application pool.

Page 11: Chapter 26

Understanding Application Pools

The web application pool sets a small group of low-level settings that apply only to ASP.NET applications,

Such as the maximum number of requests to put on hold before sending a “Service Unavailable” response to new clients (by default, it’s 1000) etc.

Application pools include two settings that are uniquely important and may require your customization:

• The version of ASP.NET that IIS runs to process the requests in your website

• The Windows account that IIS uses to run your website

Page 12: Chapter 26

The ASP.NET Account

When the web server runs your web application, it performs all its work under a specific Windows user account that has a carefully limited set of privileges. The actual account that’s used depends on the web server you’re using:

• If you’re using the integrated test server in Visual Studio, the server runs under your account.

• If you’re using IIS 7, it’s the network service account. This is a special account that Windows creates when you first install it.

• If you’re using IIS 7.5, it’s an account that’s based on the application pool. For example, an application pool named ASP.NET v4.0 will use an account named IIS AppPool\ASP.NET v4.0, which IIS generates automatically.

Page 13: Chapter 26

Configuring a WebsiteThe website configuration settings are split into

three broad groups, which are arranged alphabetically: ASP.NET, IIS, and Management.

Page 14: Chapter 26

Windows AuthenticationIIS supports several different protocols that it can

use when authenticating a user with Windows authentication

Page 15: Chapter 26

Windows AuthenticationBefore you can use any type of Windows authentication, you need to

install the appropriate support for IIS. To add support, open the Control Panel, choose Programs and Features, and then click the link “Turn Windows features on or off.” Head to the Internet Information Services ➤ World Wide Web Services ➤ Security group

Page 16: Chapter 26

Windows AuthenticationOnce you have the authentication features you need installed, you

simply need to select your website in IIS manager and double-click the Authentication icon (in the IIS group). Now you’ll see whatever authentication options you’ve installed.

Page 17: Chapter 26

Deploying a Simple Site

All you need to do is follow these two simple steps:

1. Create the virtual directory on the web server.2. Copy the entire site (including subdirectories) to the virtual directory.

This is often called zero-touch deployment, because you don’t need to manually configure web server resources However, some applications are more difficult to set up on a web server.

Page 18: Chapter 26

Deploying a Simple SiteHere are some common factors that will require additional configuration steps:Databases: If your web application uses a database, you’ll need to transfer the database to the web server. You can do this by generating a SQL script that will automatically create the database and load it with data.Windows account permissions: Usually, a web server will run web page code under a restricted account. This account might not be allowed to perform the tasks you rely on, such as writing to files or the Windows event log, or connecting to a database. In this case, an administrator needs to specifically grant the permissions you need to the account that runs the ASP.NET engine for your website.IIS security settings: If your website uses SSL encryption or Windows authentication the virtual directory settings will need to be tweaked. This also requires the help ofan administrator.

Page 19: Chapter 26

Code Compilation

A command-line tool named aspnet_compiler.exe, which is stored in the familiar directory.

c:\Windows\Microsoft.NET\Framework64\[Version]

You use this compiler on your development machine before you deploy the application.

aspnet_compiler -m metabasePath targetDirectory

Page 20: Chapter 26

Deploying with Visual Studio

Visual Studio includes features that integrate with IIS and allow you to create virtual directories without leaving the comfort of your design-time environment.Visual Studio has several deployment-related features:

• You can use the Copy Web Site feature to transfer an existing website to a virtual directory.

• You can use the Publish Web Site feature to compile your website and transfer it to another location.

Page 21: Chapter 26

Copying a Website

Select Website ➤ Copy Web Site from the menu

Page 22: Chapter 26

Publishing a WebsiteSelect Build ➤ Publish Web Site from the menu