Webmethod using HttpContext returns null reference exception
It is a web method running via .asmx page:
Quick summary:
[WebMethod]
Method Name
{
string Port=HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
if (Port == null || Port == "80" || Port == "443")
{
Port = "";
}
else
{
Port = ":" + Port;
}
}
When i test this method, i get an exception
HttpContext.Current.Request.ServerVariables["SERVER_PORT"] 'System.Web.HttpContext.Current' is null.
What conditions httpcontext will be null?
Why is it failing the method due to null reference开发者_Go百科 exception?
Does these have anything to do with IIS?
精彩评论