I still remember the day when I joined Microsoft in Oct 2004. I was excited to be in my dream company, and at the same time, quite tense that I would now be required to support ASP.NET. I was a pure WinForm guy then and since I came from a very small company, “I am a pretty good programmer” thought was getting etched somewhere deep in my mind. Boy, what a big frog I was in a really shallow well! I still thank God for getting me here and showing me the mirror. Not that I’ve become a genius of any sorts, but now I probably understand a little bit more about the term “Smart Programmer” and why you shouldn’t be calling GC.Collect too many times, why knowing the architecture is as important as coding itself, why web garden in IIS is not supposed to fix all your performance issues, etc. etc. etc.

!!
Over the last 4 years, I have learnt a lot of things and have worked with some pretty amazing folks. Folks who debug and fix all sort of issues with ASP.NET/IIS and still so humble about it.
I loved my stint at DSI. I am feeling nostalgic and super-excited yet again, since on 8th of September, I would no longer be a part of IIS/ASP.NET team. I would be joining as a Product Field Engineer for Sharepoint. I hear that Sharepoint is rocking the world stage big-time, and it will be a pretty nice task that I will be doing. Reminds me of the fact that history repeats itself. From a Winform to IIS/ASP.NET and now over to Sharepoint. Let’s see what future has in store for me.
For the few folks who read my blogs, expect a lot more stuff on Sharepoint. And by the way, it happens to be my last post here. Going forward I will be posting exclusively on http://www.dotnetscraps.com/. Will see you there...
For my dear team members > If you are reading this, I am sure that I am NOT gonna miss you, since we’ll keep in touch always
!!
-Rahul
In one of my previous posts, I mentioned about how to troubleshoot some issues with the use of a module. In this post, I will show you how a similar module could be of use when you want to log all the errors in a text file for troubleshooting purposes. Please ensure that C:\Temp folder has Write access for the account that is running the IIS Worker Process. Here is the code for the module...
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
namespace myModules
{
class Trigger:IHttpModule
{
public void Init(System.Web.HttpApplication context)
{
context.EndRequest += new EventHandler(this.EndRoutine);
}
public void EndRoutine(object o, EventArgs e)
{
HttpApplication myApp;
myApp = (HttpApplication)o;
HttpContext c = myApp.Context;
if (myApp.Context.AllErrors != null)
{
StreamWriter sw = new StreamWriter("C:\\Temp\\ErrorList.txt", true);
foreach (Exception ex in myApp.Context.AllErrors)
{
sw.WriteLine("Error occurred at #{0}", DateTime.Now.ToString());
sw.WriteLine("Error occurred in page #{0}", c.Request.FilePath);
sw.WriteLine(ex.InnerException.Message);
sw.WriteLine(ex.InnerException.StackTrace);
sw.WriteLine();
}
sw.Dispose();
}
}
public void Dispose()
{
//Nothing to Dispose as of now
}
}
}
You can save the downloaded file to the bin folder of your web application and add the following to the web.config...
<httpModules>
<add name="Trigger" type="myModules.Trigger, myModules"/>
</httpModules>
Here is the sample output (C:\Temp\ErrorList.txt) for one of the applications where I have used the Throw New AppDomainUnloadedException or similar lines to create the error...

