通过asp.net中的指定登录 [英] login through designation in asp.net

查看:109
本文介绍了通过asp.net中的指定登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个登录类型,一个是simpleuser,另一个是admin ...一个管理员是默认管理员,他创建其他管理员的帐户,他也分配设计和部门



登录代码



i have a two login types one is simpleuser and other is admin ...one admin is default admin he create accounts of other admins and he assign desginations and departments also

login code

if (users == 1)
                {
                    Session["Login2"] = txt_username.Value;
                    Session["Login3"] = txt_pass.Value;

                    Session["UserTypeID"] = users;

                    Response.Redirect("AdminOp.aspx");
                }
                else if (users == 2)
                {

                    Session["Login2"] = txt_username.Value;
                    Session["Login3"] = txt_pass.Value;


                    Session["UserTypeID"] = users;

                    Response.Redirect("upload.aspx");
                }
            }           
        catch
        {
            Label8.Text = "Incorrect User Name or Password";
        }
    } 





1是管理员,2是用户当supervsior登录他们的帐户然后他看到菜单里面有这样的选项这是adminOp.aspx





1 is admin and 2 is user when supervsior is login to their account then he see menu where there is a options like this this is adminOp.aspx

View Documents

            </span>
        </a>
    </li>
    <li>
        <a href="SuperVisor.aspx">
            <span>

                Approve Documents

            </span>
        </a>
    </li>







现在当经理登录时,他们如何访问他们的页面并能够看到他们的菜单,因为在上面的选项中只有主管......怎么做才是经理?




now when manager is login then how they access their page and able to see their menu because in above options there is only supervisor ...what about done this is manager?

推荐答案

此代码不可读。创建角色列表,并通过连接表将用户分配给角色。使枚举成为一个字段,并将其存储在会话中。让'1是经理'是一个神秘的规则,使您的代码难以维护。不要在会话中存储用户名和密码,为什么要这样做?使用switch代替if / then / else,理想情况下打开方法调用,这样你的代码就是可读的。喜欢这个



This code is not readable. Create a list of roles, and assign users to roles via a joining table. Make the enum a bit field, and store that in the session. Having '1 is managers' is an arcane rule that makes your code hard to maintain. Don't store the username and password in the session, why would you do that ? Use switch instead of if/then/else, and ideally switch on method calls, so your code is readable. Like this

switch(userType)
{
  case User.Admin:
     LoginAdmin(username, password);
     break;
  case User.Basic:
      LoginBasicUser(username, password);
      break;
}


这篇关于通过asp.net中的指定登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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