MembershipUser currentUser = Membership.GetUser();
//Get Username of Currently logged in user
string username = currentUser.UserName;
//Get UserId of Currently logged in user
string UserId = currentUser.ProviderUserKey.ToString();
|
Here i written much code like from Membership i am getting currently logged in username no need to use MembershipUser event to get currently logged in user we have another simple way to get currently logged in username you just define like this in your page
string userName = Page.User.Identity.Name;
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
Subscribe by RSS
Subscribe by Email
16 comments :
Hi,
Thanks Really Useful information.
This code helps me a lot- "Page.User.Identity.Name;"
It working perfect. Now i can display the current user name on Home page. But i got a small issue....It display whole user email id on home page like Welcome xyz@gmail.com BUt i want to display only XYZ on home page is it possible using this logic? If so, please reply....
Thank you...
-Ajay
@Ajay..
Split your username with @ operator like this
string strData = "suresh@gmail.com";
char[] separator = new char[] { '@' };
string[] strSplitArr = strData.Split(separator);
string username=strSplitArr[0]
After split your username as shown above you will get username
Thanks
Dear Suresh,
Your Blog is very helpful, God Bless.
I request you to please share how we can extract image file from database into crystal report.
Also write detail blog on crystal reports designing and functionality
Thank you
Imtiaz
if the user forget his password then after submitting his email address how the email address authenticated with database and after authentication sends the login details in the email
Do one thing for any user if forgot password ..i am givinu u code...first store the user name or password on database then if any user may forget password then the password will send him via email id.....this code definitely work try it....
...........................
C# code....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPass_Click(object sender, EventArgs e)
{
//Create Connection String And SQL Statement
//string strConnection = ConfigurationManager.ConnectionStrings["goodwillConnectionString"].ConnectionString;
string strSelect = "SELECT UserName,Password FROM Users WHERE Email = @Email";
SqlConnection connection = new SqlConnection("Data Source=ABHISHEK-PC\\SA;Integrated Security=true;Initial Catalog=goodwill");
connection.Open();
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = strSelect;
SqlParameter email = new SqlParameter("@Email", SqlDbType.VarChar, 50);
email.Value = txtEmail.Text.Trim().ToString();
command.Parameters.Add(email);
//Create Dataset to store results and DataAdapter to fill Dataset
DataSet dsPwd = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter(command);
dAdapter.Fill(dsPwd);
connection.Close();
if(dsPwd.Tables[0].Rows.Count > 0 )
{
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(txtEmail.Text.ToString());
loginInfo.From = new MailAddress("id@gmail.com");
loginInfo.Subject = "Forgot Password Information";
loginInfo.Body = "Username: " + dsPwd.Tables[0].Rows[0]["UserName"] + "
Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "
";
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "pwd");
smtp.Send(loginInfo);
lblMessage.Text = "Password is sent to you email id,you can now ";
}
else
{
lblMessage.Text = "Email Address Not Registered";
}
}
Hi, Can you please suggest me ASP-c# snippet to get list of users logged in currently?
Hai Mr.Suresh...
After Successfully Login,how to get the logined username into home page lable.