The ASP .NET Debugging Options in IIS
There are many occasions we need to troubleshoot the web applications which have several technologies tied together. For the ASP .NET hosting we can enable the server-side and client side debugging as shown in the following screenshots. It is accessed from the Your_Web_Site Properties page provided the ASP was installed and running properly. Make sure you disable these settings for the production or real deployment.
The following screenshot shows the debugging options for ASP .NET which are very useful in assisting the troubleshooting tasks during the development stage.
Other info for debugging the web applications is through the IIS log file. Click the Web Site property page and there are several standard logging formats that you can choose from. Then click the Properties button.
We can customize the details of the logging properties using the General Properties and Extended Properties pages.
The following screenshots shows the detail of the IIS web extended logging. Make sure you just select the desired options only because for high volume of traffic it will consume a lot of storage.
The following screenshot shows the IIS log file physical path which can be opened by any text editor or exported to other format such as spreadsheet.
The following screenshot shows a sample of the IIS log file content opened in the text editor.
Well, let get back to our project. We can actually publish the web service or application directly from the VS IDE. Select the web service project folder > Right-click mouse > Select the Publish menu. We are not completing this task in this exercise because we already publish the web service 'manually' (just click the Cancel button in the Publish Web page).
Set the target location for the web service or application and then click the Publish button.
Next, let continue developing our asynchronous web service project. We will add a new project that will demonstrate the asynchronous access to the web service. In the new implementation of the asynchronous web access, most of the tasks already have been automated using the event based asynchronous web access techniques however in this exercise we are using the old techniques which based on the early .NET class library. Create a new project in the current solution.
Select the solution folder > Right-click mouse > Click Add menu > Click the New Project sub menu.
Select Class Library template and you can use the AsyncModuleCS as the project name if you want. Click the OK button.
Rename the file to AsyncModule to reflect the application to be developed. The class will be renamed automatically. This class will define the IHttpModule interface which includes the event handler and asynchronous callback.
Add the following using directives and delete the unused directives.
Add/edit the following given code.
/// Demonstrates an async module in ASP.NET
public class AsyncModule : IHttpModule
// static data members
static int counter = 0;
static int modCounter = 0;
const string RedirectLocation = "accessdenied.aspx";
// instance data members
Regex locationRegex = new Regex(RedirectLocation, RegexOptions.IgnoreCase);
public void Init(HttpApplication app)
// register for our async event
app.AddOnAuthorizeRequestAsync(new BeginEventHandler(ref AsyncBeginHandler),
new EndEventHandler(ref AsyncEndHandler));
// add a sync EndRequest handler to explain what happened if access is denied
app.EndRequest += new EventHandler(ref OnEndRequest);
int modCount = Interlocked.Increment(ref modCounter);
TraceHelper.WriteLine("Initializing the module instance", modCount);
// Required on this interface
public void Dispose()
public IAsyncResult AsyncBeginHandler(object src, EventArgs e, AsyncCallback cb, object extraData)
HttpApplication app = (HttpApplication)src;
// per-request init
instanceCounter = Interlocked.Increment(ref counter);
isAuthorized = false;
ctx = app.Context;
// let anyone into the access denied page
Match m = locationRegex.Match(ctx.Request.FilePath);
// is it something other than accessdenied.aspx? Check authorization...
// create service proxy, async result, and callback
AsyncModuleCS.localhost.Service1 authServ = new AsyncModuleCS.localhost.Service1();
MyAsyncResult myAr = new MyAsyncResult(cb, authServ, instanceCounter);
AsyncCallback myCb = new AsyncCallback(ref WebServiceAsyncCallback);
// start async call
TraceHelper.WriteLine("Begin the authorization...", instanceCounter);
authServ.BeginIsAuthorized(ctx.User.Identity.Name, myCb, myAr);
else // otherwise, complete synchronously
isAuthorized = true;
TraceHelper.WriteLine("Request for accessdenied asp page, skipping...", instanceCounter);
return new MyAsyncResult(null, null, true, true, null, instanceCounter);
public void AsyncEndHandler(IAsyncResult ar)
MyAsyncResult myAr = (MyAsyncResult)ar;
TraceHelper.WriteLine("End the authorization...", instanceCounter);
// if this user isn't authorized, then bail out
ctx.Response.StatusCode = 403;
TraceHelper.WriteLine("Request Rejected!", instanceCounter);
// clear variables
ctx = null;
instanceCounter = -1;
isAuthorized = false;
myAr.EndOp(); // Throw if necessary
public void WebServiceAsyncCallback(IAsyncResult ar)
MyAsyncResult myAr = (MyAsyncResult)ar.AsyncState;
AsyncModuleCS.localhost.Service1 authServ = (AsyncModuleCS.localhost.Service1)myAr.AsyncState;
// get back result
isAuthorized = authServ.EndIsAuthorized(ar);
TraceHelper.WriteLine("WebService call completed...", instanceCounter);
// tell ASP.NET we're done
int cnt = instanceCounter;
TraceHelper.WriteLine("Begin notifing ASP.NET...", cnt);
myAr.Complete(false, isAuthorized, null);
TraceHelper.WriteLine("End notifing ASP.NET...", cnt);
public void OnEndRequest(object src, EventArgs E)
HttpApplication app = (HttpApplication)src;
// did we block someone?
if (app.Response.StatusCode == 403)
Many times we have encountered the unresolved System.Net namespace when using VStudio 2008 which also happens in VStudio 2005. So, you can see the IHttpModule interface in the code cannot be resolved and under the References folder, there is no System.Web namespace although we already included the using System.web namespace using directive. So we need to include it manually.
Select the project folder > Right-click mouse > Select Add Reference menu.
In the .NET page, select the System.Web component and click OK button.
Now, you can see the System.Web namespace in the References folder and any reference to the namespace should be resolved.
Next we will resolve the reference to the web service created in the previous project.