Click here to Skip to main content
15,913,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Currently when page run it go to the common login gateway/page but while running on local host, I want it to pass my user id directly which is registered in DB.


 protected void Page_Load(object sender, EventArgs e)
    {

        DBClass.Manager.DbType = "oracle";
        objDatabase = DBClass.Manager.CreateDatabase(ConfigurationManager.AppSettings["ConnectionString"]);

        bool flag = true;
        try
        {

            //Response.Write(Request.ServerVariables["HTTP_REFERER"].ToString());
            if (Request.ServerVariables["HTTP_REFERER"].ToString().Trim() != "http://realnet.in.ril.com/Realnet/aspx/mypage.aspx")
            {
                flag = false;
            }
            else
            {
                flag = true;
            }
            Response.Write(flag);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
            flag = false;
        }

        if (flag == true)
        {
            string uid = Request.QueryString["uid"].ToString();

            //string uid = "37101621";

            uid = uid.Substring(1, (uid.Length) - 1);

            string str = "select * from m_cmto_users a,m_cmto_roles b where a.user_role_code=b.role_code and user_ecno='" + uid + "' and user_flag='R'";
            DataSet ds = objDatabase.ByText(str);
            if (ds.Tables[0].Rows.Count > 0)
            {
                //Response.Write(ds.Tables[0].Rows.Count);
                string username = ds.Tables[0].Rows[0]["user_name"].ToString();
                string ecno = ds.Tables[0].Rows[0]["user_ecno"].ToString();
                string role = ds.Tables[0].Rows[0]["role_desc"].ToString();

                Session["username"] = username;
                Session["ecno"] = ecno;
                Session["role"] = role;
                Session["role_code"] = ds.Tables[0].Rows[0]["role_code"].ToString();
                Session["SDate"] = System.DateTime.Now.ToString("dd MMM yyyy");
                Response.Redirect("Cmto_Mainpage.aspx"); 
            }
            else
            {
                Response.Redirect("http://realnet.in.ril.com/Realnet/aspx/mypage.aspx");

            }
        }
        else
        {
            Response.Redirect("http://realnet.in.ril.com/Realnet/aspx/mypage.aspx");
        }

    }
}


What I have tried:

I can't find any help just trying to comment the redirecting page.
Posted
Updated 5-Apr-17 21:04pm
Comments
Prifti Constantine 6-Apr-17 2:53am    
You could store the variable inside the Session and then get it from whichever page you would like from.

1 solution

I am not sure about the exact meaning of your question because my english it´s not very good.
But, I suggest you to change the line that says:
//string uid = "37101621";

with
if (Request.IsLocal)
{
  uid = "37101621";
}

so, if the request is local (that is: the request comes from the local server) the uid variable takes the hard-coded value "37101631" instead of the uid parameter of the Request.

I hope this can help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900