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);
处就报错了。当我请求 http://www.frank.com/100.aspx
----------------------------------------------------------------------------
为 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行报错,该如何修改,请指教,谢谢
{
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);
处就报错了。当我请求 http://www.frank.com/100.aspx
----------------------------------------------------------------------------
为 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行报错,该如何修改,请指教,谢谢
解决方案 »
- repeater控件中定义的linkbutton控件怎样用(单击后传递数据至后台)
- 兄弟菜鸟,初次接触WEBGIS,大侠入内
- 通过 Response.Write 能否在一个新的页面输出?
- 文件读取的问题
- 如何处理DetailsView中的两列的对齐问题??
- 关于Session,我的系统是由其他Web程序,用window.open打开的,我将其中url参数放在Session中,立即就丢失了
- 哪个高手哥哥帮我看下 SqlDataReader问题~小妹在线等~
- DropDownList的问题??
- 如何过滤脚本代码?
- c#代码
- asp.net关于后台程序选中了一个treeNode之后,用TreeView.selectNOde()获取到的不是后台程序选中的那个TreeNode的问题
- 请问谁有比较好的完善的后台模板
改为:if(context != null && context.Server != null)
context.Server.Transfer("showinfo.aspx?id=" + id,false);试试。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息: System.Web.HttpException: 为 showinfo.aspx 执行子请求时出错。源错误:行 44: if (context != null && context.Server != null)
行 45: {
行 46: context.Server.Execute("showinfo.aspx?id=" + id, false);
行 47: }
行 48: }还是不行
Regex regex = new Regex(@"^/(\d+?).aspx");
Page page1;
if (regex.IsMatch(url))
{
Match match = regex.Match(url);
string id = match.Groups[1].Value;
if (context != null && context.Server != null)
{
page1 = BuildManager.CreateInstanceFromVirtualPath("/showinfo.aspx", typeof(Page)) as Page;
context.Server.Transfer(page1, false);
}
}
else
{
page1 = BuildManager.CreateInstanceFromVirtualPath(url, typeof(Page)) as Page;
context.Server.Transfer(page1, false);
}