当控件到达response.redirect行时,浏览器中将产生以下错误。
response.redirect中的网址正确。
页面未正确重定向

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/

10-16 23:08