Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET 5 (ASP.NET Core) - unable to run with IIS

I am trying to deploy my ASP.NET 5 MVC project to local IIS, but facing with some errors.

Error

When open (my website address) localhost:80 I've got HTTP 404. I facing the same behaviour if I manualy run the approot\web.cmd. I think the problem is same. In web.cmd console I see this output for every request (for non-static routes, static files works good):

fail: Microsoft.Data.Entity.Query.Internal.SqlServerQueryCompilationContextFactory[1]
  An exception occurred in the database while iterating the results of a query.
  System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. File not found.
  File name: 'System.Data.SqlClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
  File name: 'System.Data.SqlClient'
     at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
     at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
     at Microsoft.Data.Entity.Storage.Internal.SqlServerConnection.CreateDbConnection()
     at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
     at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
     at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
     at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
     at Microsoft.Data.Entity.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()

Problem

When I run the dnx web from my project development directory MySolution\src\MyProject It's all OK

My Project.json

You can see that I am using dnxcore50 and haven't dependency to System.Data.SqlClient.

{
"userSecretsId": "aspnet5-Stomatology-b7dc4859-6376-4a5f-a583-d17b3660a64c",
"version": "1.0.0-*",
"compilationOptions": {
    "emitEntryPoint": true
},

"dependencies": {
    "AutoMapper": "4.1.1",
    "Domain": "1.0.0-*",
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final"
},

"commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
},

"frameworks": {
"dnxcore50": { }
},

"exclude": [
    "wwwroot",
    "node_modules"
],
"publishExclude": [
    "**.user",
    "**.vspscc"
],
"scripts": {
    "prepublish": [ "npm install", "bower install" ]
}

}

My deploying and IIS settings

  1. I deploy using File System options, like in manauls
  2. I installed HTTP Platform Handler
  3. I used Application Pool without managment environment

Conclusion

So, is there any way to fix this problem?

like image 928
Alexey Markov Avatar asked Feb 06 '16 23:02

Alexey Markov


People also ask

Can ASP.NET Core run on IIS?

The module allows ASP.NET Core apps to run behind IIS. If the Hosting Bundle is installed before IIS, the bundle installation must be repaired. Run the Hosting Bundle installer again after installing IIS.

How do I fix unable to launch IIS Express web server?

Try deleting the automatically-created IISExpress folder, which is usually located at %userprofile%/Documents , e.g. C:\Users\[you]\Documents\IISExpress . Don't worry, VS should create it again - correctly, this time - once you run your solution again. This worked for me.


1 Answers

I made it works. Below are the steps I have taken to get it to work:

  1. The requested page cannot be accessed because the related configuration data for the page is invalid.

    • Install HTTP Platform Handler
    • Make sure that ASP.NET 4.6 enabled in Windows Components: Internet Information Servies ->World Wide Services -> Application Development Components -> ASP.NET 4.6
  2. Unable to load System.Data.SqlClient

    • Add System.Data.SqlClient to your project.json
  3. Unable to load sni.dll

    • Use x64 coreclr runtime on x64 OS.
    • Install MS VC++ 2012 redistributable

If It still doesnt't work... (help for me for present day 08.02.2016 with 1.0.0-rc1-update1): - remove all dnx runtimes - install latest Update for ASP.NET and Web tools in Visual Studio - set the latest x64 runtime in VS in deploy settings

I think, this is a some kind of magic, I don't know, why this works.

like image 177
Alexey Markov Avatar answered Oct 10 '22 21:10

Alexey Markov