Hi I have an application which works fine when i run it using visual studio, I am saving employee name , photo and email it works fine and save the file to the directory in my project -->employee Photo Folder , Now when I deploy this application to IIS ( i have checked to put the published folder on DESKTOP as well as in wwwroot
folder as well .
but when saving the record from the deployed application it did not get saved and i am unable to debug as it is deployed as per my understanding server.MAPPATH does not work on iss
below is the code which works fine with visual studio
- if (upload != null && upload.ContentLength > 0 && upload.ContentLength < 41943040)
- {
- var avatar = new File
- {
- FileName = System.IO.Path.GetFileName(upload.FileName),
- FileType = FileType.Avatar,
- ContentType = upload.ContentType
- };
- File fl = new File();
- fl.FileName = System.IO.Path.GetFileName(upload.FileName);
- string pic = System.IO.Path.GetFileName(upload.FileName);
- string path = System.IO.Path.Combine(
- Server.MapPath("~/StudentPhotos/"), pic);
- var allowedExtensions = new[] {
- ".jpg", ".png", ".jpeg", ".gif", ".svg"
- };
-
- if (upload != null)
- {
-
- if (upload.ContentLength > 0)
- {
-
- string ext = System.IO.Path.GetExtension(upload.FileName).ToLower();
-
- if (allowedExtensions.Contains(ext))
- {
-
-
- string name = upload.FileName.ToLower();
-
- string rootpath = "/StudentPhotos/";
-
-
-
- string s = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath(rootpath), name);
-
- upload.SaveAs(s);
- student.Student_photo = "~/StudentPhotos/" + name;
- }
- }
- }
- }
- else
- {
- ModelState.AddModelError("", errorMessage: "you cannot add file having size more than 40 MB ");
- return View();
- }