2013-12-13 38 views
1

我有以下的操作方法,其上傳的文件添加到文件夾後: -無法上傳文件在我的文件夾的內容,發佈我的asp.net MVC Web應用程序到IIS

if (ModelState.IsValid) 
       { 
        string ADusername = User.Identity.Name.Substring(User.Identity.Name.IndexOf("\\") + 1); 
        repository.InsertOrUpdateDataCenter(dc, ADusername); 
        repository.Save(); 
        if (DataCenterfile != null) 
        { 
         var fileName = Path.GetFileName(DataCenterfile.FileName); 

         var path = Path.Combine(Server.MapPath(Url.Content("~/Content/uploads")), dc.ID + ".png"); 
         DataCenterfile.SaveAs(path); 
        } 
        return RedirectToAction("Details", new { id = dc.ID }); 
       } 

但我我收到以下異常: - 我已經發表了我的web應用到IIS

Server Error in '/TMS' Application. 

Could not find a part of the path 'C:\inetpub\wwwroot\TMS\Content\uploads\97.png'. 

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 'C:\inetpub\wwwroot\TMS\Content\uploads\97.png'. 

Source Error: 

記住,上述運作良好霸菱,但之後,我開始收到此錯誤。所以任何人都可以建議我如何解決這個問題? 感謝

+1

愚蠢的問題,但'/ Content'文件夾存在於它發佈到的IIS站點中?發佈時可能不包括它。 –

+0

謝謝,我檢查了IIS管理器和你是正確的上傳文件夾不在IIS裏面,當它訪問Visual Studio上的應用程序時,它是我應用程序的一部分。你能否告訴我爲什麼不包括在內,以及如何包含它? –

回答

-1

上傳文件夾不在IIS內部,所以我必須手動發佈它。

3

相信你想要做的是設置「建設行動」爲Content文件夾「內容」。

您可以通過在解決方案資源管理器中選擇文件夾來完成此操作,然後在屬性下進行操作。在那裏你會看到「Build Action」選項。將其設置爲「內容」或「無」。

+0

在屬性下沒有選項來設置構建操作,所以我所做的是我右鍵單擊該文件夾,然後選擇發佈此文件夾。並且它已發佈到IIS,但我仍然確定爲什麼該文件夾未包含在我的第一個發佈中,並且應該手動發佈此文件夾? –

相關問題