您的位置:首页 > 移动开发

HOW TO Set Up Multi-Server ASP.NET Web Applications and Web Services

2011-06-28 17:31 686 查看
This step-by-step article discusses how to set up
multi-server ASP.NET Web Applications and Web services. For most uses of
ASP.NET, a single server can handle all requests in a timely manner. However,
many environments must deploy multiple servers to handle consistently high
volumes of traffic, to support processor-intensive applications, to respond to sudden
bursts in traffic, or to meet redundancy requirements.

In the simplest
form, you can deploy Web pages that consist only of static HTML pages and
images in a multi-server configuration by copying the files to multiple Web
servers and then configuring a load balancing mechanism to distribute requests
between the Web servers.

As the Web site complexity increases, the difficulty of synchronizing files and configurations between the
servers also increases. Dynamic sites require multiple servers to have access to a single
database and to share state information among themselves. This article
describes how to design multi-server ASP.NET solutions that include databases
and sessions.

Manage State

As a user navigates through an ASP.NET site, ASP.NET stores
information about the user's session state. The exact information that is stored in the
session varies by application, but may include the user’s name, preferences,
and shopping cart information.

By default, ASP.NET stores session information
in the server memory. This configuration is known as in process
. Although this configuration provides the best performance
possible, you lose the session information if you restart the ASP.NET server.
Additionally, in multi-server architectures, a single user’s request can be
sent to a different server. A user may start a session at one server, but later
requests are sent to a different in-process server. This results in a new
session being created for that user and all earlier information that was stored
in the session is lost.

ASP.NET provides two solutions for sharing
state information between multiple servers: the ASP.NET State Server service,
and Microsoft SQL Server. You can use either of these solutions to store state
information between server restarts, and to allow users to move between servers during a single
session.
For additional information, click the
following article numbers to view the articles in the Microsoft Knowledge Base:

317604

HOW TO: Configure SQL Server to
Store ASP.NET Session State

815159

HOW TO: Analyze ASP.NET Web Application Performance by Using the Performance Administration Tool

SQL Session State

I found out the hard way that storing session in a SQL server takes a
little more work then most of the books that I have read talk about.
Most articles don’t talk about what settings you should have when you
are in a web farm. This article will hopefully point you in the right
directions and keep you from the headaches that I had.

One of the first things to check is the easiest to fix. You will
need to make sure you have a constant machine key between servers. The
machine key is used for encryption and decryption of cookie data.
Unless you set the machine key to a specific code on each machine they
will use their own unique key, so when your connection switches from one
server to the other server it can’t decrypt the data and you lose your
session.

Microsoft has a couple articles on their site on how to create the
machine keys and where to place them. You can place this machine key in
your machine.config
or web.config
files.

312906
HOW TO: Create Keys by Using Visual C# .NET for Use in Forms Authentication

313091
HOW TO: Create Keys by Using Visual Basic .NET for Use in Forms Authentication

The other fix is a little more complicated to change and is less
likely to be a problem for everyone. This problem happens when you add
more websites to one server then to the other server then you try to
load balance two websites. What happens is that the application path
for the websites is different on each server. For example on one server
you have a web with an application path of //LM/W3SVC/2
and on the other server it has an application path of //LM/W3SVC/4
.
The problem is IIS uses the application path to store the data, and if
they don’t match you will lose your session. You will have to
synchronize the application path for the websites on all your web
servers in the web farm.

Microsoft has an article on this problem and how to fix it. If you think this is your problem please check out this article.

325056
PRB: Session State Is Lost in Web Farm If You Use SqlServer or StateServer Session Mode

When I was going through this we had both of these problems, and
after running though these steps we are now using SQL session state on
our website, on a three server web farm.

Synchronize Configuration and Content

A Web site’s security, performance, and many other aspects of its
behavior are defined by the configuration of the Web server. Multi-server sites
must have the configuration synchronized between all the servers to provide a
consistent experience to users whose requests are sent to different Web
servers. ASP.NET makes it simple to synchronize configuration between multiple
servers because all configuration information is stored in the virtual
server’s path as XML files. These files have a .config file name extension.

You
can copy configuration files to servers by using any standard file copy or
synchronization method, including DFS, the File Replication service, and
Microsoft Application Center 2000. The following batch file will work in
environments where each Web server has the virtual server root folder shared as
wwwroot$:

XCOPY //source-server/wwwroot$ //destination-server#/wwwroot$ /D /E /O /X


When you deploy configuration information and ASP.NET content to
multiple servers, it is critical to deploy the content from a single staging
server to all production servers at the same time. This reduces the chance of
problems occurring when a user’s requests are sent to different servers.
Microsoft recommends that all configuration and content updates occur on the
staging server. Ideally, this staging server does not receive requests from
users. It is dedicated to the task of testing and deploying new
content.

When you replicate updated .config files to a Web server,
that Web application automatically restarts.

Note
If you put assemblies in the Global Assembly Cache, you cannot replicate them by using file synchronization.

Other Tasks

Besides configuring state management and content synchronization,
you must perform the following tasks to deploy a
multi-server ASP.NET solution. These tasks are not specific to ASP.NET.

Request distribution
: Incoming HTTP requests must be distributed among all servers by
using a mechanism such as round-robin DNS, Microsoft Application Center 2000,
or a third-party load distribution device.

Log aggregation
: Before you process HTTP usage logs, it is a good idea to
combine the logs to create a single log that includes requests sent to all
systems.

Monitoring
: To detect problems that affect a single server or the whole
site, you must monitor both the external URL for the site and the URLs for each
of the Web servers.

Centralized database
: Web applications that use a database must have a single database that is
shared between multiple Web servers. In environments that require no single
point of failure, cluster the database server.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