在会话中重定向用户

在会话中重定向用户

本文介绍了在会话中重定向用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户可以填写的表单,然后单击提交按钮将该数据保存到数据库中。同时,提交按钮还将用户重定向回他们的欢迎页面。我有六个不同用户的六个欢迎页面,这些用户可以通过数据库中的用户级别访问。当用户登录该站点时,将根据其级别将其定向到该用户的欢迎页面。然后,用户将进入会话,他们可以在该会话中单击指向不同表单的不同链接,以便他们可以输入数据并将数据提交到数据库中。在会话中,如何让用户回到自己的欢迎页面?我在编写它时遇到了麻烦。



这是带有提交按钮的表单代码:



  protected   void  Page_Load( object  sender,EventArgs e)
{
TextBoxINST_ID.Text = Session [ INST_ID]的ToString();
}
protected void ButtonSubmit_Click( object sender,EventArgs e)
{

SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager。 ConnectionStrings [ DepartConnectionString]。ConnectionString);
con.Open();


SqlCommand cmd = new SqlCommand( 插入表1(INST_ID,TOTAL_REVE,INSTRUCTIO,RESEARCH,PUBLIC_SER,ACADEMIC_S,STUDENT_SE,INSTITUTIO,PHYSICAL_P,SCHOLARSHI,AUXILIARY_,HOSPITALS,INDEPENDEN,OTHEREXP,TOTASSETS,TOTLIABILITY,NoNEXPPERMRESASSETS,EXPENDABLE,UNRNETASSETS,TOTALREV ,TUITFEES,CURRDEBT,LONGTERMDEBT)值(@ INST_ID,@ TOTAL_REVE,@ INSTRUCTIO,@ RESEARCH,@ Public_SER,@ ACADEMIC_S,@ STUDENT_SE,@ INSTITUTIO,@ PHYSICAL_P,@ SCHOLARSHI,@ AUXILIARY_,@ HEALTHPITALS,@ INDEPENDEN,@OTHEREXP ,@ TOTASSETS,@ TOTLIABILITY,@ NoNEXPPERMRESASSETS,@ EXPENDABLE,@ UNRNETASSETS,@ TOTALREV,@ TUITFEES,@ CURRDEBT,@ LongterMDEBT),con);


cmd.CommandType = CommandType.Text;

cmd.Parameters.AddWithValue( @ INST_ID,TextBoxINST_ID.Text );
cmd.Parameters.AddWithValue( @ TOTAL_REVE,TextBoxTROA.Text);
cmd.Parameters.AddWithValue( @ INSTRUCTIO,TextBoxInstr.Text);
cmd.Parameters.AddWithValue( @ RESEARCH,TextBoxRes.Text);
cmd.Parameters.AddWithValue( @ PUBLIC_SER,TextBoxPubS.Text);
cmd.Parameters.AddWithValue( @ ACADEMIC_S,TextBoxAcad.Text);
cmd.Parameters.AddWithValue( @ STUDENT_SE,TextBoxStudS.Text);
cmd.Parameters.AddWithValue( @ INSTITUTIO,TextBoxInstiS.Text);
cmd.Parameters.AddWithValue( @ PHYSICAL_P,TextBoxOperM.Text);
cmd.Parameters.AddWithValue( @ SCHOLARSHI,TextBoxSFEDA.Text);
cmd.Parameters.AddWithValue( @ AUXILIARY _,TextBoxAuxE.Text);
cmd.Parameters.AddWithValue( @ HOSPITALS,TextBoxHosS.Text);
cmd.Parameters.AddWithValue( @ INDEPENDEN,TextBoxIndeO.Text);
cmd.Parameters.AddWithValue( @ OTHEREXP,TextBoxOED.Text);
cmd.Parameters.AddWithValue( @ TOTASSETS,TextBoxTA.Text);
cmd.Parameters.AddWithValue( @ TOTLIABILITY,TextBoxTL.Text);
cmd.Parameters.AddWithValue( @NoNEXPPERMRESASSETS,TextBoxNPRNA.Text);
cmd.Parameters.AddWithValue( @ EXPENDABLE,TextBoxETRNA.Text);
cmd.Parameters.AddWithValue( @ UNRNETASSETS,TextBoxTUNA.Text);
cmd.Parameters.AddWithValue( @ TOTALREV,TextBoxTR.Text);
cmd.Parameters.AddWithValue( @ TUITFEES,TextBoxTFN.Text);
cmd.Parameters.AddWithValue( @ CURRDEBT,TextBoxCD.Text);
cmd.Parameters.AddWithValue( @ LONGTERMDEBT,TextBoxLTD.Text);


