[英]Admin user not able to login (Role based)
I have a functionality where Super Admin creates user. 我具有Super Admin创建用户的功能。 For Ex: SuperUser creates admin.
例如:SuperUser创建管理员。
Then, I am unable to log in with the Admin details. 然后,我无法使用管理员详细信息登录。 The data of the admin is getting stored in the table.
管理员的数据将存储在表中。 I am sure its role based issue.
我确信它是基于角色的问题。 But I am not getting exactly where it is stucking.
但是我没有确切地了解它所卡住的地方。 Please see the code for your reference:-
请参阅代码以供参考:
Role Define:- 角色定义:-
<div class="form_div">
<div class="normalText3">
<div class="txtlbl">Username:</div>
<div>
<asp:TextBox ID="txtUsername" runat="server" CssClass="form_txtfld"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtUsername" ErrorMessage="*" ></asp:RequiredFieldValidator>
</div>
</div>
<div class="normalText3">
<div class="txtlbl">Password:</div>
<div>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="form_txtfld"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtUsername" ErrorMessage="*" ></asp:RequiredFieldValidator>
</div>
</div>
<div class="normalText3">
<div class="txtlbl"></div>
<div>
<asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="button-form" onclick="btnLogin_Click" />
</div>
</div>
</div>
Code behind for the login data:- 登录数据后面的代码:-
protected void btnLogin_Click(object sender, EventArgs e)
{
String LoginID = txtUsername.Text.Trim().ToLower();
String LoginPassword = txtPassword.Text.Trim();
LoginLogic _LoginLogic = new LoginLogic();
DataSet dsLoginDetails = _LoginLogic.Ds_getLoginDetails(LoginID, LoginPassword);
if (dsLoginDetails.Tables[0].Rows.Count > 0)
{
if (LoginID.ToLower() == "mserm")
{
Session["user"] = LoginID;
Session["role"] = UserRoles.RELATIONSHIPMANAGER;
Session["password"] = LoginPassword;
Response.Redirect("mseLoanApplications.aspx");
}
else if (LoginID.ToLower() == "msebo")
{
Session["user"] = LoginID;
Session["role"] = UserRoles.BUSINESSOFFICER;
Session["password"] = LoginPassword;
Response.Redirect("mseLoanApplications.aspx");
}
else if (LoginID.ToLower() == "mser")
{
Session["user"] = LoginID;
Session["role"] = UserRoles.RISKOFFICER;
Session["password"] = LoginPassword;
Response.Redirect("mseLoanApplications.aspx");
}
else if (LoginID.ToLower() == "fxadmin")
{
Session["user"] = LoginID;
Session["role"] = "fxadmin";
Session["password"] = LoginPassword;
Response.Redirect("rblfileuploader.aspx");
}
else if (LoginID.ToLower() == "mediaadmin")
{
Session["user"] = LoginID;
Session["role"] = "mediaadmin";
Session["password"] = LoginPassword;
Response.Redirect("mediakitadmin.aspx");
}
else if (LoginID.ToLower() == "dropboxadmin")
{
Session["user"] = LoginID;
Session["role"] = "dropboxadmin";
Session["password"] = LoginPassword;
Response.Redirect("dropboxadmin.aspx");
}
else if (LoginID.ToLower() == "careeradmin")
{
Session["user"] = LoginID;
Session["role"] = "careeradmin";
Session["password"] = LoginPassword;
Response.Redirect("CareerJobList.aspx");
}
else if (LoginID.ToLower() == "careersa")
{
Session["user"] = LoginID;
Session["role"] = "careersa";
Session["password"] = LoginPassword;
Response.Redirect("CareerJobList.aspx");
}
else
{
Session["user"] = LoginID;
Session["role"] = "admin";
Session["password"] = LoginPassword;
Response.Redirect("CareerJobList.aspx");
}
}
else
{
String sc = "<Script>alert('Can not Login. Invalid Username or Password')</script>";
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "Ad" + DateTime.Now, sc, false);
}
}
Please help, I tried debugging the code and I was getting null values. 请帮忙,我尝试调试代码,但得到空值。
The following code you provided in your comment for the Ds_getLoginDetails
method: 您在注释中为
Ds_getLoginDetails
方法提供的以下代码:
public class LoginLogic
{
public LoginLogic();
public void ChangePassword(string LoginID, string LoginPassword);
public DataSet Ds_getLoginDetails(string LoginID, string LoginPassword);
}
The Ds_getLoginDetails
method does not return any data and it does not query your database. Ds_getLoginDetails
方法不返回任何数据,也不查询数据库。
You when you initialise a new instance of LoginLogic
and call Ds_getLoginDetails
you are never actually returning an object. 当您初始化
LoginLogic
的新实例并调用Ds_getLoginDetails
您实际上从未返回过任何对象。
Your login details should look something like: 您的登录详细信息应类似于:
public DataSet Ds_getLoginDetails(string LoginID, string LoginPassword)
{
var ds = new DataSet();
using (var conn = new SqlConnection("Your connection string comes here"))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "select * from Users where LoginID=@LoginID and Password=@Password";
cmd.Parameters.AddWithValue("@LoginID", LoginID);
cmd.Parameters.AddWithValue("@Password", LoginPassword);
var adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
}
return ds;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.