ASP.NET Accessing Image from saved in folder dynamically under Form Authenticated Application

Last Reply one year ago By pandeyism

Posted one year ago

Sir,

 I have used Form Authentication in my web application. During registration I have saved users photo in folder and name of file in db. Need to display every users profile image after login. I have given permission to access that folder in Web.Config as below : 

<system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/login.aspx" defaultUrl="~/Index.aspx" protection="All" timeout="15"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
    <sessionState mode="InProc" timeout="20"/>
    <customErrors mode="Off" defaultRedirect="~/Error.aspx" redirectMode="ResponseRewrite"/>
  </system.web>
 
    
  <location path="Photo">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>

As you can see I have provided access permission to Photo folder.

During accessing image at bakend I am providing exact location as: 

Server.MapPath("~/Photo/"+dr["Photo"].ToString());

I have checked on browser the path of the called image using Inspect Element property of Chrome, the path is ok as below:

<img src="Photo/user_profile1.jpg" alt="" id="image1" />

 But image is not displaying on page. Why ?

Posted one year ago
Sumeet says:
Server.MapPath("~/Photo/"+dr["Photo"].ToString());

Remove the Server.MapPath from url.

image1.ImageUrl = "~/Photo/" + dr["Photo"].ToString();