繁体   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