marco birchler
marco birchler

Reputation: 1746

ASP.NET Core can't find view when integrated to IIS

I have built an ASP.NET Core application and want to rollout this app on my Win2008 server. If I start the application directly in kestrel (double click on the exe which contains the main) everything works fine. However if I start the application via IIS I get the following exception:

fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HKU0DCR0LPSS": An unhandled exception was thrown by the application. System.InvalidOperationException: The view 'Login' was not found. The following locations were searched: /Views/Account/Login.cshtml /Views/Shared/Login.cshtml at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations) at Microsoft.AspNetCore.Mvc.ViewResult.d__26.MoveNext()

Exactly this exception was already discussed in this question. But I compared my files with the proposed solution and still get the error.

I have also noticed that a configuration file which was originally placed next to the application.exe has to be moved inside the wwwroot folder if I start the app via IIS.

Here is the content of my web.config which sits inside the wwwroot folder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="..\ERMSClient.exe" arguments="" stdoutLogEnabled="true" stdoutLogFile="..\logs\stdout" />
  </system.webServer>
</configuration> 

And this is my project.json

{
  "dependencies": {
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNetCore.Server.WebListener": "0.1.0",
    "Microsoft.AspNetCore.Http": "1.0.0",
    "Microsoft.AspNetCore.Authorization": "1.0.0",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0",
    "Microsoft.AspNetCore.Mvc.ApiExplorer": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Abstractions": "1.0.0",
    "Microsoft.AspNetCore.Session": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Newtonsoft.Json": "9.0.1",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "System.Web.Helpers.dll": "1.0.0",
    "AutoMapper": "5.0.2",
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final",
    "Microsoft.Extensions.Configuration": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0"
  },
  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net461": {
      "dependencies": {
        "d3Communicator": {
          "target": "project"
        }
      }
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },
  "scripts": {
    "prepublish": [ "npm install", "bower install" ],
    "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
  }
}

In addition I have to mention that I have upgraded this project from ASP.NET RC1. Therefore I have perhaps an old entry or something else somewhere.

Upvotes: 1

Views: 2629

Answers (1)

marco birchler
marco birchler

Reputation: 1746

I found the very very simple answer to my problem. Somehow I assumed that I have to point the physical path of my IIS site to the wwwroot directory of my ASP.NET Core project. This is not correct the physical path has to point to the full publish directory above the wwwroot.

Upvotes: 1

Related Questions