如何在不重定向到登录页面的情况下传递我的硬编码ID [英] How can I pass my hard coded id without redirecting to login page

查看:87
本文介绍了如何在不重定向到登录页面的情况下传递我的硬编码ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,当页面运行时,它会进入公共登录网关/页面,但在本地主机上运行时,我希望它直接传递我在DB中注册的用户ID。 


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;
}
其他
{
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其中a.user_role_code = b.role_code和user_ecno ='+ uid +'和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 [ecno] = ecno;
会话[角色] =角色;
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);
}
其他
{
Response.Redirect(http://realnet.in.ril.com/Realnet/aspx/mypage.aspx);

}
}
其他
{
Response.Redirect(http://realnet.in.ril.com/Realnet/aspx/mypage的.aspx);
}

}
}





我尝试过:



我只是试图评论重定向页面时找不到任何帮助。

解决方案

< blockquote>我不确定你的问题的确切含义,因为我的英语不是很好。

但是,我建议你换一行说:

 // string uid =37101621; 



with

 if(Request。 IsLocal)
{
uid =37101621;
}



所以,如果请求是本地的(即:请求来自本地服务器), uid 变量需要硬编码值37101631而不是请求的 uid 参数。



我希望这可以帮到你。

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.

解决方案

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.


这篇关于如何在不重定向到登录页面的情况下传递我的硬编码ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