登录,用户,网站管理员 [英] Login , User, administrators on a web site

查看:104
本文介绍了登录,用户,网站管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在我的网站上,我正在为想要购买产品的简单用户和他们有其他能力的管理员工作登录。



我为ASP.NET配置和规则设置了管理员帐户。



我创建了一个文件夹Adminpages包含Admin.aspx和web.config文件,它包含

 <?  xml     version   =  1.0   编码  =  utf-8  >  
< 配置 >
< system.web >
< 授权 >
< allow users = 管理员 / >
< deny 用户 = < span class =code-keyword>? / >
< / authorization >
< /system.web>
< / configuration >





In登录页面我创建了以下代码:

 protected void Login1_Authenticate(object sender,AuthenticateEventArgs e)
{
string adm =admin;
string auth = Convert.ToString(Login1.UserName.ToUpper());

if(auth == adm)
{
Response.Redirect(〜/ AdminPages / Admin.aspx);
}
else
{
//认证码
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ConnectionString]。ToString());

string aSQL =从[User]中选择ID_USER,NAME_USER,PASSWORD,其中UPPER(NAME_USER)= @USER和UPPER(PASSWORD)= @ PASS;
try
{
SqlCommand cmd = new SqlCommand(aSQL,con);
cmd.Parameters.Add(@ User,SqlDbType.Char,10,UserName)。Value = Login1.UserName.ToUpper();
cmd.Parameters.Add(@ Pass,SqlDbType.Char,10,PASSWORD)。Value = Login1.Password.ToUpper();
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
//检查数据库名称
dr.Read();
if(dr.HasRows)
{
Session [user] = dr [ID_USER];
Response.Redirect(cart.aspx?ID =+ Request.QueryString [ID] +& quant =+ Request.QueryString [quant]);
}
else
Response.Write(用户或密码无效);

}
最后
{
con.Close();
}
}



当我尝试进入购物车时一切正常但是当我尝试以管理员身份登录时

没有任何反应。



我知道为了在管理员页面中登录工作我必须改变什么?



Thnx提前!

Jason

解决方案

有关如何设置代码的示例,请参阅此文章:



ccilk [ ^ ]

Hi guys,

In my web site I'm working on login for simple users who wants just to buy products and the administartors which they have other abilities .

I setup the account for administrator at ASP.NET configuration and the rules.

I create a folder Adminpages which contains the Admin.aspx and a web.config file which it have

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <authorization>
            <allow users="Administrator" />
          <deny users="?"/>
        </authorization>
    </system.web>
</configuration>



In login page I create the following code:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        string adm = "admin";
        string auth=Convert.ToString(Login1.UserName.ToUpper());
       
        if (auth == adm)
        {
            Response.Redirect("~/AdminPages/Admin.aspx");
        }
        else
        {
            //authentication code
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

            string aSQL = "select ID_USER, NAME_USER, PASSWORD from [User] where UPPER(NAME_USER)= @USER and UPPER(PASSWORD)=@PASS";
            try
            {
                SqlCommand cmd = new SqlCommand(aSQL, con);
                cmd.Parameters.Add("@User", SqlDbType.Char, 10, "UserName").Value = Login1.UserName.ToUpper();
                cmd.Parameters.Add("@Pass", SqlDbType.Char, 10, "PASSWORD").Value = Login1.Password.ToUpper();
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                //check database for names
                dr.Read();
                if (dr.HasRows)
                {
                    Session["user"] = dr["ID_USER"];
                    Response.Redirect("cart.aspx?ID=" + Request.QueryString["ID"] + "&quant=" + Request.QueryString["quant"]);
                }
                else
                    Response.Write("User or password invalid");

            }
            finally
            {
                con.Close();
            }
        }


When I try to enter in shopping cart everything is ok but when i try to login as administrator
nothing happens.

Any idea what i must change in order to work the login in administrator page?

Thnx in advance!
Jason

解决方案

See this article for examples on how to set up your code:

ccilk[^]


这篇关于登录,用户,网站管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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