PDA

View Full Version : سوال: مشکل ذخیره کردن اطلاعات فرم در بانک اطلاعاتی در هاست



پیام حیاتی
سه شنبه 17 آذر 1394, 17:46 عصر
سلام عزیزان
در لوکال هیچ مشکلی وجود نداره اما در هاست با کلیک بر روی دکمه ثبت اطلاعات با پیغام خطای زیر روبرو میشم (این حالت زمانی اتفاق می افتد که تصویری را برای آپلود انتخاب می کنم ، اگر تصویری انتخاب نشود مشکلی پیش نمی آید.) :


Server Error in '/' Application.


Runtime Error


Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.


Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".




<!-- Web.Config Configuration File -->


<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.




<!-- Web.Config Configuration File -->


<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>


این کدهای من :


string view = "";
for (int i = 0; i <= RadioButtonList1.Items.Count - 1; i++)
{
if (RadioButtonList1.Items[i].Selected)
{
if (view == "")
{
view = RadioButtonList1.Items[i].Text;
}
else
{
view += "," + RadioButtonList1.Items[i].Text;
}
}
}




PersianCalendar p = new PersianCalendar();
string dt_fa = p.GetYear(DateTime.Now) + "/" + p.GetMonth(DateTime.Now) + "/" + p.GetDayOfMonth(DateTime.Now);
string dt_pic = DateTime.Now.ToString("yyyy-MM-dd");


//Save Pic-1
string filename1 = "";
string filename2 = "";


if (FileUpload1.PostedFile != null)
{
// Check the extension of image
string extension = Path.GetExtension(FileUpload1.FileName);


if (extension.ToLower() == ".png" || extension.ToLower() == ".jpg" && FileUpload1.PostedFile.ContentLength < 512000)
{
Stream strm = FileUpload1.PostedFile.InputStream;
//filename1 = System.DateTime.Now.ToString("yyyyMMddhhmmss") + FileUpload1.FileName;
//filename1 = System.DateTime.Now.ToString("yyyyMMddhhmmss");
using (var image = System.Drawing.Image.FromStream(strm))
{


int newWidth = 240; // New Width of Image in Pixel
int newHeight = 240; // New Height of Image in Pixel
var thumbImg = new Bitmap(newWidth, newHeight);
var thumbGraph = Graphics.FromImage(thumbImg);
thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
var imgRectangle = new Rectangle(0, 0, newWidth, newHeight);
thumbGraph.DrawImage(image, imgRectangle);


//Create Random Numbers
Random r = new Random();
string n = r.Next().ToString();


// Save the file
filename1 = n + FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~\\img\\Home\\") + filename1);
filename2 = n + FileUpload1.FileName;
thumbImg.Save(filename1, image.RawFormat);
//Show Image
//Image1.ImageUrl = @"~\img\Home\" + FileUpload1.FileName;
}
}
else
{
filename2 = "Default.png";
}
}




con.Open();
string Query = "insert into T_Amlak (am_ostan , am_city , am_mantaghe , am_user , am_fullname , am_title_home , am_eghdam , am_metraj , am_room , am_year , am_view , am_main_price , am_pish_price , am_month_prices , am_number , am_pic1 , am_descrip , am_date_fa) values ('" + DropOstan.SelectedItem.Text + "' , '" + DropCity.SelectedItem.Text + "' , '" + txtMantaghe.Text + "' , '" + Session["u_id"].ToString() + "' , '" + txtFullNameSell.Text + "' , '" + DropTitle.SelectedItem.Value + "' , '" + DropEghdam.SelectedItem.Value + "' , '" + txtMetraj.Text + "' , '" + DropRestRoom.SelectedItem.Value + "' , '" + txtYear.Text + "' , '" + view + "' , '" + txtMainPrice.Text + "' , '" + txtPishPrice.Text + "' , '" + txtMonthPrices.Text + "' , '" + txtnumber.Text + "' , '" + filename2 + "' , '" + txtDescrip.Text + "' , '" + dt_fa + "') ";
//string Query = "insert into T_Amlak (am_mantaghe , am_cod_namayandegi) values ('" + DropMantaghe.SelectedItem.Value + "' , '" + Session["n_id"].ToString() + "') ";
SqlCommand com = new SqlCommand(Query, con);
com.ExecuteNonQuery();
con.Close();
clr();
lblSuccessRegister.Visible = true;
lblSuccessRegister.Text = "اطلاعات با موفقیت ثبت شد.";


کد :


<customErrors mode="Off"/>

به وب کانفیگ اضافه کردم که خطای زیر رو دارم :


Server Error in '/' Application.


Access to the path 'C:\Inetpub\vhosts\ahvazsell.ir\home.ahvazsell.ir\ img\Home\318836651angel (2).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\ahvazsell.ir\home.ahvazsell.ir\ img\Home\318836651angel (2).jpg' 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 File 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 140: // Save the file
Line 141: filename1 = n + FileUpload1.FileName;
Line 142: FileUpload1.SaveAs(Server.MapPath("~\\img\\Home\\") + filename1);
Line 143: filename2 = n + FileUpload1.FileName;
Line 144: thumbImg.Save(filename1, image.RawFormat);

پیام حیاتی
سه شنبه 17 آذر 1394, 18:45 عصر
ممکنه خطا به خاطر وجود سایت در ساب دامین باشد؟

aminmousavi
چهارشنبه 18 آذر 1394, 00:14 صبح
سلام دوست عزیز . به اون فولدر شما Permission ندارین از طریق پنل هاست وارد شید و دسترسی کامل به اون فولدر برای IIS رو بدید .

پیام حیاتی
چهارشنبه 18 آذر 1394, 08:14 صبح
امین جان سطوح دسترسی برای پوشه img و home را برابر fullcontrol قرار دادم :

137337

خطای جدید :


A generic error occurred in GDI+.


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.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.


Source Error:




Line 142: FileUpload1.SaveAs(Server.MapPath("~\\img\\Home\\") + filename1);
Line 143: filename2 = n + FileUpload1.FileName;
Line 144: thumbImg.Save(filename1, image.RawFormat);
Line 145: //Show Image
Line 146: //Image1.ImageUrl = @"~\img\Home\" + FileUpload1.FileName;


137338

پیام حیاتی
چهارشنبه 18 آذر 1394, 16:37 عصر
بروز رسانی

پیام حیاتی
پنج شنبه 19 آذر 1394, 16:54 عصر
از خیر تبدیل گذشتم.
با جایگزین کردن این کدها مشکل برطرف شد:


//Save Pic-1
string patch1 = "";
string extension = Path.GetExtension(FileUpload1.FileName);
//Create Random Numbers
Random r = new Random();
string n = r.Next().ToString();


if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength < 512000 && extension.ToLower() == ".png" || extension.ToLower() == ".jpg")
{
string filename1 = n + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\img\\Home\\" + filename1));
patch1 = filename1;
//patch1 = "~\\img\\Home\\" + filename1;
}


else
{
patch1 = "Default.png";
}