'/'应用程序中的服务器错误。与视图

时间:2017-06-19 15:46:29

标签: c# asp.net asp.net-mvc asp.net-mvc-4 iis

我正在为我的学校开展一个新项目,我正在尝试在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 - &gt; wwwroot - &gt; MyFolder。我已经添加了IUSR和IIS_IUSRS的权限来读取和执行。我已经尝试改变了完全控制。

这不是我在ASP.NET MVC中添加到IIS的第一个项目,但对于这个我不知道是什么问题...

我希望你能帮助我,因为我必须在本周结束之前发布这个网站......

提前致谢,

Mattexis

2 个答案:

答案 0 :(得分:0)

这个答案实际上不值得Stackoverflow ...但我猜你没有真正意识到什么是mvc以及它的工作原理你需要检查这个link

无论如何都是这个问题。我相信你已经在你的控制器中添加了一个动作,如下所示:

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

您可以右键单击Index并创建一个视图,在“创建”对话框中,它会要求您命名视图,如果您更改了它的名称,则需要返回视图名称,如:

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

虽然它与您轻松的动作同名return View();

现在,如果您不知道自己是否更改过,请按以下方式查看:

创建控制器时,它还会在视图文件夹中创建一个与控制器同名的文件夹。因此,如果创建HomeController,它还会在View文件夹中创建Home文件夹。打开此文件夹检查文件的名称是什么,或者是否有文件?

如果您从控制器中的操作调用视图,请始终记住这一点,视图需要与控制器位于同一文件夹中或共享文件夹中,否则您将收到上述错误。

更新:

同样如@Will所提到的,如果您在服务器上运行该应用程序,则需要验证尝试访问该文件的帐户是否有权阅读。

答案 1 :(得分:0)

您已将MVC文件部署到虚拟目录。打开IIS管理员和convert the directory to an application