Hope this helps,
Rahul
Quote of the day:
The nice thing about standards is that there are so many of them to choose from. - Andrew S. Tanenbaum
Posted at > 6:10 PM IST
This blog entry is a continuation of the KB Article http://support.microsoft.com/?id=910447
Scenario 9:Find out what is the peak time for your IIS Server
How can you find out what is the peak time (peak hour) for your Website using Logparser?
Answer:
Logparser "SELECT quantize(time,60), count(*) as Frequency from ex080716.log GROUP BY quantize(time,60) order by quantize(time, 60)" -rtp:-1
Here is a brief snapshot of my LogFile...
And here is the output...
QUANTIZE(time, 60) Frequency
------------------ ---------
02:37:00 4
02:38:00 3
02:39:00 8
02:40:00 55
02:41:00 215
02:45:00 40
02:46:00 36
Statistics:
-----------
Elements processed: 361
Elements output: 7
Execution time: 0.00 seconds
You may also try...
Logparser "SELECT quantize(time,60), count(*) as Frequency INTO Image.GIF from ex.log GROUP BY quantize(time,60) order by quantize(time, 60)"
Here is the output...
This tells me that 2:41 GMT is the Peak Minute for my web-site. If you want to get the details per hour... change the query to...
Logparser "SELECT quantize(time,3600), count(*) as Frequency INTO Image.GIF from ex.log GROUP BY quantize(time,3600) order by quantize(time, 3600)"
As you can easily figure out, my site doesn't have too many hits after all 
Hope this helps...
Rahul
Quote of the day:
People who have no weaknesses are terrible; there is no way of taking advantage of them. - Anatole France
Posted at > 10:07 AM IST
...well first of all, I am NOT recommending it, but sometimes it could be necessary! Now, let's proceed to the code...
1. Create a page called RunBatchFile.vb and paste the following...
Imports System.Diagnostics
Imports System.IO
Partial Class RunBatchFile
Inherits System.Web.UI.Page
Dim _password As New System.Security.SecureString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim password As String
'Read from any Registry or Encrypted config file if you like for added security.
password = "YOUR___PASSWORD"
For Each c As Char In password
_password.AppendChar(c)
Next
Dim strFilePath As String = "c:\\temp\\test.bat"
Dim psiMyProcess As ProcessStartInfo = New ProcessStartInfo("cmd.exe")
psiMyProcess.LoadUserProfile = True
psiMyProcess.UserName = "Administrator"
psiMyProcess.Password = _password
psiMyProcess.UseShellExecute = False
psiMyProcess.CreateNoWindow = True
psiMyProcess.RedirectStandardOutput = True
psiMyProcess.RedirectStandardInput = True
psiMyProcess.RedirectStandardError = True
psiMyProcess.WorkingDirectory = "c:\\temp\\"
Dim prcProcess As Process = Process.Start(psiMyProcess)
Dim strm As StreamReader = File.OpenText(strFilePath)
Dim strOut As StreamReader = prcProcess.StandardOutput
Dim strIn As StreamWriter = prcProcess.StandardInput
Do While strm.Peek() <> -1
strIn.WriteLine(strm.ReadLine())
Loop
strm.Close()
strIn.WriteLine(String.Format("# {0} ran successfully. Exiting now!", strFilePath))
strIn.WriteLine("Exit")
prcProcess.Close()
Dim strOutput As String = strOut.ReadToEnd().Trim()
strIn.Close()
strOut.Close()
Response.Write(String.Format("<font face=courier size=0>{0}</font>", _
strOutput.Replace(System.Environment.NewLine, "<br>")))
End Sub
End Class
2. The batch file that I have is a one liner (and a no-brainer)... [Here, one and two are folders containing a few files]
xcopy one\*.* two /y
3. If everything is in place, you should get something like this as output...
Hope this helps,
Rahul
Quote of the day:
The human race has one really effective weapon, and that is laughter. - Mark Twain
No matter how many things you keep in mind before developing an application, when once they are put in production... quite often you will see something not behaving the way you expected. Many-a-times, the applications would throw an error which you can troubleshoot depending on the error message you found. In this post, my intention is not to cover those "error" scenarios. I intend to cover something which is more problematic to troubleshoot... like intermittent slowness in some pages, or some errors that are coming up and you are not able to locate what's wrong with those bad-pages.
What would you do in those situations??
I know there is not a single correct answer to this question and it is scenario specific. Let me show you one little trick which might help you while troubleshooting your web-applications. This application (module) is no-where near completion... it just shows you how you can use Modules to troubleshoot the issue. You can tweak the code based on your scenario and work accordingly. I will share the plain httpmodule in this post. Once I am done with this module with lots of other automated configuration stuff (like capturing all viewstate, session information, etc), I will update my blog accordingly.
Let's proceed by creating a class Library (I will call it myModules)
1. Add a reference to System.Web
2. Copy the following in a new class file called Trigger.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace myModules
{
class Trigger:IHttpModule
{
DateTime fTimerValue;
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += new EventHandler(this.BeginRoutine);
context.EndRequest += new EventHandler(this.EndRoutine);
}
public void BeginRoutine(object o, EventArgs e)
{
fTimerValue = DateTime.Now;
}
public void EndRoutine(object o, EventArgs e)
{
HttpApplication myApp;
TimeSpan t = TimeSpan.MinValue;
myApp = (HttpApplication)o;
HttpContext c = myApp.Context;
if(c.Response.StatusCode == 200)
{
t = DateTime.Now - fTimerValue;
if (t.TotalSeconds > 5)
{
c.Response.Write("Tweak this page!! It took... " + t.TotalSeconds + " seconds");
c.Response.Write("<BR>");
c.Response.Write("Name > " + c.Request.PhysicalPath);
return;
}
}
myApp.Context.Response.Write("This response took " + t.ToString() + " seconds");
}
public void Dispose()
{
//Nothing to Dispose as of now
}
}
}
3. In your WebApplication... drop the
myModules.dll from the class library that you just created.
4. Last step... modify the web.config by adding...
<httpModules>
<add name="Trigger" type="myModules.Trigger, myModules"/>
</httpModules>
5. I tried this with an Empty project. And introduced Sleep statement in the Page_Load...
protected void Page_Load(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(26000);
}
6. Notice that, I haven't recompiled my web-application. Only thing that is required is... copy the DLLs in the bin folder and add httpModules section in the web.config.
The output is...
As I said earlier... this is a very meager output, and not enough to fix the issue. But now that you know how to use Modules to troubleshoot your application, feel free to tweak around the code and fix the issue at hand.
Happy troubleshooting!
Rahul
Quote of the day:
An idealist is one who, on noticing that a rose smells better than a cabbage, concludes that it will also make better soup. - H. L. Mencken
If you work with a lot of samples, the chances are quite likely that you will end up in a rather dirty list of Recent Projects List in Visual Studio. I'm personally quite nit-picky and I really hate it when I find something like this...
Now... I don't know which of these Samples should I click on (since I have two in the list!). Anyway, there are multiple reasons why you would like to remove the junk entries from this list. One way is to open the Registry and navigate to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\ProjectMRUList. This list contains all the values you are looking for. Delete the values which you don't like and restart Visual Studio.
Another way, which I think is a smarter one is to download this ZIP and do the following...
1. Extract it anywhere in your machine.
2. Open Visual Studio, click on Tools -> External Tools...
3. Click on Add button and in the Title field, write "Clear Recently Used List"
4. In the Command Line, browse to the <SAVED__PATH>\ClearRecentItems.exe and click on OK.
4. Now, you should have this tool listed on your Tools Menu in VS 2008.
5. Here is the sample output...
Feel free to download the code for this small utility...
Hope this helps,
Rahul
There are times when you want to incorporate a picture, a large piece of code in a limited web space... ex. a blog post which has a lot of <DIV> tags. Now, to crop or resize the picture may not be the option always. I still see a lot posts where the images are either cropped or line breaks are introduced into the code.
The problem with the line break is that it increases the overhead and time spent on the blogger's part in formatting the post. Apart from that, it also creates chances of typos which would make that code snippet not compile when an end user tries it.
Let's say I have a piece of code which I want to blog about (in Windows Live Writer)...
I use Paste from Visual Studio plugin and really love it. When I paste my code from Visual Studio using the Plugin, here is what I get...
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html 'I am making this line even longer' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ OutputCache Duration="72000" VaryByParam="none" Location="Any" %>
See how the 4th line overflows! Not good, right? So, what next???
Noooo... please don't split that line.....
Select View -> HTML Code and add the DIV tag as follows around the code.
<div style="overflow: scroll">
Your Code Or Image.
</div>
Here is the output...
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Drawing" %>
<!DOCTYPE html 'I am making this line even longer' PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ OutputCache Duration="72000" VaryByParam="none" Location="Any" %>
Hope this helps,
Rahul
UPDATE> Going forward I will be posting on www.dotnetscraps.com. It will give me much more flexibility in hosting the code and do some of the other things that I have in my mind for quite some time now.
When I tried opening the AjaxControlToolkit.sln by double clicking on it, it was throwing the following error at me...
---------------------------
Microsoft Visual Studio
---------------------------
The application for project 'H:\Downloads\AjaxControlToolkit\SampleWebSite' is not installed.
Make sure the application for the project type () is installed.
---------------------------
OK Help
---------------------------
To get rid of it, open the SLN file directly from File -> Open -> Project/Solution. Create a backup if you like (when prompted!).
You may also get the following error while trying to compile the Solution...
Parser Error Message: Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
This is because, you probably didn't install the AJAXControl Toolkit. Get it from here.
Another error that you could encounter is...
error : Could not load file or assembly 'vjslib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Done building project "TemplateVSI.csproj" -- FAILED.
Install JS Redist from here and you should be good.
Cheers,
Rahul
I have found that a couple of my plug-ins, namely Social Bookmarking and Smiley Plugin don’t work as expected in Windows Live Writer’s latest version. If you are encountering any issues and running Vista machine, please try running WLW as an Administrator.
Apparently a few things changed with WLW and I am still investigating if there is a way to make this work in a Non-Admin mode. I will keep you posted if I discover the root cause.
Thanks,
Rahul
...and I am pretty excited about it! In our team, we deal with a lot of issues with IIS and ASP.NET and have a plenty of folks in our team who blog individually, and do it pretty well.
We will continue to have our own blogs, but going forward you will see a lot of good information about troubleshooting IIS 7 and ASP.NET from a bunch of really talented folks. Feel free to subscribe to our new team blog and let me know if you would like to see some more topics that you require help on. It could be anything from simple to complex, related to IIS 7 or ASP.NET. Our focus is not only knowledge sharing, but also sharing some of the troubleshooting skills that we acquire because of handling multiple complex issues as a part of our job.
Definitely, I won't have all the answers, but I am priviledged to be working with quite a lot of smart folks who do
!!
As an insider let me tell you that we are coming up with a lot of posts which will help you create different modules with IIS 7. Give us a lot of hits on the new blog </shameless promotion of our team ends!>) 
Cheers,
Rahul
Quote of the day: A person who trusts no one can't be trusted. - Jerome Blattner
This blog entry is a continuation of the KB Article http://support.microsoft.com/?id=910447.
Scenario 8: Checking the traffic/requests between a specific client and server
Why would you do it in the first place?
You may want to troubleshoot an authenticate issue for that specific client for the error that s/he reported to you. May be that's why!
Answer:
Logparser "select date, time, c-ip, cs-username, s-sitename, s-computername, s-ip, s-port, cs-method, cs-uri-stem, cs-uri-query, sc-status, sc-substatus,sc-win32-status, sc-bytes, cs-bytes, time-taken,cs-version, cs-host, cs(User-Agent), cs(Cookie), cs(Referer), s-event, s-process-type, s-user-time, s-kernel-time, s-page-faults, s-total-procs, s-active-procs, s-stopped-procs from <FILENAME> where c-ip='Client-IP'" -i:IISW3C -rtp:-1
And the output will be something like...
Hope that helps,
Rahul
Quote of the day: It may be true that the law cannot make a man love me, but it can stop him from lynching me, and I think that's pretty important. - Martin Luther King Jr.
I joined the Windows Mobile bandwagon pretty late and still getting used to it. No doubt, it is awesome, but it does come with its own set of frills. I realized it when my time zone (Start->Settings->System, Clock & Alarms) always went back to GMT+1 Prague, Budapest. I used to change it often and reset my time, but pretty soon it started frustrating me and I was thinking to go back to the service center to get this fixed.
Thankfully, the troubleshooter in me woke up
and I decided to check if this is an issue just with my device or the OS. Pretty soon, I came to know from one of my colleagues, that not only he suffered from the same problem... he also found a fix for it.
Start -> Settings -> Personal Tab
Phone -> Time Zone -> Automatic Change time zone and clock. Uncheck this checkbox and the problem should go away.
Now, a bit of rant...
Windows Mobile is great, but as a newbie, I just don't get this behavior. Why the heck would this be a feature (or is this a bug)?? Changing the time zone sounds fine if I am travelling, but how does it make sense if I am located at Bangalore, have already set my time zone, and next morning I appear in Prague, without a ticket !!! Well, technology can sure take us places, I guess
.
<Rant ends!>
Until next time
Rahul
Quote of the day: We learn something every day, and lots of times it's that what we learned the day before was wrong. - Bill Vaughan
Or... what exactly is this "Compatibility Files" folder icon doing in my Windows Explorer??
Jerry's Blog explains this stuff beautifully!
So, why am I blogging about this?
Well... to cut the long story short, I have lost almost 3 hours yesterday searching for some files/folders to fix an issue with one of my software which had a corrupted cache folder. The support professionals asked me to delete some specific folder along with a couple of files, and I was not able to find them... no matter how much I searched. In the end, when I clicked on Compatibility Files, I found that the address bar changed as follows... and the files were right there! Honestly, it felt as if those files were giving that mocking smile at me
!!
Thought you should know...
Until next time 
Rahul
Quote of the day: First secure an independent income, then practice virtue. - Greek Proverb
I have created a very simple C# console application which gives me the following MSIL code when compiled... The next screenshot has almost the same code but with some special difference. Can you tell me what could have caused it and is it good or bad?
I will answer this in the comments (or next post as necessary)
.
Until then...
Cheers,
Rahul
Quote of the day: I'm a great believer in luck, and I find the harder I work the more I have of it. - Thomas Jefferson
There are quite a few times, when I get an issue related with a specific DataControl and I want to bind it to a datasource. All geared up and with full enthusiasm, I start dealing with the issue... and DARN... I find that I did something awfully bad with my SQL Server during my last case!! So now, instead of fixing my core issue, I end up fixing my SQL Server. Since we don't really like digressing from the main issue I am posting this entry on my blog so that I could keep it handy and instead of fixing the SQL server, I can concentrate on fixing the root cause of the issue. By the way, SQL server rocks... more often than not, it is my bad that I end up doing something silly against it 
SamplePage1.aspx in C#
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public class SampleDataSource
{
DataTable dt;
public SampleDataSource()
{
dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Description", typeof(string));
dt.Columns.Add("Address", typeof(string));
for (int i = 0; i < 10; i++)
{
DataRow dr;
dr = dt.NewRow();
dr["ID"] = i;
dr["Name"] = "Some Name " + i.ToString();
dr["Description"] = "Some Description " + i.ToString();
dr["Address"] = "Some Address " + i.ToString();
dt.Rows.Add(dr);
}
}
public DataTable DataSource
{
get
{
return this.dt;
}
}
}
protected void Populate_Click(object sender, EventArgs e)
{
SampleDataSource s = new SampleDataSource();
GridView1.DataSource = s.DataSource;
GridView1.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" Width="50%" runat="server">
</asp:GridView>
<asp:Button ID="Populate" runat="server" Text="Populate" onclick="Populate_Click" />
</div>
</form>
</body>
</html>
SamplePage2.aspx in VB.NET
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Class SampleDataSource
Dim dt As DataTable
Public Sub New()
Dim i As Integer
dt = New DataTable
dt.Columns.Add("ID", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
dt.Columns.Add("Description", GetType(String))
dt.Columns.Add("Address", GetType(String))
For i = 0 To 10
Dim dr As DataRow
dr = dt.NewRow
dr("ID") = i
dr("Name") = "Some Name " + i.ToString()
dr("Description") = "Some Description " + i.ToString()
dr("Address") = "Some Address " + i.ToString()
dt.Rows.Add(dr)
Next
End Sub
Public ReadOnly Property DS() As DataTable
Get
Return dt
End Get
End Property
End Class
Protected Sub btnPopulate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sd As New SampleDataSource()
dgSample.DataSource = sd.DS
dgSample.DataBind()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="dgSample" width="50%" runat="server"></asp:GridView>
<asp:Button ID="btnPopulate" Text="Populate" runat="server" onclick="btnPopulate_Click" />
</div>
</form>
</body>
</html>
I know this might not be helpful to most of you at all since this code doesn't do much by itself. I have certain samples to do, and may be in future, this post will help me and some of my folks here while troubleshooting!
Until next time 
Rahul
Quote of the day: Every hero becomes a bore at last. - Ralph Waldo Emerson