Skip to navigation

PCPro-Computing in the Real World Printed from www.pcpro.co.uk

Register to receive our regular email newsletter at http://www.pcpro.co.uk/registration.

The newsletter contains links to our latest PC news, product reviews, features and how-to guides, plus special offers and competitions.

Real World Computing

Configuring ASP.NET

Posted on 20 Feb 2006 at 12:07

Thomas Lee looks at how to manage and configure ASP.NET, together with IIS and HTTP

ASP.NET Does Integer Maths!

ASP.NET Simple Integer Calculator

A:

B:

Result:

OnClick="Add" Width="135" />

As you can see, this page contains only layout and calls to process the data. When it's clicked, ASP.NET gets directed to call the Add method, but the details of what exactly is to happen are contained in the Add method's separate code-behind file. The @PAGE directive at the top of the page tells ASP.NET which code-behind file (calc.aspx.cs) contains the Add method.

calc.aspx.cs looks like this:

using System;

public partial class _Default : System.Web.UI.Page

{

protected void Add(object sender, EventArgs e) //add 2 numbers

{

int d1 = Convert.ToInt32(TextBox1.Text);

int d2 = Convert.ToInt32(TextBox2.Text);

int result = d1+d2;

Label1.Text=result.ToString();

}

protected void Sub (object sender, EventArgs e) //subtract 2 numbers

{

int d1 = Convert.ToInt32(TextBox1.Text);

int d2 = Convert.ToInt32(TextBox2.Text);

int result = d1-d2;

Label1.Text=result.ToString();

}

}

When you first request calc.aspx in your browser, the web server sends the HTML page, which includes an HTML form. When you click on either of its buttons, the browser sends the information you enter into the two textboxes back to the server, along with an indication of which button was pressed. Once the request is received at the server, ASP.NET orchestrates calling the appropriate method (the Add method if you clicked the first button).

Configuring ASP.NET

You can configure ASP.NET in three separate places:

IIS Manager MMC snap-in: use IIS Manager to configure general web app settings required for your ASP.NET app, to configure app pools and add or remove websites from your system.

ASP.NET configuration files: ASP.NET uses a hierarchy of web.config files, which apply only to ASP.NET resources.

Page code: some configuration items are actually contained in the web page itself; for example, in the <@Page...> directive. You can disable HTTP response buffering using the Buffer attribute (http://msdn.microsoft.com/ library/default.asp?url=/library/en-us/cpgenref/html/cpconPage.asp)

For the most part, though, you'll be configuring ASP.NET apps in web.config. .NET provides a single machine.config file, which holds master settings applying to all apps running on the same computer, located in:

%systemroot%\Microsoft.NET\\CONFIG\machine.config,

where is v2.0.50727 for .NET 2 and v1.1.4322 for .NET 1.1. Web.config files are located in the virtual folders that make up your website, side by side with the web content. Tools like Visual Web Developer Express make this relatively easy.

If the application URL is multilevel, as in myserver/a/b/c/calc.asp, you can have a web.config file in each of the virtual folders in the URL path - that is, /a/web.config, /a/b/web.config and /a/b/c/web.config - where values specified lower in the virtual path override values higher up. There's also a 'no override' feature to avoid lower-level web.config values overriding those higher up where necessary. And ASP.NET blocks any request for web.config files, so you can only view them via the PC's own file system, not remotely.

1 2 3 4 5
Be the first to comment this article

You need to Login or Register to comment.

(optional)

advertisement

Latest Real World Computing
Latest Blog Posts Subscribe to our RSS Feeds
Latest News Stories Subscribe to our RSS Feeds
Latest Reviews Subscribe to our RSS Feeds

advertisement

Sponsored Links
 
SEARCH
SIGN UP

Your email:

Your password:

remember me

advertisement


Hitwise Top 10 Website 2008