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



Will you give this article a +1 ? Thanks in advance




About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "How to determine if your ASP.NET application is running as a 32-bit or 64-bit application"
  1. Jay said...
    October 6, 2009 at 10:33 AM

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

 

Copyright © 2009-2014 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions