当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 错误处理
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Web;
using System.Web.Caching;
using System.Collections;
namespace MeetingProxy.MeetingException

{
/**//// <summary>
/// 错误码的描述
/// </summary>
public class ErrProcedure
{
private static Hashtable errMessages = new Hashtable();
public static Hashtable GetErrMessages()
{
if (CommonCache.Get("ErrMessage") as Hashtable == null)
{
string path = null;
HttpContext context = HttpContext.Current;
if (context != null)
path = context.Server.MapPath("~ErrMessage.xml");
else
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrMessage.xml");
XmlDocument xdoc = new XmlDocument();
xdoc.Load(path);
foreach (XmlNode child in xdoc.LastChild)
{
errMessages.Add(int.Parse(child.LastChild.InnerText), child.FirstChild.InnerText);
}
CacheDependency cd = new CacheDependency(path);
CommonCache.Max("ErrMessage", errMessages,cd);
return errMessages;
}
else
{
return CommonCache.Get("ErrMessage") as Hashtable;
}
}


}
}
<?xml version="1.0" encoding="UTF-8"?>
<ErrMessage>
<Err>
<Description>登录会议室错误</Description>
<ErrCode>100</ErrCode>
</Err>
<Err>
<Description>您申请的会议室被别人抢用,会议室创建失败,请重新申请</Description>
<ErrCode>101</ErrCode>
</Err>
<Err>
<Description>必须有端口号</Description>
<ErrCode>200</ErrCode>
</Err>
<Err>
<Description>用户名或者密码错误</Description>
<ErrCode>300</ErrCode>
</Err>
</ErrMessage>

using System;
using System.Collections.Generic;
using System.Text;
namespace MeetingProxy

{
public class MeetingBaseException:ApplicationException
{
int errCode;
public MeetingBaseException(string message, int errCode)
: base(message)
{
this.errCode = errCode;
}
public MeetingBaseException(int errCode)
{
this.errCode = errCode;
}
public int ErrCode
{
get
{ return errCode; }
set
{ this.errCode = value; }
}
}
}
private string VerifySession()
{
string passport = null;
if (HttpContext.Current != null)
{

passport = HttpContext.Current.Session["Username"] as string;
}
if (passport == null)
{
//用户没有通过Session验证
throw new MeetingBaseException(ErrProcedure.GetErrMessages()[301].ToString(), 301);
}
return passport;
}
throw new MeetingBaseException(108);
<data name="R303" xml:space="preserve">
<value>用户名已经存在</value>
</data>
public static string GetErrInfo(int errCode)
{
string resourceKey;
if (errCode >= 0)
{
resourceKey = "R" + errCode.ToString();
}
else
{
errCode = errCode * -1;
resourceKey = "R_" + errCode.ToString();
}
Type t = typeof(Resources.Login);
PropertyInfo pi = t.GetProperty(resourceKey);
return pi.GetValue(null, null).ToString();

}
using System;
using System.Collections.Generic;
using System.Text;
namespace YahooBase.Result

{
/**//// <summary>
/// 普通返回值
/// </summary>
public class SoapResult
{
private int errCode;
public SoapResult()
{ }
public SoapResult(int errCode)
{
this.errCode = errCode;
}
public int ErrCode
{
get
{ return errCode; }
set
{ errCode = value; }
}
}
}


{
try
{
mc.FreeConfrence();
return new SoapResult(0);
}
catch (MeetingBaseException me)
{
return new SoapResult(me.ErrCode);
}
catch (ApplicationException ae)
{
Log4net.log.Error(ae);
return new SoapResult(-500);
}
catch (Exception e)
{
if (e.InnerException != null)
{
Log4net.log.Error(e.InnerException);
}
Log4net.log.Error(e);
return new SoapResult(-500);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace YahooBase.Result

{
/**//// <summary>
/// 查询历史帐单信息
/// </summary>
public class HistoryFeeResult:SoapResult
{
public HistoryFeeResult(int errCode):base(errCode)
{}
public HistoryFeeResult()
{}
public MonthFee[] MonthFeeList;
}
public class MonthFee
{
public string MonthName;
public Category[] CategoryList;
}
public class Category
{
public Category(decimal fee, string name)
{
Fee = fee;
Name = name;
}
public Category()
{ }
public decimal Fee;
public string Name;
}
}
<?xml version="1.0" encoding="utf-8" ?>
- <HistoryFeeResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<ErrCode>0</ErrCode>
- <MonthFeeList>
- <MonthFee>
<MonthName>三月</MonthName>
- <CategoryList>
- <Category>
<Fee>44.6</Fee>
<Name>市话</Name>
 
评论 (0) All