当控件到达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);
}
}
}
答案 0 :(得分:2)
难道你正在重定向到无限循环吗? 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造成的。
答案 1 :(得分:1)
您正在重定向到同一页面,导致无限循环。