How to determine if your ASP.NET application is running as a 32-bit or 64-bit application

When I was first asked this question, I thought to look at the System.IntPtr struct. On further investigation, I found a very simple technique suggested by Perica Zivkovic.

Here’s how to determine if your ASP.NET application is running as a 32-bit or 64-bit application

C#

protected void Page_Load(object sender, EventArgs e)
{
if (IntPtr.Size == 8)
{
Response.Write("Running as a 64-bit app");
}
else if (IntPtr.Size == 4)
{
Response.Write("Running as a 32-bit app");
}

}

VB.NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If IntPtr.Size = 8 Then
Response.Write("Running as a 64-bit app")
ElseIf IntPtr.Size = 4 Then
Response.Write("Running as a 32-bit app")
End If

End Sub

Note: There could be a possibility that you are running a 32-bit .NET Framework on a 64-Bit Windows OS. Check a cool technique described by Raymond How to detect programmatically whether you are running on 64-bit Windows






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

1 comment:

VJ said...

great...
this is the easiest way to detect an environment.