Avatar of ThomasCookScandinavia
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.NullReferenceException: Object reference not set to an instance of an object.     at ASP.global_asax.Application_BeginRequest(Object sender, EventArgs e) in d:\inetpub\wwwroot\mywebsitename\Global.asax:line 37     at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

In my Global.asax file line 37 reads:
string[] hostParts = Request.ServerVariables["HTTP_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?
ASP.NETHTTP Protocol

Avatar of undefined
Last Comment
ThomasCookScandinavia
Avatar of davidmuto
davidmuto
Flag of Canada image

I would suggest using Request.ServerVariables["SERVER_NAME"] instead. Has always worked for me in the past.
Avatar of ThomasCookScandinavia
ThomasCookScandinavia

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
Avatar of davidmuto
davidmuto
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ThomasCookScandinavia

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!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo