有区别地展示错误信息
2006-09-14 17:32
218 查看
在asp.net 2.0中,当应用出现错误时,可以向用户展示友好的出错信息,让用户看不到直接的出错信息和出错的位置,以避免敏感的信息泄露。但有时,如果想让开发者在远程能看到具体的详细开发信息的话,则又要分开区别对待,Scott在他的BLOG里教了大家如做了,现总结之(http://weblogs.asp.net/scottgu/default.aspx)
首先,我们在web.config中设置如下
<customErrors mode="RemoteOnly">
<error statusCode="500" redirect="friendlyErrorPage.htm"/>
</customErrors>
这里friendlyErrorPage.htm为一个自定义***的友善页面
,为了能让比如程序员或者其他权限的人能看到比较详细具体的出错信息,则需要在global.asax中的application_error事件中添加如下代码
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
If (Context IsNot Nothing) And (Context.User.IsInRole("Developer")) Then
Dim err As Exception = Server.GetLastError()
Response.Clear()
Response.Write("<h1>" & err.InnerException.Message & "</h1>")
Response.Write("<pre>" & err.ToString & "</pre>")
Server.ClearError()
End If
End Sub
这里,首先判断用户访问的角色,当发现是一个 developer角色时,则用Server.GetLastError()方法得出最新的异常信息并显示出来。
而为了调试方便,可以改用
If (Context IsNot Nothing) And (Context.User.IsInRole("BUILTIN/Administrators")) Then
来进行本机调试也可以看到运行的效果,这里判断只有Administrators用户才能看到具体出错信息
如果要进一步学习如何在asp.net 2.0中实现角色管理,可以参考SCOTT的文章
http://weblogs.asp.net/scottgu/pages/Recipe_3A00_-Implementing-Role_2D00_Based-Security-with-ASP.NET-2.0-using-Windows-Authentication-and-SQL-Server.aspx
http://www.cnblogs.com/jackyrong/archive/2006/08/17/479492.html
首先,我们在web.config中设置如下
<customErrors mode="RemoteOnly">
<error statusCode="500" redirect="friendlyErrorPage.htm"/>
</customErrors>
这里friendlyErrorPage.htm为一个自定义***的友善页面
,为了能让比如程序员或者其他权限的人能看到比较详细具体的出错信息,则需要在global.asax中的application_error事件中添加如下代码
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
If (Context IsNot Nothing) And (Context.User.IsInRole("Developer")) Then
Dim err As Exception = Server.GetLastError()
Response.Clear()
Response.Write("<h1>" & err.InnerException.Message & "</h1>")
Response.Write("<pre>" & err.ToString & "</pre>")
Server.ClearError()
End If
End Sub
这里,首先判断用户访问的角色,当发现是一个 developer角色时,则用Server.GetLastError()方法得出最新的异常信息并显示出来。
而为了调试方便,可以改用
If (Context IsNot Nothing) And (Context.User.IsInRole("BUILTIN/Administrators")) Then
来进行本机调试也可以看到运行的效果,这里判断只有Administrators用户才能看到具体出错信息
如果要进一步学习如何在asp.net 2.0中实现角色管理,可以参考SCOTT的文章
http://weblogs.asp.net/scottgu/pages/Recipe_3A00_-Implementing-Role_2D00_Based-Security-with-ASP.NET-2.0-using-Windows-Authentication-and-SQL-Server.aspx
http://www.cnblogs.com/jackyrong/archive/2006/08/17/479492.html
相关文章推荐
- 有区别地展示错误信息
- 有区别地展示错误信息
- 有区别地展示错误信息
- 有区别地展示错误信息
- Extjs 表单验证后,几种错误信息展示方式
- laravel ajax form的情况下 validator rule (\Validator 对象)展示错误信息
- jquery validator简单使用,微复杂度密码校验,错误信息集中展示
- 要求使用 IIS 6.0 动态内容时 " HTTP 错误 404 - 文件或目录找 " 错误信息
- 区别于windows,Linux下 结构体指针应正确使用,否则易引发错误
- ojdbc6中的错误信息
- 标准库函数perror用法(打印出错误原因信息字符串)
- xcode4 设置调试错误信息小结
- angular 验证===错误信息在div中
- Python自动化之ajax返回表单验证的错误信息和序列化扩展
- mysql-explain 展示的各种信息的解释
- flex与struts 之 将错误信息存入xml
- Turbo C(V2.0)编译错误信息
- C语言错误信息解释:中文
- java.lang.RuntimeException: Unable to start activity ComponentInfo 错误的一些信息
- 分析器错误信息: 发现不明确的匹配。