<pre lang="C#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
public partial class Loginaspx : System.Web.UI.Page
{
#region DATABASE_MEMBER
DataVariables objDataVar = new DataVariables();
DAL objDAL = new DAL();
LoginCredentials objLoginCred = new LoginCredentials();
LoginDAL objLoginDAL = new LoginDAL();
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindUserType();
}
}
protected void btnCheck_Click1(object sender, EventArgs e)
{ }
/// <summary>
/// Login
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnLogin_Click(object sender, ImageClickEventArgs e)
{
try
{
// error in following control(txtusername etc)
objLoginCred.UserID = txtusername.Text.Trim();
objLoginCred.Password = txtPassword.Text.Trim();
objLoginCred.UserType = ddlUserType.SelectedItem.ToString();
/*Get records on the basis of use credentials*/
objDataVar.dtstEstOff = objLoginDAL.GetLogin(objLoginCred);
/*Check whether Fetched datatable HAS records or NOT */
if (objDataVar.dtstEstOff.Tables[0].Rows.Count > 0)
{
Session["USERID"] = objLoginCred.UserID;
Session["USERTYPE"] = objLoginCred.UserType;
// Roles.CreateRole("members");
// Session["sitemap"] = GetDataSource(objLoginCred.UserType, Server.MapPath("~"));
if(!Roles.RoleExists(objLoginCred.UserType))
{
Roles.CreateRole(objLoginCred.UserType);
Roles.AddUserToRole(objLoginCred.UserID, objLoginCred.UserType);
}
Response.Redirect("~//HomePage.aspx", false);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "Error", "alert('Invalid UserName / Password !')", true);
// Invalid UserName/Password
}
}
catch (Exception ex)
{ }
}
XmlDataSource GetDataSource(string UserRole, string ServerPath)
{
XmlDataSource objData = new XmlDataSource();
objData.XPath = "siteMap/siteMapNode";
switch (UserRole)
{
case "Administrator":
objData.DataFile = ServerPath + @"/web.sitemap";
Roles.AddUserToRole(objLoginCred.UserType, "Administrator");
break;
case "Department":
objData.DataFile = ServerPath + @"/Department.sitemap";
Roles.CreateRole("Department");
Roles.AddUserToRole(objLoginCred.UserType, "Department");
break;
case "Vendor":
objData.DataFile = ServerPath + @"/User.sitemap";
Roles.CreateRole("Vendor");
Roles.AddUserToRole(objLoginCred.UserType, "Vendor");
break;
default:
objData.DataFile = ServerPath + @"/Default.sitemap";
break;
}
objData.DataBind();
return objData;
}
/// <summary>
///
/// </summary>
public void bindUserType()
{
// error in following control(ddlusertype)
objDataVar.dtstEstOff = objLoginDAL.GetUserType();
// objDataVar.dtblEstOff= objDataVar.dtstEstOff.Tables[0];
ddlUserType.DataSource = objDataVar.dtstEstOff.Tables[0];
ddlUserType.DataTextField = "UserType";
ddlUserType.DataValueField = "UserType";
ddlUserType.DataBind();
}
}</pre>
//here is my current design page
<pre lang="ASP.NET">&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Master/SiteMain.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Loginaspx" %&gt;
&lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %&gt;
&lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"&gt;
&lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt;
<br />
&lt;!--googleon: index--&gt;
<table height="410px" id="loginContainer" style="background-image: removed('Images/login-box-backg.png');&lt;br mode=" hold=" /&gt; clip: rect(50px, auto, auto, auto);">
<tr>
<td class="main" align="center" valign="top">
<table style="margin: 35px 0px 0px 0px; width: 415px;">
<tr>
<td style="margin: 50px;" class="heading">
&lt;asp:Image runat="server" ID="imgLogo" ImageUrl="~/Images/IISc_logo_mncf_32.png" /&gt;
&lt;asp:Label ID="label1" runat="server" Text="Login"&gt;
</td>
</tr>
<tr>
<td align="center" class="UserType">
<table>
<tr>
<td>
&lt;asp:Image ID="Image2" runat="server" ImageUrl="~/Images/user_cut.png" /&gt;
</td>
<td>
&lt;asp:Label ID="labelUserType" runat="server" Text="User Type" Font-Bold="True"&gt;
</td>
<td>
&nbsp;
</td>
<td>
&lt;asp:DropDownList ID="ddlUserType" runat="server"&gt;
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" colspan="2" class="vldEmail vldEmailLength vldMand">
&lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter user name!"
ControlToValidate="txtUserName" Font-Size="9pt" ForeColor="#FF9900" ValidationGroup="Login"&gt;*
&lt;label for="EmailLogin" class="Hidden"&gt;
&lt;/label&gt;
&lt;asp:TextBox ID="txtusername" TabIndex="1" runat="server" ForeColor="#96CDE0" &gt;
&lt;%-- <br />
<span style="color: #EBEBEB">(e.g.
[email protected]</span>--%&gt;
</td>
</tr>
<tr>
<td align="left" colspan="2" class="vldEmail vldEmailLength vldMand">
&lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter valid password!"
ControlToValidate="txtPassword" ForeColor="#FF9900" ValidationGroup="Login"&gt;*
&lt;label for="PassLogin" class="Hidden"&gt;
&lt;/label&gt;
&lt;asp:TextBox ID="txtPassword" TabIndex="1" runat="server" ForeColor="#96CDE0"
TextMode="Password"&gt;
</td>
</tr>
<tr>
<td colspan="2" align="left">
<table>
<tr>
<td valign="top" align="left" class="fieldUserMessage email msg">
&lt;asp:Image runat="server" ID="Image1" ImageUrl="~/Images/information_icon_20.png" /&gt;
</td>
<td>
&lt;asp:LinkButton ID="lbtnForgotPassword" runat="server" Text="Forgot password" TabIndex="1"
Style="color: #99d4e8; font-weight: bold; text-decoration: underline; font-size: 10pt;"
Font-Bold="True"&gt;
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<br />
</td>
</tr>
&lt;%-- <tr>
<td align="left">
&lt;asp:CheckBox ID="cbRememberMe" runat="server" Checked="true" Text="Remember me"
ForeColor="#41a5c6" Font-Size="5pt" TabIndex="1" /&gt;
</td>
</tr>--%&gt;
<tr>
<td colspan="2">
&lt;asp:ImageButton ID="btnLogin" runat="server" ImageUrl="~/Images/login_button.png"
TabIndex="1" BackColor="#214682" ValidationGroup="Login" OnClick="btnLogin_Click" /&gt;
&lt;asp:ValidationSummary ID="ValidationSummary1" runat="server" BackColor="#3C6AAA"
ShowMessageBox="True" ShowSummary="False" ValidationGroup="Login" /&gt;
</td>
</tr>
</table>
</td>
</tr>
</table></pre>