0

我有一个非常奇怪的问题,我无法弄清楚。我不确定它是怎么发生的。这仅在 IE 10 中发生(尚未尝试其他版本的 IE)。这在 Firefox、Chrome、Opera 或 Safari 中不会发生。当用户 1 登录网站时,他们也可以看到他们所属的商店。如果有 10 家商店并且他们只能访问 4 家,那么他们只会在下拉菜单中看到这 4 家商店。下拉列表是动态的,并从 SQL Server 表中接收值。如果用户 1 注销,他们会被发送到注销页面,该页面会放弃会话,将用户从表单身份验证中注销,然后将他们重定向回登录页面。现在,用户 2 登录。它转到“仪表板”,显示用户 2 已登录。当用户 2 导航到特定页面时,用户 2 用户名变为用户 1' s 用户名,然后用户 2 现在可以看到用户 1 所属的所有商店。离开此页面,将显示用户 2 的信息。导航回该特定页面,用户 1 又回来了。正如我之前所说,我不确定发生了什么。我什至不确定要向您展示什么代码。我会假设如果这是一个编码问题,它会在我的页面加载到那个特定的页面上。这是该网络表单的页面加载。它将在该特定页面上的我的页面加载中。这是该网络表单的页面加载。它将在该特定页面上的我的页面加载中。这是该网络表单的页面加载。

代码背后

protected void Page_Load(object sender, EventArgs e)
    {
        conn.Open();

        //This selects the user's ID where the user name equals the user that is currently logged in. 
        SqlCommand cmdUserID = new SqlCommand("SELECT UserID from Users WHERE UserName = '" + User.Identity.Name + "'", conn);
        selectUserID = Convert.ToString(cmdUserID.ExecuteScalar());

        //Selections the location ID where the userID is equal the the UserName.
        SqlCommand cmdLocationID = new SqlCommand("SELECT LocationID from UserControl WHERE UserID = '" + selectUserID + "'ORDER BY LocationID ASC", conn);
        selectLocationID = Convert.ToString(cmdLocationID.ExecuteScalar());

        //Selects the Coporate or Store where the userID is equal to the UserName.
        SqlCommand cmdCorporateStore = new SqlCommand("SELECT MAX(CorporateStore) from Users WHERE UserID = '" + selectUserID + "'", conn);
        selectCorporateStore = Convert.ToString(cmdCorporateStore.ExecuteScalar());

        //Selects if the user is an Admin.
        SqlCommand cmdAdmin = new SqlCommand("SELECT MAX(Admin) from Users WHERE UserID = '" + selectUserID + "'", conn);
        selectAdmin = Convert.ToString(cmdAdmin.ExecuteScalar());

        conn.Close();

        //use to display "Garage" when an admin logs in.
        if (selectAdmin == "Yes")
        {
            Control allUsers = this.Page.Master.FindControl("login").FindControl("loginview").FindControl("ulmenu").FindControl("allUsers");
            allUsers.Visible = true;
        }

        gvVehicleTEMP.ControlStyle.Font.Size = 8;

        if (!IsPostBack)
        {
            ddlDealershipRec.Items.Clear();
            List<string> locationList = new List<string>();
            List<int> locationIDList = new List<int>();

            conn.Open();

            //used to populate the dropDownList depending who is logged in. 
            using (SqlDataReader reader = cmdLocationID.ExecuteReader())
            {
                while (reader.Read())
                {
                    int locationID = reader.GetInt32(0);
                    locationIDList.Add(locationID);
                }
                conn.Close();
            }

            foreach (int id in locationIDList)
            {
                conn.Open();
                SqlCommand cmdLocation = new SqlCommand("SELECT LocationName FROM Location WHERE LocationID = '" + id + "' ORDER BY LocationName ASC", conn);
                using (SqlDataReader reader = cmdLocation.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string location = reader.GetString(0);
                        locationList.Add(location);
                    }
                    conn.Close();
                }
            }

            foreach (string location in locationList)
            {
                ddlDealershipRec.Items.Add(new ListItem(location));
            }
            if (Session["Search"] != null)
            {
                if (gvVehicleTEMP.Rows.Count == 0)
                {
                    gvVehicleTEMP.Visible = true;
                    gvVehicleBOUNCE.Visible = false;
                    string Search = (string)(Session["Search"]);
                    string Option = (string)(Session["Option"]);
                    string Dealership = (string)(Session["Dealership"]);

                    ddlDealershipRec.SelectedValue = Dealership;
                    ddlSearchOptions.SelectedValue = Option;
                    tbSearch.Text = Search;

                    conn.Open();

                    if (ddlSearchOptions.Text == "Stock #")
                    {
                        DataTable dt = new DataTable();
                        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM VehicleTEMP WHERE (Dealership LIKE  '%" + Dealership + "%') AND StockNumber = '" + Search + "'", conn);
                        da.Fill(dt);
                        gvVehicleTEMP.DataSource = dt;
                        gvVehicleTEMP.DataBind();

                        conn.Close();
                        Session.Clear();

                    }
                    else if (ddlSearchOptions.Text == "Deal #")
                    {

                        DataTable dt = new DataTable();
                        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM VehicleTEMP WHERE (Dealership LIKE  '%" + Dealership + "%') AND FIMAST = '" + Search + "'", conn);
                        da.Fill(dt);
                        gvVehicleTEMP.DataSource = dt;
                        gvVehicleTEMP.DataBind();

                        conn.Close();
                        Session.Clear();
                    }

                    if (selectCorporateStore == "Store")
                    {
                        foreach (GridViewRow row in gvVehicleTEMP.Rows)
                        {
                            gvVehicleTEMP.FooterRow.Visible = false;
                            gvVehicleTEMP.Columns[16].Visible = false;
                            gvVehicleTEMP.Columns[17].Visible = false;
                            gvVehicleTEMP.Columns[20].Visible = false;
                            gvVehicleTEMP.Columns[21].Visible = false;
                            gvVehicleTEMP.Columns[22].Visible = false;
                            gvVehicleTEMP.Columns[23].Visible = false;
                            gvVehicleTEMP.Columns[26].Visible = false;

                            ((TextBox)row.FindControl("tbStockNumber")).Enabled = false;
                            ((DropDownList)row.FindControl("ddlLocation")).Enabled = false;
                            ((TextBox)row.FindControl("tbGrossProfit")).Enabled = false;
                            ((TextBox)row.FindControl("tbReason")).Enabled = false;
                            ((TextBox)row.FindControl("tbFunded")).Enabled = false;
                            ((TextBox)row.FindControl("tbTitled")).Enabled = false;
                        }
                    }
                    else if (selectCorporateStore == "Corporate")
                    {
                        foreach (GridViewRow row in gvVehicleTEMP.Rows)
                        {
                            btnTopUpdate.Visible = true;
                            gvVehicleTEMP.Columns[4].Visible = false;
                            gvVehicleTEMP.FooterRow.Visible = true;
                            ((TextBox)row.FindControl("tbStockNumber")).Enabled = true;
                            ((DropDownList)row.FindControl("ddlLocation")).Enabled = true;
                            ((TextBox)row.FindControl("tbGrossProfit")).Enabled = true;
                            ((TextBox)row.FindControl("tbReason")).Enabled = true;
                            ((TextBox)row.FindControl("tbFunded")).Enabled = true;
                            ((TextBox)row.FindControl("tbTitled")).Enabled = true;
                        }
                    }
                }
            }
        }
    }

