页面重定向中断表单身份验证

时间:2019-07-22 20:57:11

标签: javascript c#

通过IIS窗口身份验证登录时,页面使用JavaScript中的window.location.href方法将窗口位置重定向到另一个页面。每次执行window.location.href时,IIS窗口身份验证会将用户注销。为什么?

注意:ASP.NET代码或JavaScript代码均没有编译错误。

ASP.NET代码:

   public void Button_Click(object sender, EventArgs e)
    {
        string redtpath = hdnfldVariable.Value;
        string uid = TextBox1.Text;
        string pass = TextBox2.Text;

        try
        {
            string qry = "select * from wb_schema.ULoginTbl where UserId='" + uid + "' and Passwd='" + pass + "'";
            string connstr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(connstr))
            {

                conn.Open();
                SqlCommand cmd = new SqlCommand(qry, conn);
                SqlDataReader sdr = cmd.ExecuteReader();

                if (sdr.Read())
                {
                    Server.Transfer(redtpath);
                }
                else
                {
                    Label3.Text = "UserId & Password Is not correct Try again..!!";
                }

                cmd.Connection.Close();
                conn.Close();
            }

        }
        catch (Exception ex)
        {
            Response.Write("Exception:login.aspx.cs(" + redtpath + ")=>" + ex.Message);
        }
    }

JavaScript代码:

var matchMedia = window.msMatchMedia || window.MozMatchMedia || window.WebkitMatchMedia || window.matchMedia;

if (typeof (matchMedia) !== 'undefined') {
            window.matchMedia('(orientation: portrait)').addListener(function () {
                if (window.matchMedia('(orientation: portrait)').matches) {
                    window.location.href = "/handheld.aspx";
                } 
                if (window.matchMedia('(orientation: landscape)').matches) {
                    document.open();
                    document.write(rotatemsghtml);
                    document.close();
                }
            });
        }

0 个答案:

没有答案