gpt4 book ai didi

asp.net - 回发时的响应重定向

转载 作者:行者123 更新时间:2023-12-02 17:48:08 24 4
gpt4 key购买 nike

我的代码如下:

protected void Page_Load(object sender, EventArgs e)
{
if(IsPostback)
{
if(/* User is not authenticated to perform any actions on this page */)
{
Response.Redirect(/* Error Page */);
}
}
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
/* do some stuff */
}

我猜想如果我提交按钮进行回发并且我没有经过身份验证,那么在 Page_Load 中将发生重定向并发回 HTTP 302。但是,它似乎运行 Response.Redirect代码行,在 Page_Load 中继续处理它,然后甚至在之后运行 btnSubmit_Click。响应不是错误页面。

我可以在 Response.Redirect 之后调用 return 以防止在该函数中进行进一步处理,但 btnSubmit_Click 函数仍会运行。

为什么会这样?

最佳答案

要防止处理更多代码,请使用:

Response.Redirect(url, true);

第二个参数将结束进一步的处理。

关于asp.net - 回发时的响应重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11976820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com