C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




how to capture UserRole thru session


Posted Date: 05 Sep 2008      Total Responses: 2

Posted By: samir dutta       Member Level: Gold     Points: 1


My Developer Friends

with my databsae i have 3 field username, userpass, userrole
when user will login with username and userpass; I would like to store Session["userrole"] so that I can check from master page coding.

Actually my master page is having some Role checks (Admin or User). Based on Admin or User am populating treeview

pls help how to capture UserRole thru session. am attaching my coding for your ready ref

private bool ValidateLogin(string strUserName, string strPassword)
{
bool blnValidLogin = false;
SqlDataReader sqlDr = null;

SqlConnection sqlConn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
string strSQL = "Select username, userpass, userrole From login Where username = '" + strUserName + "' And userpass = '" + strPassword + "'";

try
{
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand(strSQL, sqlConn);
sqlDr = sqlCmd.ExecuteReader();

if (sqlDr.HasRows)
{

blnValidLogin = true;
Session["LoggedIn"] = "LoggedIn";

//string role = (string)sqlDr[2];
//Session["userrole"] = "admin";
}
return blnValidLogin;
}
catch (SqlException ex)
{
ctrlLogin.FailureText = ex.Message;
return false;
}
finally
{
sqlConn.Close();
}
}





Responses

Author: Kumar    05 Sep 2008Member Level: SilverRating:     Points: 2
Might be useful for starter,
http://forums.asp.net/p/1220870/2177702.aspx


Author: samir dutta    05 Sep 2008Member Level: GoldRating:     Points: 2
hi friends

Can anyone solve my problem?
I want to know how can i store UserRole into session variable from the following sql query when am making login

pls help


Post Reply
You must Sign In to post a response.
Next : gridview
Previous : How to update data of grid on perious page,on closing the pop up window
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

conference calls

Contact Us    Privacy Policy    Terms Of Use