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

on Jul 27, 2018 01:32 AM


 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 : 

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

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

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


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 ?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Jul 27, 2018 02:49 AM
Sumeet says:

Remove the Server.MapPath from url.

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