try
{
String a="3";
Response.Redirect("B.aspx");
}
catch (Exception)
{
Response.Redirect("A.aspx");
}
以前没有注意,上面的代码为什么“Response.Redirect("A.aspx");”总会执行,如果不是 Response.Redirect的话,其它操作则不会。
解决方案 »
- javascript 静态页面可以获取数据库的数据吗?
- 如何获取datagrid滚动后在界面显示最顶端的是第几行?
- asp.net C#可以短信群发功能吗
- 焦头烂额得出来的经验:关于结构体复制 —与菜鸟们分享!
- 请问怎么反射到 this[key] ?
- 求解释
- Infragistics2.WebUI.UltraWebTab.v7.2.dll控件调不出来
- ※※※紧急求助:XML文件及其查询问题※※※
- [技术讨论],什么样的窗体能继承?
- 菜鸟问题:如何直接调用 Windows 的 IE 组件,(我想写 浏览器 软件)
- 在iis中能浏览 但在浏览器中http://locathost/却打不开
- 请教:我的vs2008里怎么没有启用了Ajax的WCF服务?
加了False是可以了。不加为什么还会执行“Response.Redirect("A.aspx");”呢?
把这个异常的ex错误信息输出来看一下就知道问题出在哪里了
Response.Write("Hello world!");
Response.flash();
Response.Redirect()--exception
你跟一下,就明白了
System.Threading.ThreadAbortException: 正在中止线程。
在 System.Threading.Thread.AbortInternal()
在 System.Threading.Thread.Abort(Object stateInfo)
在 System.Web.HttpResponse.End()
在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
在 System.Web.HttpResponse.Redirect(String url)我的代码是try
{
String id="";
if (new PostService().Proc_newPost(user.ID, this.txtTitle.Text.Trim(), this.txtContent.Value, this.ddlPlate.SelectedValue, ref id)>0)
{
Response.Redirect("B.aspx?ID=" + id);
}
}
catch (Exception er)
{
string error= er.ToString();
Response.Redirect("A.aspx");
}
Response.Redirect("B.aspx?ID=" + id);加了Flase参数就可以了。我不明白的是Response.Redirect("B.aspx?ID=" + id);在这里为什么会引发异常?
把代码弄详细点
上面的代码已经是全部代码了?执行一个存储过程,得到一个ID,再跳转。跟那个存储过程里面没有关系。你测试一下,什么也不做 try
{ Response.Redirect("B.aspx");
}
catch (Exception)
{
Response.Redirect("A.aspx");
}
我是一个Button触发的,也会有错误的。
报的是这个错误
System.Threading.ThreadAbortException: 正在中止线程。
在 System.Threading.Thread.AbortInternal()
在 System.Threading.Thread.Abort(Object stateInfo)
在 System.Web.HttpResponse.End()
在 System.Web.HttpResponse.Redirect(String url, Boolean endResponse)
在 System.Web.HttpResponse.Redirect(String url)
try
{
redirectPath = "B.aspx";
}
catch
{
redirectPath = "A.aspx";
} Response.Redirect(redirectPath);
只是为什么Response.Redirect会引发异常,其它操作则不会。
Random ran = new Random();
if (ran.Next(1000) % 2 == 0)
{
Response.Redirect("A.aspx");
}
else
{
Response.Redirect("B.apsx");
}
这样并不会有任何错误,猜想是应该之前的Response.Redirect在Catch块中,而编译器编译后会有两个代码块进行Response.Redirect的操作,具体的原因只有微软的人才能说的清楚了,也说不定是一个bug哦!呵呵