2010-07-06 197 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