在类中如何使用 Server.MapPath
来源:互联网 发布:java层次遍历二叉树 编辑:程序博客网 时间:2024/05/01 14:18
直接在类中使用 Server.MapPath 会出现错误,这是由于类中不能直接使用 System.Web.UI.Page 的非静态函数造成的。解决方法有两种:
方法一、为类增加继承
class CFoo : System.Web.UI.Page
方法二、利用上下文直接使用
System.Web.HttpContext.Current.Server.MapPath
在使用方法一时请注意:C#中,派生类只能从一个类中继承。
方法二中,System.Web.HttpContext.Current 中 System.Web 是名称空间,HttpContext.Current 是类,HttpContext 封装有关个别 HTTP 请求的所有 HTTP 特定的信息,Current 表示当前 HTTP 请求。
如果我们引入名称空间 System.Web 了,则可以省略为 HttpContext.Current.Server.MapPath。
其实这里并不是只限于 Server.MapPath,还可以这样使用 Server 类的其它属性与方法,比如:Server.HtmlEncode(注意大小写)。
- 在类中如何使用 Server.MapPath
- 类中如何引用server.MapPath()
- 类中如何引用server.MapPath()
- 类中如何引用server.MapPath()
- 类中无法使用Server.MapPath()功能~
- 类中无法使用Server.MapPath()功能~
- .net 如何在.ashx,.cs文件使用server.mappath解决方法
- C#在类中使用Server.MapPath()及在winform中对字符串进行编码
- ASP.NET在类中引用Application和Server.MapPath
- C# 在类库文件无法使用Server.MapPath解决方法
- ASP.NET中Server.MapPath() 和Request.MapPath()使用
- ASP.NET中Server.MapPath() 和Request.MapPath()使用
- asp.net中Server.MapPath的使用
- 实体类cs中调用server.MapPath()
- Server.MapPath的使用
- Server.MapPath使用
- Server.MapPath()使用注意事项
- Server.MapPath() 在Application_Start使用有时候出现错误(Server.MapPath() 探究)
- 让电脑对病毒免疫(自娱自乐!仅供参考!)
- mini2440 clock学习
- 相对路径
- Java异常类总结
- 2010移动开发者大会系列报道:在App Store日进斗金的推广秘诀
- 在类中如何使用 Server.MapPath
- 超链接去掉边框和下划线
- 安全之美(英文影印版)
- enum枚举型变量的使用
- 一个使用JS提交表单并传递参数的问题
- Opencore介绍
- CSS开头空两格
- 网站黑白
- WinForm下载