PDA

View Full Version : سوال: خطا در هنگام اپلود فایل



baran_mehr
سه شنبه 12 مرداد 1389, 13:26 عصر
این کد اپلود فایل هست
این کد تو دستگاهم کار میکنه اما تو هاست جواب نمیده و خطا میگیره

Dim savepach As String = Request.PhysicalApplicationPath + "Download\"
If FileUpload.HasFile Then
savepach += FileUpload.FileName
FileUpload.SaveAs(savepach)
labMassege.Text = "فایل با موفقیت ذخیره شد"
Else
labMassege.Text = "عمل ذخیره سازی فایل صورت نگرفت "
End If

این پیغام خطا صادر میشه:

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>

Vahid_moghaddam
سه شنبه 12 مرداد 1389, 13:45 عصر
در web.config تغییرات زیر رو اعمال کنید تا متن خطا رو ببینید.


.
.
.
<compilation debug="true">
.
.
.
<customErrors mode="RemoteOnly"/>
.
.
البته بعد از حل مشکل، به حالت اول برگردونید.

اگه خطا این بود:
A generic error occurred in GDI+
به دو تاپیک زیر (حل شده) سر بزنید:
http://barnamenevis.org/forum/showthread.php?t=231784&highlight=permission
http://barnamenevis.org/forum/showthread.php?t=228008&highlight=permission
(لینک دوم، پست پنجم به بعد)

baran_mehr
سه شنبه 12 مرداد 1389, 14:07 عصر
اینکارو کردم اما تاثیری نداشت و هنوزم خطا میده

Vahid_moghaddam
سه شنبه 12 مرداد 1389, 14:17 عصر
اینکارو کردم اما تاثیری نداشت و هنوزم خطا میده

متن خطا چیه؟

پست اول شما، فقط اعلام می کنه خطایی رخ داده اما به دلیل تنظیمات web.config و امنیت، متن خطا رو نشون نمی ده. اون خاصیت ها رو که عوض کنید، خطا رو نشون می ده

baran_mehr
سه شنبه 12 مرداد 1389, 15:34 عصر
همون پیغام پست اولمو میده پیغام جدیدی نمیده

Vahid_moghaddam
سه شنبه 12 مرداد 1389, 16:08 عصر
ببخشید. من یه جا اشتباه نوشتم. به جای RemoteOnly بذارید Off


<customErrors mode="Off"/>

baran_mehr
سه شنبه 12 مرداد 1389, 19:58 عصر
فکر کنم اجازه تغییر رو بهم نمیده درسته؟


Exception Details: System.UnauthorizedAccessException: Access to the path 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) 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.

Vahid_moghaddam
سه شنبه 12 مرداد 1389, 22:56 عصر
احتمالا. از کنترل پنل هاست یا از iis به فولدر مورد نظر اجازه write بدید

baran_mehr
چهارشنبه 13 مرداد 1389, 00:55 صبح
میشه دقیقا بگید باید کجا برم. تو کدوم قسمت؟

amirjalili
چهارشنبه 13 مرداد 1389, 10:49 صبح
این خطا در تایپیک مرجع کامل خطاها و باگ ها در asp.net توضیح داده شده.

m2148059
چهارشنبه 13 مرداد 1389, 12:03 عصر
string savePath = Server.MapPath("~/Template/");

کد بالا رو امتحان یعنی مسیرو اینطوری بده ببین درست می شه ؟
server.mappath آدرس سرور را اتوماتیک حفظ می کنه تو پرانتزم اون مسیری که تو فایل root می خوای فایلا توش upload بشن رو بنویس . کد کلیشم خواستی ایناهاش :

if (FileUpload1.HasFile)
// Call a helper method routine to save the file.
SaveFile(FileUpload1.PostedFile);
else
// Notify the user that a file was not uploaded.
UploadStatusLabel.Text = "You did not specify a file to upload.";

این کدرو تو هرجا می خوای بنویس (تو هر event ی) بعدم تابع زیر رو بنویس :

