51代码网ORACLEMYSQLSQL SERVER其它数据库java/jspasp/asp.netC/C++/VC++APP应用其它语言服务器应用
您现在的位置: 51代码网 >> asp.net >> 文章正文

System.Web.HttpException: 为 showinfo.aspx 执行子请求时出错

更新时间:2012-7-21:  来源:51代码网

public class MyHandler : IHttpHandler
{
public MyHandler()
{
  request = HttpContext.Current.Request;
  response = HttpContext.Current.Response;
}

  #region IHttpHandler 成员

  public bool IsReusable
  {
  get { return true; }
  }

  public HttpRequest request;

  public HttpResponse response;

  public void ProcessRequest(HttpContext context)
  {
  string url = context.Request.RawUrl;
  Regex regex = new Regex(@"^/(\d+?).aspx");
  if (regex.IsMatch(url))
  {
  Match match = regex.Match(url);
  string id = match.Groups[1].Value;
  context.Server.Execute("showinfo.aspx?id=" + id,false);
  }
  else
  {
  context.Response.Redirect(request.Url.ToString());
  }
  }

  #endregion
}

我想实现Url重写功能,照着网上的例子来写的,现在发现在context.Server.Execute("showinfo.aspx?id=" + id,false);
处就报错了。

当我请求
----------------------------------------------------------------------------
 为 showinfo.aspx 执行子请求时出错。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Web.HttpException: 为 showinfo.aspx 执行子请求时出错。

源错误:

行 42: Match match = regex.Match(url);
行 43: string id = match.Groups[1].Value;
行 44: context.Server.Execute("showinfo.aspx?id=" + id,false);
行 45: }
行 46: else
-------------------------------------------------------------------------------
第44行报错,该如何修改,请指教,谢谢

context.Server.Execute("showinfo.aspx?id=" + id,false); 
改为:

C# code
if(context != null && context.Server != null)
    context.Server.Transfer("showinfo.aspx?id=" + id,false);

  • 上一篇文章:
  • 下一篇文章: 没有了
  • 赞助商链接
    推荐文章
  • 此栏目下没有推荐文章
  • {
    设为首页 | 加入收藏 | 友情链接 | 网站地图 | 联系站长 |