想获取客户端ip地址,使用了下面语句
string _ip = request.ServerVariables.Get("Remote_Addr").ToString().Trim();
但是会提示错误:当前上下文中不存在名称“Request”
其实只需要前面加上 HttpContext.Current. 就可以了,改为
string _ip =HttpContext.Current.Request.ServerVariables.Get("Remote_Addr").ToString().Trim();
或者加上 System.Web.HttpContext.Current
其它:当前上下文中不存在名称"Server"也是同样的道理
HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
string url = System.Web.HttpContext.Current.Server.MapPath("/File/" + gfilename + filenameext);
相关新闻
- 小程序登录流程图理解 2020-08-18
- 在C#中获取web.config中的配置信息 2021-08-23
- 小程序open-data头像样式 2021-04-10
- 小程序rich-text 富文本解析图片过大和图片路径的问题 2020-11-25
- C#中去掉字符串的最后一个字符 2020-11-23