日期:2014-05-17  浏览次数:20500 次

为什么不识别这个,命名空间不对吗?
我有多个网页,里面有相同的函数,我想把相同的函数集中写到一个类里面。但是其中的几个函数出现错误,分别在网页里是没有错误的:

  public string getip() //获取客户端ip地址函数
  {
  string ip = "";
  if (Context.Request.ServerVariables["HTTP_VIA"] != null)
  {
  ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();

  }
  else
  {
  ip = Context.Request.ServerVariables["REMOTE_ADDR"].ToString();
  }
  return ip;
  }

这是第一个 编译错误:错误 1 当前上下文中不存在名称“Context”
我的命名空间是:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


第二个问题:tableworks1.Rows[row].Cells[cell].InnerText = "已获得" + getvote(vid) + "票"; 
不认识这个tableworks1,这是我在其中一个网页定义的表的id,如何让类能认识它?

------解决方案--------------------
Context换成
HttpContext.Current
------解决方案--------------------
赞同11楼的,System.Web.HttpContext.Current.Response.