简体   繁体   中英

Server Error in '/' Application. with View

I'm working on a new project for my school, and I'm trying to publish my website in ASP.Net MVC in IIS 8 on a Windows Server 2012 r2.

My project is with Framework .net 4.5.2.

When I try to launch my website on IIS I have this error :

    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. 

And I have this too :

    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 

I've tried everything with framework .net v4.5 or 4.5.2 for my project and for my application pool :

    .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)

UPDATE : First of all, thanks for your answers.

I'm using MVC and I have create controllers and used the view create by default with this controller. I haven't change their name or anything. Just put some code in it. My project work well with Visual Studio Community 2015.

For the rest, my Views folder is like this :

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

One more thing is that I've put my folder in "inetpub --> wwwroot --> MyFolder . And I have added rights for IUSR and IIS_IUSRS to read and execute. I've already tried to change right to total control.

It's not the first project I add to IIS in ASP.NET MVC, but for this one I don't know what is the problem...

I hope you can help me because I have to publish this website before the end of the week...

Thanks in advance,

Mattexis

This answer is actually shouldn't be worthy of Stackoverflow.. but i am guessing you didn't really realized what is mvc and how its working for that you need to check this link .

Anyways as for this issue. i believe you have added an action within your controller like below:

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

You can right click on the Index and Create a View, In the Create dialog it asks you to name the View, if you have changed it's name then you need to return the View name like:

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

While its the same name as the action you easily just return View();

Now if you do not know if you have changed it or not, here is how you can check this out:

When you create a controller it also create a folder with same name as your controller within the view folder. so if create HomeController, it also creates the Home Folder within your View Folder. Open this Folder check what is the name of the file or is there a file there even?

Always remember this if you are calling a view from an action in a controller, the view needs to be in same folder as your controller or in the shared folder, otherwise you receive the error above.

Update:

also as @Will mentioned, if you are running the application on the server you need to verify the account attempting to access the file has rights to read.

You have deployed your MVC files to a virtual directory. Open IIS admin and convert the directory to an application .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM