gpt4 book ai didi

c# - response.redirect 不起作用

转载 作者:行者123 更新时间:2023-11-30 16:33:28 25 4
gpt4 key购买 nike

当控件到达 response.redirect 行时,浏览器中会产生以下错误。response.redirect 中的 url 是正确的。
页面没有正确重定向

Firefox 检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求。

*   This problem can sometimes be caused by disabling or refusing to accept
cookies.

这是代码

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void imgbtnLogin_Click(object sender, ImageClickEventArgs e)
{
UserFunction objUser = new UserFunction();
UserProperties objUserProperties = new UserProperties();
IUserFunction iUserFunction = (IUserFunction)objUser;
objUserProperties.UserName = txtUserName.Text;
objUserProperties.Password = txtPassword.Text;
string userName = txtUserName.Text; ;
string password = txtPassword.Text; ;
DateTime login = DateTime.Now;
DateTime? logout = null;
int UserId;
string StartUpPage;
bool success = iUserFunction.ValidateUser(objUserProperties, out StartUpPage);
if (success)
{
Session["UserId"] = objUserProperties.UserId;
Session["RoleId"] = objUserProperties.RoleId;
Session["UserName"] = objUserProperties.UserName;
Session["MyTheme"] = objUserProperties.Theme;
iUserFunction.AddLoginHistory(objUserProperties.UserId, login, logout, 1);
Response.Redirect(StartUpPage);

}
else
{
Label1.Text = "Wrong UserName/password.";
//ScriptManager.RegisterStartupScript(this, this.GetType(), "ClientScript", "alert('Invalid Credential');", true);
}
}
}

最佳答案

难道你正在重定向到一个无限循环? Here is a link到该错误的一些信息。

如果您为这两个页面编写了如下代码,则可能会发生这种情况。

Page1.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect(Page2Url);
}

Page2.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect(Page1Url);
}

更新

如果您确定这不是代码中的无限循环,我将按照 this link 中的步骤进行操作并查看问题是否是由 cookie 引起的。

关于c# - response.redirect 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3189198/

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