Company

Our Services

Our Clients

Articles

Querying Server Variables Affects Performance

Published on: 30 August 2007 By: Ahsan Khan

Querying the ServerVariables Collection Affects Performance. A lot of useful information can be accessed by using ServerVariables but when ServerVariables are called, IIS builds a collection of data and it costs system resources. Values of some ServerVariables do not vary frequently. In case when data like LOCAL_ADDR, PATH_INFO, or SERVER_PORT is requried, it is perferred to use constants in your application and keep this data in constant strings.

For example:
strUrl = "http://" & Request.ServerVariables("LOCAL_ADDR") & ":" & Request.ServerVariables("SERVER_PORT") & Request.ServerVariables ("PATH_INFO")

If the above data is required to build a URL, then other means of keeping this data should be considered instead of calling the ServerVariables on every webpage. You may keep this information in your SQL Database or in an Application variable in the Application_OnStart procedure in Global.asa.

Its worth noting that when a request is made to the server to collect a single server variable IIS builds a collection of all the Environment Variables and not just the one that was requested. Request to the ServerVariables is compromising the performance of the server and the website/web application.

Links related to this article:
IIS/ASP.NET ServerVariables Collection List


underline

View All Articles (Articles Archive)

 

Chapter Zero Limited, 2 Providence Court, Pynes Hill, Exeter, UK, EX2 5JL
Tel: +44 (0)1392 361500, Fax: +44 (0)1392 361501