簡體   English   中英

“ /”應用程序中的服務器錯誤。 與視圖

[英]Server Error in '/' Application. with View

我正在為我的學校開展一個新項目,並且試圖在Windows Server 2012 r2上的IIS 8中的ASP.Net MVC中發布我的網站。

我的項目是使用Framework .net 4.5.2。

當我嘗試在IIS上啟動我的網站時,出現此錯誤:

    Server Error in '/' Application. 

    The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/Home/Index.aspx
    ~/Views/Home/Index.ascx
    ~/Views/Shared/Index.aspx
    ~/Views/Shared/Index.ascx
    ~/Views/Home/Index.cshtml
    ~/Views/Home/Index.vbhtml
    ~/Views/Shared/Index.cshtml
    ~/Views/Shared/Index.vbhtml 
    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.InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/Home/Index.aspx
    ~/Views/Home/Index.ascx
    ~/Views/Shared/Index.aspx
    ~/Views/Shared/Index.ascx
    ~/Views/Home/Index.cshtml
    ~/Views/Home/Index.vbhtml
    ~/Views/Shared/Index.cshtml
    ~/Views/Shared/Index.vbhtml

    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: 


    [InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
    ~/Views/Home/Index.aspx
    ~/Views/Home/Index.ascx
    ~/Views/Shared/Index.aspx
    ~/Views/Shared/Index.ascx
    ~/Views/Home/Index.cshtml
    ~/Views/Home/Index.vbhtml
    ~/Views/Shared/Index.cshtml
    ~/Views/Shared/Index.vbhtml]

    System.Web.Mvc.ViewResult.FindView(ControllerContext context) +499
    System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +143

    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +88
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +831
    System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
    System.Web.Mvc.Async.<>c__DisplayClass21.
    <BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +43
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +67
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +607
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134

 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2053.0 

我已經為我的項目和應用程序池使用了框架.net v4.5或4.5.2進行了所有嘗試:

    .NET v2.0 (version v2.0 and v4.0.39319 of CLR.NET)
    .NET v2.0 Classic (version v2.0.50727 of CLR.NET and v4.0.39319 of CLR.NET)
    .NET v4.5 (version v4.0.39319 of CLR.NET and v2.0.50727 of CLR.NET)
    .NET v4.5 Classic v4.0.39319 of CLR.NET and v2.0.50727 of CLR.NET)
    Classic .NET AppPool (version v4.0.39319 of CLR.NET and v2.0.50727 of CLR.NET)
    DefaultAppPool (version v4.0.39319 of CLR.NET and v2.0.50727 of CLR.NET)

更新:首先,感謝您的回答。

我正在使用MVC,並且具有創建控制器,並且默認情況下將此視圖與該控制器一起使用。 我沒有改變他們的名字或其他任何東西。 只需在其中添加一些代碼即可。 我的項目與Visual Studio Community 2015配合良好。

其余的,我的Views文件夾是這樣的:

--> Views
     --> Home
         --> About.cshtml
         --> Contact.cshtml
         --> Legal.cshtml (not used)
     --> Participants
         --> Create.cshtml
         --> Index.cshtml
     --> Shared
         --> _Layout.cshtml
         --> Error.cshtml

還有一件事是,我已經將文件夾放在“ inetpub-> wwwroot-> MyFolder中。我還為IUSR和IIS_IUSRS添加了讀取和執行的權限。我已經嘗試過更改完全控制權。

這不是我在ASP.NET MVC中添加到IIS的第一個項目,但是對於這個項目,我不知道是什么問題...

希望您能對我有所幫助,因為我必須在本周末之前發布此網站...

提前致謝,

Mattexis

這個答案實際上不應該是Stackoverflow值得的。但是我猜您沒有真正意識到mvc是什么,以及它如何工作,您需要檢查此鏈接

無論如何,關於這個問題。 我相信您已經在控制器中添加了一個動作,如下所示:

public ActionResult Index()
{
    return View();
}

您可以右鍵單擊“ Index並創建一個視圖,在“創建”對話框中,它要求您命名視圖,如果更改了它的名稱,則需要返回如下視圖名稱:

public ActionResult Index()
{
    return View("Changed");
}

盡管其名稱與動作相同,但您只需return View();

現在,如果您不知道是否進行了更改,可以通過以下方法進行檢查:

創建控制器時,它還會在視圖文件夾中創建一個與控制器名稱相同的文件夾。 因此,如果創建HomeController,它也會在您的View文件夾中創建Home文件夾。 打開此文件夾,檢查文件的名稱是什么,甚至還有文件?

如果要從控制器中的操作調用視圖,請務必記住這一點,該視圖必須與控制器位於同一文件夾中或位於共享文件夾中,否則您會收到上述錯誤。

更新:

就像@Will提到的那樣,如果您正在服務器上運行該應用程序,則需要驗證嘗試訪問該文件的帳戶是否具有讀取權限。

您已將MVC文件部署到虛擬目錄。 打開IIS admin 並將目錄轉換為應用程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM