2010-07-06 202 views
3

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

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

在IE和Fiddler中会发生什么? – SLaks 2010-07-06 18:46:42

+0

你在使用IIS7吗? – 2010-07-06 18:49:10

+0

在IE中它永远需要。并没有任何反应.. – Jaspal 2010-07-06 18:53:29

回答

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); 
} 

UPDATE

如果你是积极它不是在你的代码我一个无限循环将遵循this link中的步骤并查看问题是否由Cookie引起。

+0

不,事实并非如此。所有设置正确,如信息 – Jaspal 2010-07-06 18:46:20

+0

中提到的,其实我在登录页面上重定向后,检查用户的主页的凭据 – Jaspal 2010-07-06 18:48:30

+0

嗯,你确定用户通过身份验证? – 2010-07-06 18:49:30

1

您正在重定向到同一页面,导致无限循环。

+0

这也是我的猜测。 – 2010-07-06 19:18:16