ThomasCookScandinavia
asked on
Request.ServerVariables["HTTP_POST"] throws an exception
Hi Guys,
I've come across an exception thats being recorded by my Log4Net database about once a second in my ASP.NET webapplication. The error generated is:
System.NullReferenceExcept ion: Object reference not set to an instance of an object. at ASP.global_asax.Applicatio n_BeginReq uest(Objec t sender, EventArgs e) in d:\inetpub\wwwroot\mywebsi tename\Glo bal.asax:l ine 37 at System.Web.HttpApplication .SyncEvent ExecutionS tep.System .Web.HttpA pplication .IExecutio nStep.Exec ute() at System.Web.HttpApplication .ExecuteSt ep(IExecut ionStep step, Boolean& completedSynchronously)
In my Global.asax file line 37 reads:
string[] hostParts = Request.ServerVariables["H TTP_HOST"] .Split('.' );
I use this bit of code to get the country domain extension of the url, and then set the UIculture to the correct language.
Isn't the HTTP_POST variable always set in the header of a web request?
I've come across an exception thats being recorded by my Log4Net database about once a second in my ASP.NET webapplication. The error generated is:
System.NullReferenceExcept
In my Global.asax file line 37 reads:
string[] hostParts = Request.ServerVariables["H
I use this bit of code to get the country domain extension of the url, and then set the UIculture to the correct language.
Isn't the HTTP_POST variable always set in the header of a web request?
I would suggest using Request.ServerVariables["S ERVER_NAME "] instead. Has always worked for me in the past.
ASKER
I could try that, but I suspect it would give me the same exception. What do you think coulkd be the problem behind this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh I didn't know that. It's strnge because I can find HTTP_HOST if I get a collection of all ServerVariables. ANyway I'll use SERVER_NAME instead and add some code to test for nulls. Thanks David!