page_load 中发生了很多事情,但对我来说一切都很好。我正在通过 FormsAuthentication 使用 AD 身份验证(但我无法使用角色来允许特定用户查看某些信息)。我几乎把它归结为 IE,但该公司使用 IE 作为标准浏览器。有谁知道解决方案,或者看到我做错了什么?我忘了提到这发生在生产服务器和开发服务器上(仅在 IE 中),但在 IE 中的本地机器上调试不会导致问题。IIS 是 Server 2008 上的第 7 版。非常感谢任何建议。如果需要更多信息,请告诉我。

编辑:发生在 IE 9 和 11 上。如果我刷新有问题的页面,它工作正常。不太清楚发生了什么。

4

1 回答 1

1

Internet Explorer 比其他浏览器更频繁地缓存页面,并且很多人都遇到了问题。

即使在 IE8 和较新的 IE 版本之间,缓存也存在差异。此处发布了一种禁用浏览器缓存的方法:IE 8 and client-side caching

//Ie 8 and lower have an issue with the "Cache-Control no-cache" and "Cache-Control store-cache" headers.
//The work around is allowing private caching only but immediately expire it.
if ((Request.Browser.Browser.ToLower() == "ie") && (Request.Browser.MajorVersion < 9))
{
     context.Response.Cache.SetCacheability(HttpCacheability.Private);
     context.Response.Cache.SetMaxAge(TimeSpan.FromMilliseconds(1));
}
else
{
     context.Response.Cache.SetCacheability(HttpCacheability.NoCache);//IE set to not cache
     context.Response.Cache.SetNoStore();//Firefox/Chrome not to cache
     context.Response.Cache.SetExpires(DateTime.UtcNow); //for safe measure expire it immediately
}

如果不支持IE8,可以只用一行

context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
于 2013-11-12T20:08:27.147 回答