void SaveFile(HttpPostedFile file)
{
// TextBox1.Page.RegisterRequiresViewStateEncryption( );
// Specify the path to save the uploaded file to.
string savePath = Server.MapPath("~/Template/");
// Get the name of the file to upload.
string fileName = ID.Text+color.Text+box.Text+menu.Text+".jpg";
// Create the path and file name to check for duplicates.
string pathToCheck = savePath + fileName;
// Create a temporary file name to use for checking duplicates.
string tempfileName = "";
// Check to see if a file already exists with the
// same name as the file to upload.
if (System.IO.File.Exists(pathToCheck))
{
int counter = 2;
while (System.IO.File.Exists(pathToCheck))
{
// if a file with this name already exists,
// prefix the filename with a number.
tempfileName = counter.ToString() + fileName;
pathToCheck = savePath + tempfileName;
counter++;
}
fileName = tempfileName;
// Notify the user that the file name was changed.
UploadStatusLabel.Text = "A file with the same name already exists." +
"<br />Your file was saved as " + fileName;
}
else
{
// Notify the user that the file was saved successfully.
UploadStatusLabel.Text = "Your file was uploaded successfully.";
}
// Append the name of the file to upload to the path.
savePath += fileName;
// Call the SaveAs method to save the uploaded
// file to the specified directory.
FileUpload1.SaveAs(savePath);
}

موفق باشی

baran_mehr
چهارشنبه 13 مرداد 1389, 12:34 عصر
شما تو پستتون این دلایل رو مطرح کردید.
من تو دستگاه خودم برنامه هیچ مشکلی نداره و iis هم نصب نکردم ولی وقتی تو هاست هست این پیغام خطا رو میده. من فکر میکنم مربوط به اجازه نوشتن تو فولدر باشه.

Server Error in '/' Application.


علت :
1:
این خطا ممکن دلائل زیادی داشته باشه، که دو تا از مهمترینهاش، خراب بودن IIS/.NET FX و اجرا بصورت Partial Trust هستش. اگر برنامه بدون تغییر به این وضعیت افتاده، .NET Framework رو Uninstall کنید، IIS رو هم Uninstall کنید، سپس ابتدا IIS و بعد .NET FX رو نصب کنید. بخاطر داشته باشید که حتما Service Pack مربوطه رو نیز نصب کنید. چون در برخی موارد عدم نصب SP باعث این خطا میشه (بخصوص هنگام استفاده از Component های Telerik).

"به نقل از مهدی موسوی"
2:
وقتی مثلا یکجایی میخواهید مقدار substring رو بگیرید و به جای اینکه از مقدار int رو در پارامتر متد قرار بدید مقداری string ی رو قرار بدید.

کد:
string s = "wdsdd";
s.Substring("sss");یا هرجایی که مقداری نامناسب رو به عنوان پارامتر به متد پاس بدید.

کد:
int.Parse(1)3:
دلیل بروز چنین خطایی وجود نداشتن ایندکس مربوط به یک آرایه می باشد.

Vahid_moghaddam
چهارشنبه 13 مرداد 1389, 15:54 عصر
کنترل پنل هاست شما چیه؟ plesk یا ...؟

amirjalili
چهارشنبه 13 مرداد 1389, 16:44 عصر
البته اون خطایی که شما دیدید مربوط به چیز دیگه ای هست.

درستش اینجا بود :



خطا :
کد:

Access to the path 'مسیر فایل' is denied
علت :
وقتی شما بخواهید در یکی از درایو های ویندوز فایلی مثل یک فایل word یا تصویر ایجاد کنید در حالی که در اون مسیر توسط ویندوز اجازه write کردن فایل رو ندارید و یا به هر دلیلی دسترسی به اون مسیر رو نداشته باشید با این خطا مواجه میشید.

راهکار :

مجوز write کردن رو در اون مسیر ویندوز به کاربر بدهید.


لینکش:
http://www.barnamenevis.org/forum/showthread.php?t=216042&page=5

baran_mehr
پنج شنبه 14 مرداد 1389, 00:43 صبح
ممنون m2148059 جان اما مشکل کد فکر کنم همون اجازه نوشتن باشه اگر حل بشه دیگه فکر نمیکنم ایرادی بگیره
Vahid_moghaddamجان بله plesk هست

man of rebellious being
پنج شنبه 14 مرداد 1389, 01:39 صبح
سلام

وارد plesk شوید وsite preview را کلیک کنید متن خطا را کامل نشان می دهد خطا رو بذارید تا بررسی شه.

Vahid_moghaddam
پنج شنبه 14 مرداد 1389, 01:39 صبح
این رو ببینید. اگه plesk هم نباشه، روش شبیه به همینه. به file manager برید و دسترسی بدید:

http://www.nettigritty.com/faq/plesk/write-permissions-in-plesk/

baran_mehr
پنج شنبه 14 مرداد 1389, 14:27 عصر
ممنون از کمک دوستان خوشبختانه وقتی اجازه نوشتن رو دادم حل شد
مرسی