Я разработал веб-приложение MVC4 в сообществе VS2013. В нем пользователь может загрузить файл PDF с веб-страницы, а затем сохранить его в базе данных. Этот код работает очень хорошо в моей VS-среде. Но теперь, когда я отправился в онлайн-проект с помощью веб-отеля, я получаю сообщение об ошибке при попытке сохранить файл PDF.«Ошибка сервера в '/' приложении» из-за моего пути к файлу
Сообщение об ошибке:
Server Error in '/' Application.
Could not find a part of the path '\\172.21.204.201\webvol5\sr\hv8di47d6tma347\restaurangkontrollen.se\public_html\App_Data\Uploads\test.pdf'.
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.IO.DirectoryNotFoundException: Could not find a part of the path '\\172.21.204.201\webvol5\sr\hv8di47d6tma347\restaurangkontrollen.se\public_html\App_Data\Uploads\test.pdf'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path '\\172.21.204.201\webvol5\sr\hv8di47d6tma347\restaurangkontrollen.se\public_html\App_Data\Uploads\test.pdf'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +338
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1430
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +205
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) +84
Projekt_Restaurangkollen.Controllers.AdminController.NyResturang(ViewModel VM, String command) +1882
lambda_method(Closure , ControllerBase , Object[]) +170
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +270
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +120
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +452
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +240
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
контроллер код:
// extract only the fielname
var fileName = Path.GetFileName(TempVM.Resturang.PDF_File.FileName);
// store the file inside ~/App_Data/uploads folder
var filePath = Path.Combine(Server.MapPath("~/App_Data/Uploads"), fileName);
TempVM.Resturang.PDF_File.SaveAs(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
TempVM.Resturang.PDF_FileName = fileName;
TempVM.Resturang.PDF_Data = bytes;
TempVM.Resturang.PDF_ContentType = filePath;
cshtml код:
<div class="pdf-upload">
@Html.TextBoxFor(u => u.Resturang.PDF_File, new { type = "file" })
</div>
код работает отлично, а внутри VS, но теперь, когда я пытаюсь его " онлайн "это не сработает. У кого-нибудь есть идеи, почему?
Поскольку пользователь работает ваш пул приложений не имеет разрешений на этом пути. Вы пытались выполнить поиск? – CodeCaster
Okey, как я могу предоставить это разрешение? И что вы подразумеваете под «попыткой поиска»? – Hussaren
Попробуйте найти в Интернете и на этом сайте ошибку. Затем вы найдете вероятные причины и возможные решения. Как вы разместили сайт? Что означает «через веб-сайт»? – CodeCaster