C# response.redirect不起作用
当控件到达response.redirect行时,浏览器中会产生以下错误。 response.redirect中的url是正确的。C# response.redirect不起作用,c#,asp.net,C#,Asp.net,当控件到达response.redirect行时,浏览器中会产生以下错误。 response.redirect中的url是正确的。 页面未正确重定向 Firefox检测到服务器正在以一种永远无法完成的方式重定向对此地址的请求 * This problem can sometimes be caused by disabling or refusing to accept cookies. 这是密码 using System; using System.Collections;
页面未正确重定向 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);
}
}
}
可能是因为你正在重定向到一个无止境的循环?为那个错误提供一些信息 如果在这两个页面中有下面这样的代码,则可能会发生这种情况 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);
}
更新
如果您确定这不是代码中的无限循环,我将按照中的步骤查看问题是否由Cookie引起。您正在重定向到同一页面,导致无限循环。不是这样。所有设置都正确,如信息中所述。事实上,我在检查用户主页的凭据后,正在登录页面上重定向。嗯,你确定用户已通过身份验证吗?是,如果凭据正确,则仅控制转到response.Redirect,你能在登录页面上发布页面加载的代码吗?在IE和Fiddler中会发生什么?在IE中,这需要永远。如果你改变了Response.Redirect(StartUpPage),什么也不会发生;to Response.Redirect(“);是否也会发生同样的事情?@Arkain,,,当我更改Response.Redirect(StartUpPage);to Response.Redirect(“)@Jaspal,然后它看起来是这样的,就像其他人所建议的那样,因为出现了一个无限重定向循环。您正在重定向到同一页面。尝试在您重定向到的页面上,以及在其他页面中的任何重定向调用上设置断点。