首次推送
This commit is contained in:
67
Mtxfw.Utility/Error.cs
Normal file
67
Mtxfw.Utility/Error.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Mtxfw.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义异常显示 by Telesa 2011.04.06
|
||||
/// </summary>
|
||||
public class Error
|
||||
{
|
||||
private string _path = System.Web.HttpContext.Current.Server.MapPath("ErrorTemplate.htm");
|
||||
private string isError;
|
||||
private Exception _exc;
|
||||
|
||||
public Error(Exception ex)
|
||||
{
|
||||
//读取Web.Config的设置 true 则开启
|
||||
isError = System.Configuration.ConfigurationManager.AppSettings["Error"];
|
||||
_exc = ex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取自定义异常的页面模板
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string Reader()
|
||||
{
|
||||
string str = string.Empty;
|
||||
try
|
||||
{
|
||||
if (File.Exists(_path))
|
||||
{
|
||||
StreamReader sr = new StreamReader(_path, Encoding.GetEncoding("gb2312"));
|
||||
str = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
sr.Dispose();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
str = ex.Message;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将异常信息写入到自定义页面
|
||||
/// </summary>
|
||||
public void Write()
|
||||
{
|
||||
if (isError.ToLower() == "true")
|
||||
{
|
||||
string str = Reader();
|
||||
if (str!=string.Empty)
|
||||
{
|
||||
str = str.Replace("$Message$", _exc.Message);
|
||||
System.Web.HttpContext.Current.Response.Write(str);
|
||||
System.Web.HttpContext.Current.Response.End();
|
||||
System.Web.HttpContext.Current.Server.ClearError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user