Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
MY database table is User:
ID                int
Email            primarykey varchar(250)     
Password          varchar(250)
Name              varchar(250)                  
Country           varchar(250)
Gender            varchar(250)
RegisterDate         datetime                   allownulls 
LastLogin            datetime                   allownulls
Description           varchar(50)
ImageName             varchar(1000)

Login.cs
C#
DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        CheckBox chBox = (CheckBox)ctlLogin.FindControl("RememberMe");
        Authenticated = UserAuthenticate(ctlLogin.UserName, ctlLogin.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            if (chBox.Checked == true)
            {
                Response.Cookies["RFriend_Email"].Value = ctlLogin.UserName;
                Response.Cookies["RFriend_PWD"].Value = ctlLogin.Password;
                Response.Cookies["RFriend_UID"].Value = Session["UserId"].ToString();
                Response.Cookies["RFriend_Email"].Expires = DateTime.Now.AddMonths(3);
                Response.Cookies["RFriend_PWD"].Expires = DateTime.Now.AddMonths(3);
                Response.Cookies["RFriend_UID"].Expires = DateTime.Now.AddMonths(3);
            }
            Response.Redirect("UserDetails.aspx?Id=" + Session["UserId"].ToString());
        }
    }
    private bool UserAuthenticate(string UserName, string Password)
    {
        bool boolReturnValue = false;
        //--------------------------------
        //Check UserID From Config File
        if (UserName == "Rahul" && Password == "Saxena")
        {
            boolReturnValue = true;
            return boolReturnValue;
        }
        else
        {
            //--------------------------------
            dt = new DataTable();
            SqlConnection con=new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite8\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
            string chkUser = "Select * FROM [User] where Email='" + UserName + "' AND Password='" + Password + "'";
            dt = dbClass.ConnectDataBaseReturnDT(chkUser);
            if (dt.Rows.Count > 0)
            {
                boolReturnValue = true;
                Session["UserId"] = dt.Rows[0]["Id"].ToString();
                SqlCommand cmd = new SqlCommand("UPDATE [User] SET LastLogon = GETDATE() where Id= @UserId", con);
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@UserId";
                param.Value = Session["UserId"];
                cmd.Parameters.Add(param);
                
            }
            return boolReturnValue;
        }

UserDetails page code have the problem
this is the code:
C#
DataBaseClass dbClass = new DataBaseClass();
  public DataTable dt;
  protected void Page_Load(object sender, EventArgs e)
  {
  }
  public void GetUserDetails(int id)
  {
      string getUserDetail = "Select ID,Email,Name,Country,Convert(varchar (20), RegisterDate, 106) RegisterDate,Convert(varchar (20), LastLogin, 106) LastLogin ,Description,ImageName FROM [User] where Id='" + id + "'";
      dt = dbClass.ConnectDataBaseReturnDT(getUserDetail);
      if (dt.Rows.Count > 0)
      {
         Image1.ImageUrl = "~/UserImage/" + dt.Rows[0]["ImageName"].ToString();
      }

Image is not displayed.
Posted
Updated 23-Mar-11 2:12am
v2
Comments
Mahendra.p25 23-Mar-11 8:17am    
just want to ask have you added that image in your UserImage Folder with the sameImage

Image1.ImageUrl = "~/UserImage/" + dt.Rows[0]["ImageName"].ToString();
Are you sure image url is correctly formed here? Did you debug and see the url? Tried to check the location?

I would suggest you to use this tip to be sure: Resolving Paths in a Multi-Folder WebSite[^]

To me, it looks like relative path issue for now.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Mar-11 10:56am    
Good answer! 5+
Get the rendered HTML of your page and check the src of image control. Make sure that this image is available and accessible by directly entering it in the address bar.

I loved this line..
Response.Cookies["RFriend_PWD"].Value = ctlLogin.Password;


I could see a lot of problems in the code including but not limited to SQL Injection, Saving important data in cookies etc. Please read about Forms authentication, SQL injections etc before continuing with the above code.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Mar-11 10:55am    
Good answer! 5+
hi,

If you have not added that image in your UserImage folder then first add it there and then again try.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900