PDA

View Full Version : سوال: یه کمک کوچیک در مورد اپلود عکس میتونه خیلی کمکم کنه



meysamdalipour
پنج شنبه 29 دی 1390, 15:29 عصر
سلام دوستان
من یه مشکلی برای آپلود عکس دارم و اون اینه که :
من عکس رو آپلود می کنم و در لوکال هاست یعنی قبل از آپلود درست کار می کنه
اما بعد اینکه آپلود کردم درست کار نمی کنه و پیام عجیب و غریبی می ده .
دستوری که من نوشتم اینه :


protected void Button1_Click1(object sender, EventArgs e)
{
if (Label3.Text == "")
Label1.Text = "بعد انتخاب عکس باید دکمه تایید را بزنید در غیر اینصورت عکس آپلود نمی شود";
else

{
objconnection = new SqlConnection(constr);
objcommand = new SqlCommand();
objcommand.Connection = objconnection;
objcommand.CommandText = "";
objcommand.CommandText = "INSERT INTO gallery" +
"(path,name)" +
"VALUES(@path,@name)";
objcommand.Parameters.AddWithValue("@path", "./galery\\" + Label3.Text);
objcommand.Parameters.AddWithValue("@name", TextBox1.Text);
objconnection.Open();
objcommand.ExecuteNonQuery();
objconnection.Close();
Label1.Text = "عکس با موفقیت ذخیره شد";
TextBox1.Text = "";
Image1.Visible = false;
}

}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
Image1.Visible = true;
Random rand = new Random();
Label3.Text = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("./galery\\" + Label3.Text));
Image1.ImageUrl = ("./galery\\" + Label3.Text);

}
اما پیام اروری که می ده اینه :
Access to the path 'C:\inetpub\vhosts\sahad.ir\httpdocs \ym7siz2tvb.jpg' is denied.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\vhosts\sahad.ir\httpdocs\ym7siz2tvb.jp g' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:


Line 48: Image1.Visible = true; Line 49: Label3.Text = FileUpload1.FileName; Line 50: FileUpload1.SaveAs(Server.MapPath("~/"+ Label3.Text));Line 51: Image1.ImageUrl = ("~/"+ Label3.Text);Line 52:

لطفا کمک کنید

behrouz110
پنج شنبه 29 دی 1390, 16:24 عصر
سلام از اين كد استفاده كن ضمن اينكه توي هاستت پوشه ايي كه ميخواي عكس رو وش بريزي پرميشنش رو قول كن

Dim pic1 As String = FileUpload1.PostedFile.FileName.Substring(FileUplo ad1.PostedFile.FileName.LastIndexOf("\") + 1)
name = Now.Year.ToString + Now.Month.ToString + Now.Day.ToString + Now.Hour.ToString + Now.Second.ToString + Now.Minute.ToString + Now.Millisecond.ToString + Path.GetExtension(FileUpload1.PostedFile.FileName)
FileUpload1.SaveAs(Server.MapPath("~\pic\") & name)

meysamdalipour
پنج شنبه 29 دی 1390, 17:44 عصر
سلام از اين كد استفاده كن ضمن اينكه توي هاستت پوشه ايي كه ميخواي عكس رو وش بريزي پرميشنش رو قول كن

Dim pic1 AsString = FileUpload1.PostedFile.FileName.Substring(FileUplo ad1.PostedFile.FileName.LastIndexOf("\") + 1)
name = Now.Year.ToString + Now.Month.ToString + Now.Day.ToString + Now.Hour.ToString + Now.Second.ToString + Now.Minute.ToString + Now.Millisecond.ToString + Path.GetExtension(FileUpload1.PostedFile.FileName)
FileUpload1.SaveAs(Server.MapPath("~\pic\") & name)


سلام دوست عزیز ممنون که پاسخ دادی ؟
جمله آخرت گفتی پزمیشنش رو قول کن این یعنی چی ؟

EnKamran
پنج شنبه 29 دی 1390, 17:49 عصر
یعنی از توی مدیریت هاست برو و به اون پوشه ای که قراره عکس داخلش آپلود بشه دسترسی Write و Read بده، جست و جو کنید در مورد دادن پرمیشن به فایل و فولدر پیدا می کنید.