I am using microsoft visual studio to build and publish my site. I was able to publish via ftp to my host godaddy.
My site worked fine locally till I published to the web.
Im getting this error when trying to up load a photo. Do I need to set the folder to read write execute?
Server Error in ‘/’ Application.
Access to the path ‘D:\Hosting\8722453\html\Pictures\1bd71b0f-bd55-48a7-9368-2e8faadf5830.jpg’ is denied.
I believe the proble is on this code block.
if (FileUpload1.HasFile)
try
{
var FileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
//FileUpload1.PostedFile.ContentType ==
if (FileUpload1.PostedFile.ContentType.ToLower() == "image/jpg" ||
FileUpload1.PostedFile.ContentType.ToLower() == "image/jpeg" ||
FileUpload1.PostedFile.ContentType.ToLower() == "image/pjpeg" ||
FileUpload1.PostedFile.ContentType.ToLower() == "image/gif" ||
FileUpload1.PostedFile.ContentType.ToLower() == "image/x-png" ||
FileUpload1.PostedFile.ContentType.ToLower() == "image/png")
{
var Myguid = Guid.NewGuid().ToString("N");
var newName = Guid.NewGuid() + FileExtension;
//Map path to folder
string realpath = Server.MapPath("Pictures\\") + newName;
//Where jays converter will store the new image.
string temppath = Server.MapPath("Pictures\\");
string newpath = Server.MapPath("Images\\");
FileUpload1.SaveAs(realpath);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
InsertMembers insert = new InsertMembers();
int age = Int32.Parse(txtAge.Text);
insert.InsertNewMember(txtEmail.Text, Myguid, txtName.Text, txtCity.Text, txtState.Text, txtDescription.Text, age, gender);
//Get Member Id to Insert into Pictures table
GetMemberInfo GetID = new GetMemberInfo();
int UMemberId = GetID.GetMemberId(Myguid);
Displayme.Text = newName.ToString();
//Now that i have member Id Lets insert new picture into picture table
Picture InsertnewPictures = new Picture();
int insertpics = InsertnewPictures.InserNewPicture(UMemberId, newName, 0);
PhotoUtils.JpegConvertor mynewvar = new PhotoUtils.JpegConvertor(temppath, newpath, newName, 300, 400, false);
//PhotoUtils.JpegConvertor mynewvare = new PhotoUtils.JpegConvertor()
}
else
{
Displayme.Text = "You can only upload jpg's png's or bmp images.";
}
}
catch (Exception ex)
{
//Handle the error
throw ex;
}
are the pictures and images directory within the virtual directory? if not this is one problem. the next thing to check is that users can read and write to those directories. something else to note is that if enough files are changed within a given period of time the IIS process will restart the website (or app pool, i’m not sure which one, of if they are one in the same).
This may be configurable in IIS, but I’m not sure. I would try to limit the number of file writes as much as possible and work with the images in memory, only writing the final result to disk. another option is to store the images in a database. removing the need to read/write files under the virtual directory.