【发布时间】:2015-05-11 05:44:38
【问题描述】:
我有一个从 jQuery Post 方法(工作正常)调用的 aspx 页面(webforms),但是后面代码中的 Response.Redirect 方法不会使用重定向的 URL 重新加载浏览器。然而,它确实点击了 URL。 我很确定这与从 jQuery 调用的页面有关,但不确定为什么会发生这种行为。
protected void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
//lid = Validation.StripToGUID(ObjToGUID(Request.QueryString("lid")))
lid = Validation.StripToGUID(ObjToGUID(Request.Form["lid"]));
string sid = null;
if (lid.Length == 36)
{
//retrieve the link (and product data) from the database
LiveItem_Data.DBConnStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
LiveItem o = new LiveItem();
o = LiveItem_Data.GetLive_ItemFromLID(lid);
if (HTTPStuff.RemoteFileExists(o.product_link))
{
Response.Redirect(o.product_link, true);
}
else
{
//generate an error
}
}
}
}
我单步执行了代码,product_link 正在工作(手动剪切并粘贴到浏览器中),并且正在调用远程页面(我正在测试与另一个具有日志记录的站点的链接)。 然而,浏览器并没有打开(试过 FF、IE、Opera、Chrome)新的 URL。
jQuery 帖子:
$('.popInfoHG').click(function () {
var ListID = $(this).parent().find('[id*=hidlid]').val();
$.post("redir.aspx", { lid: ListID });
});
我验证了 IIS Express 中的 HTTPredirect 功能已打开(来自 Visual Studio 2012)。难倒!
【问题讨论】:
-
你为什么要为
Response.Redirect(o.product_link, true);保留true -
结束响应,但是false也不行。
标签: c# jquery asp.net response.redirect