登录时,不显示上载的图像 [英] On login, uploaded image is not displayed

查看:75
本文介绍了登录时,不显示上载的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库表是用户:

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


Login.cs

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页面代码有问题
这是代码:


UserDetails page code have the problem
this is the code:

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.

推荐答案

Image1.ImageUrl = "~/UserImage/" + dt.Rows[0]["ImageName"].ToString();
您确定此处的图片网址格式正确吗?您是否调试并看到了网址?试图检查位置?

我建议您使用此技巧来确保:解析路径在多文件夹网站中 [
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.


获取页面的渲染HTML并检查图像控件的src.直接在地址栏中输入该图片,以确保该图片可用且可访问.

我喜欢这条线..
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;



我可能会在代码中看到很多问题,包括但不限于SQL注入,将重要数据保存在cookie中等.在继续上述代码之前,请先阅读有关表单身份验证,SQL注入等的信息.



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.




如果您尚未在UserImage文件夹中添加该图像,请先将其添加到其中,然后再次尝试.


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


这篇关于登录时,不显示上载的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