meysamdalipour
پنج شنبه 29 دی 1390, 16: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:
لطفا کمک کنید
من یه مشکلی برای آپلود عکس دارم و اون اینه که :
من عکس رو آپلود می کنم و در لوکال هاست یعنی قبل از آپلود درست کار می کنه
اما بعد اینکه آپلود کردم درست کار نمی کنه و پیام عجیب و غریبی می ده .
دستوری که من نوشتم اینه :
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:
لطفا کمک کنید