cmd.ExecuteNonQuery();
con.Close();
Response.Redirect( Login.aspx);
}
}

这里 代码 登录:

< pre lang = c# >
protected void Button1_Click( object sender,EventArgs e)
{

SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ DepartConnectionString]。ConnectionString);
con.Open();




if true
{
SqlCommand level = new SqlCommand( 从表22中选择accessLevel,Password,INST_ID,其中EmailAddress = @EmailAddress AND Password = @Password,con);
level.Parameters.Add( new SqlParameter( EmailAddress,TextBoxEA.Text));
level.Parameters.Add( new SqlParameter( 密码,TextBoxPW.Text));

SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(读者);

foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1 [ 0 ]。ToString());
int inst_id = Convert.ToInt32(dr1 [ 2 ]。ToString());
会话[ inst_id] = inst_id;

if (returnedLevel == 1
{
Response.Redirect( FormAPublic.aspx);
}
else if (returnedLevel == 2
{
Response.Redirect( FormCPrivateNon.aspx );
}
else if (returnedLevel == 3
{
Response.Redirect( FormDPrivateFor.aspx );
}
else if (returnedLevel == 7
{
Response.Redirect( CEOPage.aspx );
}
else if (returnedLevel == 8
{
Response.Redirect( DBPage.aspx );
}
else if (returnedLevel == 11
{
Response.Redirect( FormAPublicL.aspx );
}
else if (returnedLevel == 21
{
Response.Redirect( FormCPrivateNonL.aspx );
}
else if (returnedLevel == 31
{
Response.Redirect( FormDPrivateForL.aspx );
}

}
解决方案



I have a form that a user can fill out and click submit button to have that data to be saved into the database. At the same time the submit button also Redirects the user back to their welcome page. I have six welcome pages for six different users that are accessed by the user level in the database. When the user logs into the site, depending on their level, will be directed to the welcome page for that user. The user will then be in a Session to where they can click on different links to different forms so they can enter and submit data into the database. While in a Session, how can I get the user back to their own welcome page? I am having trouble on how to write it.

Here is the code for the form with the submit button:

protected void Page_Load(object sender, EventArgs e)
    {
      TextBoxINST_ID.Text = Session["inst_id"].ToString();
    }
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DepartConnectionString"].ConnectionString);
        con.Open();


        SqlCommand cmd = new SqlCommand("Insert into Table1 (INST_ID, TOTAL_REVE, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, EXPENDABLE, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @EXPENDABLE, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)", con);


        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTROA.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
        cmd.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
        cmd.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
        cmd.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
        cmd.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
        cmd.Parameters.AddWithValue("@SCHOLARSHI", TextBoxSFEDA.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
        cmd.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxOED.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);


        cmd.ExecuteNonQuery();
        con.Close();
        Response.Redirect("Login.aspx");
    }
}

Here is the code for the Login:

<pre lang="c#">
protected void Button1_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DepartConnectionString"].ConnectionString);
        con.Open();




        if (true)
        {
            SqlCommand level = new SqlCommand("select accessLevel, Password, INST_ID from Table22 where EmailAddress = @EmailAddress AND Password = @Password", con);
            level.Parameters.Add(new SqlParameter("EmailAddress", TextBoxEA.Text));
            level.Parameters.Add(new SqlParameter("Password", TextBoxPW.Text));

            SqlDataReader reader = level.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);

            foreach (DataRow dr1 in dt1.Rows)
            {
                int returnedLevel = Convert.ToInt32(dr1[0].ToString());
                int inst_id = Convert.ToInt32(dr1[2].ToString());
                Session["inst_id"] = inst_id;

                if (returnedLevel == 1)
                {
                    Response.Redirect("FormAPublic.aspx");
                }
                else if (returnedLevel == 2)
                {
                    Response.Redirect("FormCPrivateNon.aspx");
                }
                else if (returnedLevel == 3)
                {
                    Response.Redirect("FormDPrivateFor.aspx");
                }
                else if (returnedLevel == 7)
                {
                    Response.Redirect("CEOPage.aspx");
                }
                else if (returnedLevel == 8)
                {
                    Response.Redirect("DBPage.aspx");
                }
                else if (returnedLevel == 11)
                {
                    Response.Redirect("FormAPublicL.aspx");
                }
                else if (returnedLevel == 21)
                {
                    Response.Redirect("FormCPrivateNonL.aspx");
                }
                else if (returnedLevel == 31)
                {
                    Response.Redirect("FormDPrivateForL.aspx");
                }

            }
解决方案



这篇关于在会话中重定向用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:29