DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

  1. DZone
  2. Refcards
  3. Core ASP.NET
refcard cover
Refcard #046

Core ASP.NET

Elegant Web Development

Explains the most commonly used Core functions and controls in ASP.NET, a framework for the development of dynamic websites and web services.

Download Refcard
Free PDF for Easy Reference
refcard cover

Written By

author avatar Holger Schwichtenberg
,
Table of Contents
► About ASP.NET ► Installation ► ASP.NET Web Applications ► The ASP.NET Web Form Model ► Web Controls ► The Page Class ► A Typical Page ► State Management ► Configuration ► Deployment
Section 1

About ASP.NET

By Holger Schwichtenberg

ASP.NET stands for “Active Server Pages .NET”, however the full name is rarely used. ASP.NET is a framework for the development of dynamic websites and web services. It is based on the Microsoft .NET Framework and has been part of .NET since Version 1.0 was released in January 2002. The current version named 3.5 Service Pack 1 was released in August 2008. The next version, 4.0, is expected to be released at the end of the year 2009.

This Refcard summarizes the most commonly used core functions of ASP.NET. You will find this Refcard useful for some of the most common tasks with ASP.NET, regardless of the version you are using

Section 2

Installation

The best development environment for ASP.NET is Microsoft’s Visual Studio. You can either use the free Visual Web Developer Express Edition (http://www.microsoft.com/express/ vwd/) or any of the commercial editions of Visual Studio (e.g. Visual Studio Professional). The latest version that supports ASP.NET 2.0 and ASP.NET 3.5 is “2008” (internal version: 9.0). The .NET Framework and ASP.NET are part of the setup of Visual Web Developer Express Edition and Visual Studio. However, make sure you install Service Pack 1 for Visual Studio 2008, as this will not only fix some bugs but also add a lot of new features.

ASP.NET needs a server with the HTTP protocol (web server) to run. Visual Web Developer Express 2005/2008 and Visual Studio 2005/2008 contain a webserver for local use on your development machine. The “ASP.NET Development Server” (ADS) will be used when specifying a “File System” location when creating your project. Thus, “HTTP” would mean you address a local or remote instance of Internet Information Server (IIS) or any other ASP.NET enabled web server. ADS is a lightweight server that cannot be reached from other systems. However, there are differences between ADS and IIS, especially in the security model that makes it sometimes hard for beginners to deploy a website to the IIS that was developed with ADS. On the production system you will use IIS and only install the .NET Framework, because Visual Studio is not required here.

Hot Tip

If you choose to use Internet Information Server (IIS), install the IIS on your machine before installing the .NET Framework or Visual Studio. If you did not follow this installation order, you may use aspnet_regiis. exe to properly register ASP.NET within the IIS.
Section 3

ASP.NET Web Applications

An ASP.NET application consists of several .aspx files. An .aspx file can contain HTML markup and special ASP.NET markup (called Web Controls) as well as the code (Single Page Model). However, the Code Behind Model which comes with a separate code file called, the “Code Behind File” (.aspx. cs or .aspx.vb), provides a cleaner architecture and better collaboration between Web designers and Web developers. ASP.NET applications may contain several other elements such as configuration files (maximum one per folder), a global application file (only one per web application), web services, data files, media files and additional code files.

There are two types of Web projects: “Website Projects” (File/ New/Web Site) and “Web Application Projects” (File/New/ Project/Web Application). “Website” is the newer model, while Web Application Projects mainly exist for compatibility with Visual Studio .NET 2002 and 2003. This Refcard will only cover Web Site Projects. Most of this content is also valid for Web Applications.

Hot Tip

A well designed ASP.NET application distinguishes itself by having as little code in the Code Behind files and other code files as possible. The large majority of your code should be in referenced Assemblies (DLLs) as they are reusable in other Web applications. If you don’t want to put your code into a separate assembly, you at least should use separate classes in the “App_Code” folder within your web project.

Figure 1

Figure 1: The Content of an ASP.NET Web Application

Section 4

The ASP.NET Web Form Model

ASP.NET uses an object- and event-oriented model for web pages. The ASP.NET Page Framework analyzes all incoming requests as well as the .aspx page that the request is aimed at. The Page Framework creates an object model (alias control tree) based on this information and also fires a series of events. Event handlers in your code can access data, call external code in referenced .NET assemblies and manipulate the object model (e.g. fill a listbox or change the color of a textbox). After all event handlers have executed, the Page Framework renders the current state of the object model into HTML tags with optional CSS formatting, JavaScript code and state information (e.g. hidden fields or cookies). After interacting with the page, the user can issue a new request by clicking a button or a link that will restart the whole process.

Figure 2

Figure 2: The ASP.NET request/response life cycle

Section 5

Web Controls

An ASP.NET page can contain common HTML markup. However, only ASP.NET web controls provide full objectand event-based functionality. Web controls have two representations: In the .aspx files they are tags with the prefix “asp:”, e.g. <asp:TextBox<. In the code they are .NET classes, e.g. System.Web.UI.WebControls.TextBox.

Table 1 lists the core members of all web controls that are implemented in the base class “System.Web.UI.WebControls. WebControl”.

Name of Member Description
Id Unique identifier for a control within a page
ClientID Gets the unique identifier that ASP.NET generates if more than one control on the page has the same (String) ID.
Page Pointer to the page where the control lives
Parent Pointer to the parent control, may be the same as “Page”
HasControls() True, if the control has sub-controls
Controls Collection of sub-controls
FindControl(“NAME”) Finds a sub-control within the Controls collection by its ID
BackColor, BorderColor,
Borderstyle, BorderWidth,
Font, ForeColor, Height,
Width, ToolTip, TabIndex
Self-explaining properties for the formatting of the control.
CssClas The name of CSS class that is used for formatting the control
Style A collection of single CSS styles, if you don’t want to use a CSS class or override behavior in a CSS class
EnableViewState Disables page-scoped state management for this control
Visible Disables rendering of the control
Enabled Set to false if you want the control to be disabled in the browser
Focus() Set the focus to this control
DataBind() Gets the data (if the control is bound to a data source)
Init() Fires during initializtion of the page. Last chance to change basic setting e.g. the culture of the current thread that determines the behavior used for rendering the page.
Load() Fires during the loading of the page. Last to change to do any preparations./td>
PreRender() Fires after all user defined event handlers have completed
and right before rendering of the page starts. Your last
chance to make any changes to the controls on the page!
UnLoad() Event fires during the unloading of a page.

Table 1: Core Members in the base class system. Web.UI.WebControls.WebControl.

Tables 2, 3 and 4 list the most commonly used controls for ASP. NET web pages. However, there are more controls included in the .NET platform and many more from third parties not mentioned here.

Control Purpose Important specific members in
addition to the members inheritedn
from WebControl
<asp:Label> Static Text Text
<asp:TextBox> Edit Text (single line,
multiline or password)
TextMode, Text, TextChanged()
<asp:FileUpload> Choose a file for upload FileName, FileContent, FileBytes,SaveAs()
<asp:Button> Display a clasic button Click(), CommdName, Command()
<asp:ImageButton> Display a clickable image Click(), CommdName, Command()
<asp:LinkButton> Display a hyperlink that works like a button ImageUrl, ImageAlign, Click(),
CommdName, Command()
<asp:CheckBox> Choose an option Text, Checked, CheckedChanged()
<asp:RadioButton> Choose an option Text, Checked, CheckedChanged()
<asp:HyperLink> Display a hyperlink NavigateURL, Target, Text
<asp:Image> Display an image ImageURL, ImageAlign
<asp:ImageMap> Display a clickable
image with different
regions
ImageURL, ImageAlign,

Table 2: Core controls for ASP.NET web pages.

List controls display several items that the user can choose from. The selectable items are declared static in the .aspx file or created manually using the Items collection or created automatically by using data binding. For data binding you can fill DataSource with any enumerable collection of .NET objects. DataTextField and DataValueField specify which properties of the objects in the collection are used for the list control.

Hot Tip

If you bind a collection of primitive types such as strings or numbers, just leave DataTextField and DataValueField empty.

Hot Tip

Setting AppendDataBoundItems to true will add the databound items to the static items declared in the .aspx file. This will allow the user to select values that don’t exist in the data source such as the values “All” or “None”
Control Purpose Important specific members in
addition to the members inherited
from WebControl
<asp:Drop DownList> Allows the user to select
a single item from a
drop-down list
Items.Add(), Items.
Remove(), DataSource,,
DataTextField, DataValueField,
AppendDataBoundItems,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged()
<asp:ListBox> Single or multiple selection box Items.Add(), Items.
Remove(), DataSource,,
DataTextField, DataValueField,
AppendDataBoundItems,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged(),
Rows, SelectionMode
<asp:Check BoxList> Multi selection check box group Items.Add(), Items.
Remove(), DataSource,,
DataTextField, DataValueField,
AppendDataBoundItems,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged(),
RepeatLayout, RepeatDirection
<asp:Radio ButtonList> Single selection radio button group Items.Add(), Items.
Remove(), DataSource,,
DataTextField, DataValueField,
AppendDataBoundItems,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged(),
RepeatLayout, RepeatDirection
<asp:Bulleted List> List of items in a bulleted format Items.Add(), Items.
Remove(), DataSource,,
DataTextField, DataValueField,
AppendDataBoundItems,
SelectedIndez, SelectedItem,
SelectedValue, SelectedIndexChanged(),
BulletImageUrl, BulletStyle

Table 3: List Controls for ASP.NET web pages

Validation Controls check user input. They always refer to one input control ControlToValidate and display a text ErrorMessage if the validation fails. They perform the checks in the browser using JavaScript and also on the server. The client side validation can be disabled by setting EnableClientScript to false. However, the server side validation cannot be disabled for security reasons.

Control Purpose Important specific members
in addition to the members
inherited from WebControl
<asp:Required
FieldValidator>
Checks if a user changed the
initial value of an input control
ControlToValidate, ErrorMessage,
Display, EnableClientScript,
IsValid, InitialValue
<asp:Compare
Validator>
Compares the value entered by
the user in an input control with
the value entered in another
input control, or with a constant
value
ControlToValidate, ErrorMessage,
Display, EnablesClientScript,
IsValid, ValueToCompare, Type,
ControlToCompare
<asp:Range
Validator>
Checks whether the value of
an input control is within a
specified range of values
ControlToValidate, ErrorMessage,
Display, EnableClientScript,
IsValid, MinimumValue,
MaximumValue, Type
<asp:Regular
Expression Validator>
Checks if the user input
matches a given regular
ControlToValidate, ErrorMessage,
Display, EnavleClientScript,
IsValid, ValidationExpression
<asp:Custom
Validator>
Performs custom checks on the
server and optional also on the
client using JavaScript
ControlTValidate, ErrorMessage,
Display, EnableClientScript,
IsValid, ValidateEmptyText,
Client ValidationFunction,
ServerValidate()

Hot Tip

For the CustomValidator you can optionally write a JavaScript function that performs client side validation. The function has to look like this: <script type=”text/javascript”> function ClientValidate(source, args) { if (x > 0) // Any condition { args.IsValid=true; } else { args.IsValid=false; } } </script>
Section 6

The Page Class

All web pages in ASP.NET are .NET classes that inherit from the base class “System.Web.UI.Page”. The class Page has associations to several other objects such as Server, Request, Response, Application, Session and ViewState (see figure 3). Therefore, developers have access to a wide array of properties, methods and events within their code. Table 5 lists the most important members of a Page and its dependent classes. Please note that the Page class has the class Control in its inheritance hierarchy and therefore shares a lot of members with the WebControl class (e.g. Init(), Load(), Controls, FindControl). However, these members are not repeated here.

Figure 3

Figure 3: Object Model of “System.Web.UI.Page”

Member Description
Page Title Title string of the Page
Page.IsPostBack True, if page is being loaded in response to a client postback. False if it is being loaded for the first time.
Page.IsAsync True, if the page is loaded in an asynchronous request (i.e. AJAX request)
Page.IsValid True, if all validation server controls in the current validation group validated successfully
Page.Master Returns the MasterPage object associated with this page
Page.PreviousPage Gets the page that transferred control to the current page (only available if using Server.Transfer, not available with Response. Redirect)
Page.SetFocus(Control ControlID) Sets the browser focus to the specified control (using JavaScript)
Trace.Write Writes trace information to the trace log.
User.Identity.IsAuthenticated True, if the user has been authenticated.
User.Identity.AuthenticationType Type of Authentication used (Basic, NTLM, Kerberos, etc)
User.Identity.Name Name of the current user
Server.MachineName Name of the computer the web server is running on
Server.GetLastError() Gets the Exception object for the last exception
Server.HtmlEncode(Text) Applies HTML encoding to a string
Server.UrlEncode(Pah) Applies URL encoding to a string
Server.MapPath(Path) Maps the given relative path to an absolute path on the web server
Server.Transfer(Path) Stops the execution of the current page and starts executing the given page as part of the current HTTP request
Request.AcceptTypes String array of cliet-supported MIME accept types.
Request.Browser Provides information about the browser
Request.ClientCertificate Provides the certificate of the client, if SSL client authentication is used
Request.Cookies The list of cookies that the browser sent to the web server
Request.Form The name and value of the input fields the browser sent to the web server
Request.Headers Data from the HTTP header the browser sent to the web server
Request.IsAuthenticated True, if the user is authenticated
Request.IsSecureConnection True, if SSL is used
Request.Path Virtual path of the HTTP request (without server name)
Request.QueryString Name/Value pairs the browser sent as part of the URL
Request.ServerVariables Complete list of name/value pairs with information about the server and the current request
Request.Url Complete URL of the request
Request.UrlReferrer Refering URL of the request (Previous page, the browser visited)
Request.UserAgent Browser identification
Request.UserHostAddress IP address of the client
Request.UserLanguages Preferred languages of the user (determined by browser settings)
Response.BinaryWrite(bytes) Writes information to an HTTP response output stream.
Response.Write(string) Writes information to an HTTP response output stream.
Response.WriteFile(string) Writes the specified file directly to an HTTP response output stream.
Response.BufferOutput True if the output to client is buffered
Response.Cookies Collection of cookies that shall be sent to the browser
Response.Redirect(Path) Redirects a client to a new URL using the HTTP status code 302
Response.StatusCode HTTP status code (integer) of the output returned to the client
Response.StatusDescription HTTP status string of the output returned to the client
Session.SessionID Unique identifier for the current session (a session is user specific)
Session.Item Gets or sets individual session values.
Session.IsCookieless True, if the ID for the current sessions are embedded in the URL. False, if its stored in an HTTP cookie
ViewState.Item Gets or sets the value of an item stored in the ViewState, which is a hidden field used for state management witin a page
Application.Item Gets or sets the value of an item stored in the application state, which is an applicationscope state management facility

Table 5: Most important members of the Page class and its associated classes

Section 7

A Typical Page

Figure 4 shows the typical content of an .aspx page and Figure 5 the content of a typical code behind class. The sample used is a registration form with three fields: Name, Job Title and Email Address.

​x
1
​
2
<%@ Page Language=”C#” AutoEventWireup=”true”
3
  CodeFile=”PageName.aspx.cs” Inherits=”PageName” %>
4
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//en”
5
  “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
6
<html xmlns=”http://www.w3.org/1999/xhtml”>
7
<head runat=”server”>
8
  <title>Registration Page</title>
9
  <link href=”MyStyles.css” rel=”stylesheet” type=”text/css”/>
10
  <style type=”text/css”>
11
   .Headline
12
   {
13
    font-size: large; font-weight: bold;
14
   }
15
  </style>
16
 </head>
17
 <body>
18
  <form id=”c_Form” ruanat=”server”>
19
  <div>
20
   <asp:Label runat=”server” ID=”C_Headline” Text=”Please register:”
21
     class=”Headline”></asp:label>
22
    <p>Name:
23
   <asp:TextBox ID=”C_Name” runat=”server”></asp:TextBox>
24
   <asp:RequiredFieldValidator ID=”C_NameVal” ControlToValidate=”C_
25
   Name” ruanat=”server” ErrorMessage=”Name required”></
26
   asp:RequiredFieldValidator>
27
 </p>
28
    <p>Job Title:
29
   <asp:DropDownList ID=”C_JobTitle” runat=”server”>
30
  <asp:ListItem Text=”Software Developer” Value=”SD”></
31
 asp:ListItem>
32
  <asp:ListItem Text=”Software Architect” Value=”SA”></
33
   asp:ListItem>
34
  </asp:DropDownList>
35
 </p>
36
<p>EMail:
37
  <asp:TextBox ID=”C_EMail” runat=”server”></asp:TextBox>
38
   <asp:RequiredFieldValidator Id=”C_EMailVal1” ControlToValidate=”C_
39
  EMail” runat=”server” ErrorMessage=”EMail required”></
40
  asp:RequiredFieldValidator>
41
  <asp:RegularExpressionValidator ID=”C_EMailVal2”
42
 ControlToValidate=”C_EMail” runat=”server” ErrorMessage=”Email
43
   not valid” ValidationExpression=”\w+([-+.’]\w+)*@\w+([-.]\
44
     w+)*\.\w+([-.]\w+)*”>
45
   </asp:RegularExpressionValidator>
46
   </p>
47
   <p>
48
  <asp:Button ID=”C_register” runat=”server” Text=”Register”
49
 onclick=”C_Register_Click”/>
50
   </p>
51
   </div>
52
 </form>
53
</body>
54
</html>
55
​

Figure 4: Typical content of an ASPX file

36
1
​
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Web;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
public partial class PageName : System.Web.UI.Page
9
 {
10
  protected void Page_Load(object sender, EventArgs e)
11
   {
12
    // If an authenticated users starts using this page,
13
    // use his login name in the name textbox
14
    if (!Page.IsPostBack & Page.User.Identity.IsAuthenticated)
15
    {
16
     this.C_Name.Text = Page.User.Identity.Name;
17
     this.C_Name.Enabled = false;
18
    }
19
   }
20
 protected void C_Register_Click(object sender, EventArgs e)
21
  {
22
   if (Page.IsValid) // if all validation controls succedded
23
   { // call business logic and
24
    if (BL.Register(this.C_Name.Text, this.C_EMail.Text, this.C_
25
     JobTitle.SelectedValue))
26
    { // redirect to confirmation page
27
     Response.Redirect(“RegistrationConfirmation.aspx”);
28
    }
29
    else
30
    { // change the headline
31
     this.C_Headline. = “You are already registered!”;
32
    }
33
   }
34
  }
35
}    
36
​

Figure 5: Typical content of a Code Behind file

Section 8

State Management

State management is a big issue in web applications as the HTTP protocol itself is stateless. There are three standard options for state management: hidden files, URL parameters and cookies. However, ASP.NET has some integrated abstractions from these base mechanisms know as View State, Session State, and Application State. Also, the direct use of cookies is supported in ASP.NET.

Hot Tip

Disabling the View State (EnableViewState=false in a control) will significantly reduce the size of the page sent to the browser. However, you will have to take care of the state management of the controls with disabled View State on your own. Some complex controls will suffer the loss of functionality without View State.

The following code snippet shows how to set values for a counter stored in each of these mechanisms:

9
1
​
2
ViewState[“Counter”] = CurrentCounter_Page + 1;
3
Session[“Counter”] = CurrentCounter_Session + 1;
4
Application[“Counter”] = CurrentCounter_Application + 1;
5
Response.Cookies[“Counter”].Value = (CurrentCounter_User +
6
  1).ToString();
7
Response.Cookies[“Counter”].Expires = DateTime.MaxValue; // no
8
  expiration
9
​

Figure 6: Setting Values

Hot Tip

When reading value from these objects, you have to check first if they already exist. Otherwise you will recieve the exception “NullReferenceExeception: Object reference not set to an instance of an object.”

The following code snippet shows how to read the current counter value from each of these mechanisms: Next Column ---->

Mechanism Scope Lifetime Base Mechanism Data Type Storing Value Reading Value
View State Single user on a single page Leaving the current page Hidden FIeld “ViewState” Object (any serializable.NET data type) Page.ViewState Page.ViewState
Session State Latest interaction of a single
user with the web page
Limited number of minutes after the last request from
the user
Cookie (“ASPSessionJD...”)or URL Parameter “(S(...))”
plus server side store (local RAM, RAM on dedicated
server or database)
Object. Object must be serializable
if the store is not the local RAM
Page.Session Page.Session
Cookies A single User Closing of the browser or dedicated point in time Cookie String Page.Response.Cookies/td> Page.Response.Cookies
Application State All users Shutting down the web application Local RAM Object Page.Application Page.Application
17
1
​
2
long CurrentCounter_Application, CurrentCounter_ApplicationLimited,
3
CurrentCounter_Session, CurrentCounter_Page, CurrentCounter_User;
4
 if (Application[“Counter”] == null) { CurrentCounter_Application =
5
  0; }
6
  else { CurrentCounter_Application = Convert.ToInt64(Application[“C
7
   ounter”]); }
8
 if (Session[“Counter”] == null) { CurrentCounter_Session = 0; }
9
  else { CurrentCounter_Session = Convert.
10
   ToInt64(Session[“Counter”]);}
11
 if (ViewState[“Counter”] == null) { CurrentCounter_Page = 0; }
12
  else { CurrentCounter_Page = Convert.
13
ToInt64(ViewState[“Counter”]); }
14
 if (Request.Cookies[“Counter”] == null) { CurrentCounter_User = 0; }
15
  else { CurrentCounter_User = Convert.ToInt64(Request.
16
   Cookies[“Counter”].Value); }
17
​

Figure 7: Reading Values

Section 9

Configuration

All configurations for ASP.NET applications are stored in XMLbased configuration files with the fixed name “web.config”. In addition to the configuration files in the application root folder, subfolders may also contain a web.config that overrides parent settings. Also, there are the global configuration files machine. config and web.config in the folder \Windows\Microsoft.NET\ Framework\v2.0.50727\CONFIG that provide some default settings for all web applications. (Note: v2.0.50727 is still correct for ASP.NET 3.5!).

Visual Studio and Visual Web Developer create a default root configuration file in your web project that contains a lot of internal setting for ASP.NET 3.5 to work properly. Figure 6 shows a fragment from a web.config file with settings that are often used.

37
1
​
2
<!-- Connection strings -->
3
<connectionStrings>
4
  <add name=”RegistrationDatabase” connectionString=”Data
5
Source=EO2;Initial Catalog= RegistrationDatabase;Integrated
6
Security=True” providerName=”System.Data.SqlClient” />
7
</connectionStrings>
8
<!-- User defined settings -->
9
<AppSettings>
10
  <and key=”WebmasterEMail” value=”hs@IT-Visions.de” />
11
</appSettings>
12
<system.web>
13
  <!-- Specify a login page -->
14
  <!-- Use the URL for storing the authentication ID if cookies are
15
not allowed -->
16
  <!-- Set the authentication timeout to 30 minutes -->
17
<authentication mode=”Forms”>
18
  <forms loginUrl=”Login.aspx” cookieless=”AutoDetect” timeout=”30”>
19
  </forms>
20
  </authentication>
21
   <!-- Deny all unauthorizd access to this application -->
22
  <authorization>
23
   <deny users=”?” />
24
  </authorization>
25
 <!-- Use the URL for storing the session ID if cookies are not
26
allowed -->
27
 <!-- Set the session timeout to 30 minutes -->
28
 <sessionState cookieless=”AutoDetect” timeout=”30”></sessionState>
29
<!-- Display custom error pages for remote users -->
30
<customErrors mode=”RemoteOnly” defaultRedirect=”GenericErrorPage.
31
  htm”>
32
  <error statusCode=”403” redirect=”NoAccess.htm” />
33
  <error statusCode=”404” redirect=”FileNotFound.htm” />
34
</customErrors>
35
<!-- Turn on debugging -->
36
<compilation debug=”false”>
37
​

Figure 8: Typical setting in the web.config file.

Hot Tip

Please make sure you turn debugging off again before deploying your application as this decreases execution performance.
Section 10

Deployment

ASP.NET applications can be deployed as source code via the so called “XCopy deployment”. This means you copy the whole content of the web project folder to the production system and configure the target folder on the production system as an IIS web application (e.g. using the IIS Manager). The production web server will automatically compile the application during the first request and recompile automatically if any of the source files changed.

However, you can precompile the application into .NET assemblies to improve protection of your intellectual property and increase execution speed for the first user. Precompilation can be performed through Visual Studio/Visual Web developer (Menu “Build/Publish Website”) or the command line tool aspnet_compiler.exe.

Hot Tip

Download the “Visual Studio 2008 Web Deployment Projects” from microsoft.com. This is an Add-In that provides better control over the precompilation process.

Like This Refcard? Read More From DZone

related article thumbnail

DZone Article

Working With More Than One web.config Files in an asp.net Application
related article thumbnail

DZone Article

Paging ASP.NET ListView using DataPager without using DataSource Control
related article thumbnail

DZone Article

WPF Validation: How to Validate the Whole Form on the Button Click
related article thumbnail

DZone Article

Windows 10 Isn’t Really Free for Software Testers
related refcard thumbnail

Free DZone Refcard

Getting Started With Low-Code Development
related refcard thumbnail

Free DZone Refcard

JavaScript Test Automation Frameworks
related refcard thumbnail

Free DZone Refcard

Salesforce Application Design
related refcard thumbnail

Free DZone Refcard

E-Commerce Development Essentials

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: