网站登录用户有两类:管理员(admin)和普通用户(A部门、B部门、C部门……),全部绑定到dropdownlist(admin、A部门、B部门、C部门……)。登录流程:在default.aspx页面通过dropdownlist选定用户,而后输入用户名、密码提交,如果用户选择的是管理员(即:int.Parse(Session["DepartID"].ToString()) == 1)跳转到AdminAddNews.aspx页面,反之如果是其他的普通用户则跳转到AddNews.aspx页面。出现的问题:
在我的机器还有单位的局域网内部调试运行均没问题,但是上传到ISP服务器上就会有如下问题(我的机器、单位服务器以及ISP服务器均使用ASP.NET 2.0.50727):
管理员可以正常登录并跳转到AdminAddNews.aspx,其他的普通用户输入正确用户名和密码登录时,本应跳转到AddNews.aspx,但是有时会直接链接并打开网站主页default.aspx,有时则是白色错误页面,显示“如果仍然无法打开,建议您检查网址是否正确,网络链接设置是否正常。”,地址栏上的链接地址还是default.aspx。
我想用try-catch捕获错误,但是不起作用。请高手赐教!以下是代码:        try
        {            string strConn = System.Configuration.ConfigurationSettings.AppSettings["ConnStr"].ToString();            OleDbConnection myConnection1 = new OleDbConnection(strConn);            myConnection1.Open();            string AccessString = "select  * FROM AdminManage WHERE UserName=  '" + txtUserName.Text.ToString().Trim() + "'" + " and UserPwd='" + txtPwd.Text.ToString().Trim() + "'" + " and DepartID=" + ddlDept.SelectedItem.Value.ToString();            OleDbDataAdapter myCommandlog = new OleDbDataAdapter(AccessString, myConnection1);
            DataSet ds = new DataSet();
            myCommandlog.Fill(ds, "Log");
            //判断用户合法性
            if (ds.Tables["Log"] != null && ds.Tables["Log"].Rows.Count > 0)
            {
                Session["SessionUserName"] = txtUserName.Text.ToString().Trim();
                Session["DepartID"] = ddlDept.SelectedItem.Value.ToString().Trim();                myConnection1.Close();                if (int.Parse(Session["DepartID"].ToString()) == 1)
                {
                    Response.Redirect("AdminAddNews.aspx");
                    return;
                }                else
                {
                    Response.Redirect("AddNews.aspx");  //就是这里跳转不到AddNews.aspx
                    return;
                }            }
            else
            {
                myConnection1.Close();                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('您的用户名或密码错误,\\n请查证后重新登录!');", true);
            }
        }        catch (Exception ee)
        {
            Label5.Text = ee.ToString();      
        }

解决方案 »

  1.   

    没遇到过。。换成输出js试试。又或者你在AddNews.aspx这个页面有什么验证操作而你的session值又丢掉了
      

  2.   

    有时候if/else  会出现其它没有想到的可能你把   if (int.Parse(Session["DepartID"].ToString()) == 1)
                    {
                        Response.Redirect("AdminAddNews.aspx");
                        return;
                    }                else
                    {
                        Response.Redirect("AddNews.aspx");  //就是这里跳转不到AddNews.aspx
                        return;
                    }
    中的if/else条件互换一下或者把else改成else if()直接判断一下再进行尝试
      

  3.   

    你为什么要判断Session直接判断dropdownlist 进行跳转
      

  4.   

    <authentication mode="Forms">
    <forms name="System" path="/" loginUrl="Default.aspx" protection="All" timeout="6600">
    </forms>
    </authentication>
    是不是设置了这个呀?
      

  5.   

    操作超时的问题,你可能设置的连接超时时间太短,而isp的网络环境不好造成连接超时
      

  6.   


    代码都写成这样了,还是不行,太纠结了!                               //判断用户合法性
                if (ds.Tables["Log"] != null && ds.Tables["Log"].Rows.Count > 0)
                {
                        Session["SessionUserName"] = txtUserName.Text.ToString().Trim();
                        Session["DepartID"] = ddlDept.SelectedItem.Value.ToString().Trim();                    myConnection1.Close();                    try
                        {                        if (int.Parse(ddlDept.SelectedItem.Value.ToString().Trim()) == 1)
                            {
                                Response.Redirect("AdminAddNews.aspx");
                                return;
                            }                        if (int.Parse(ddlDept.SelectedItem.Value.ToString().Trim()) > 1)
                            {
                                Response.Redirect("AddNews.aspx");
                                return;
                            }
                                               }                    catch (Exception ee)
                        {                        Label5.Text = ee.ToString();                       }
                }
                else
                {
                    myConnection1.Close();                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "sd", "alert('您的用户名或密码错误,\\n请查证后重新登录!');", true);
                }