使用httpModules时的一个问题,非常急!在线等!
我写了一个httpModules处理程序,实现功能是对错误代码进行处理,并转到错误页面显示友好的错误信息。我的两个主要方法如下:
public void Init(HttpApplication application)
{
application.PostRequestHandlerExecute += new EventHandler(application_PostRequest);
}
private void application_PostRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpRequest request = application.Request;
string applicationPath = request.ApplicationPath;
string ss = request.Url.Query;
System.Uri uri = request.Url;
if (request.Url.AbsolutePath == applicationPath + "/" + AppControl.ERROR_PAGE && !uri.Query.StartsWith("?ErrorMsg="))
{
string expClass = "";
ErrorException errExp;
object objException = application.Request.Params["Class"];
object objError = request.Params["ErrorCode"];
if (objException != null)
{
expClass = objException.ToString();
errExp = (ErrorException)(application.Context.Application["ErrorException"]);
application.Response.Redirect("ErrorPage.aspx?ErrorMsg=" + errExp.GetMessage("Exception", expClass));
return;
}
if (objError != null)
{
expClass = objError.ToString();
errExp = (ErrorException)(application.Context.Application["ErrorException"]);
application.Response.Redirect("ErrorPage.aspx?ErrorMsg=" + errExp.GetMessage("Error", expClass));
return;
}
errExp = (ErrorException)(application.Context.Application["ErrorException"]);
application.Response.Redirect("ErrorPage.aspx?ErrorMsg=" + errExp.GetMessage("Exception", expClass));
}
我遇到的问题是:在vs.net2003开发环境下运行时,提交一个错误代码能够返回正确的错误信息。而直接访问IIS中的页面时,却没有正确的错误信息返回,不知道是什么原因?