c# - How do I save image in database in published application using C # in mvc -


i upload company logo in application,it's working when publish , check getting error

here post method of image

[httppost]  public string logo()  {      webimage photo = null;      var imagepath = "";      photo = webimage.getimagefromrequest();       string tempname = "";      if (photo.filename.contains("\\"))      {          tempname = photo.filename.substring((photo.filename.lastindexof("\\") + 1), (photo.filename.length - (photo.filename.lastindexof("\\") + 1)));      }      else      {          tempname = photo.filename;      }      string fname = tempname;      imagepath = server.mappath("~/content/temp/") + fname;      photo.resize(photo.width, 300, true);      photo.save(imagepath);      return "<img src='/content/temp/" + fname + "'  class='preview' id='targetimage' >";  } 

i getting error system.unauthorizedaccessexception: access path 'c:\inetpub\wwwroot\scl mngmnt test link_08_feb\content\temp\desert.jpg' denied

publish somewhere else except c drive (that have permission)

better define global variable in web config hold path want save image .

that how able change path anytime want.

here how can set in web.config

<appsettings>      <add key="imagepath" value="yourimagesavingpath"/>   </appsettings> 

then retrieve using

 path=system.configuration.configurationmanager.appsettings["imagepath"]; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -