将Common层中 出现的错误在UI层中显示出来

Web开发中由于分层架构开发,Common层和UI层相对独立。通常Common中出现的错误我们保存在服务器的日志里面,一般的用户无法看到。 如果想在页面中显示Common层中出现的错误,那么就可以在Common中的类按如下方式传递错误。其核心是  
System.Web.HttpContext CT=System.Web.HttpContext.Current;
获取当前的请求的Http的HttpContext对象。然后就可以使用Requeset 、Response、 Server对象了







using
System; namespace ContextTest { /// <summary> /// Class1 的摘要说明。 /// </summary> public class Class1 { public Class1() { System.Web.HttpContext CT=System.Web.HttpContext.Current; CT.Response.Write("<input type=\"submit\" name=\"Button2\" value=\"Button\"
id=\"Button2\" onmouseover=\"this.value='免费'\" onmouseout=\"this.value='收费'\" />"
); } } }


已经按 Chainet 提供的方法着色了。谢谢!

posted on 2004-05-11 15:24  吹雪  阅读(1607)  评论(1编辑  收藏  举报

导航