开发者

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.
  1. What conditions httpcontext will be null?

  2. Why is it failing the method due to null reference开发者_Go百科 exception?

Does these have anything to do with IIS?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