8

I am trying to deploy an asp.net core app on a server. I have done the following steps.

first thing is first, this is an Windows Server 2012 r2 environment that is a brand new virtual machine.

  1. build the VM
  2. update all ms updates
  3. add iis role
  4. insure asp.net 3.5 and 4.5 are installed on machine
  5. insure http redirection and static content is installed
  6. install .net core bundle
  7. publish self contained app from Visual Studio (project name Web)
  8. add this to a folder on server.
  9. try running from web.exe

I get the console app opens says now listening on: http://localhost:5000 10. I go to http://localhost:5000 from chrome on this machine and get a 404 not found.

I do steps 7 8 9 and 10 on local machine which is windows 10 i get my application.

project.json

  {
      "dependencies": {
        "AutoMapper": "5.1.1",
        "EntityFramework": "6.1.3",
        "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
        "Microsoft.AspNetCore.Diagnostics": "1.0.0",
        "Microsoft.AspNetCore.Mvc": "1.0.0",
        "Microsoft.AspNetCore.Razor.Tools": {
          "version": "1.0.0-preview2-final",
          "type": "build"
        },
        "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
        "Microsoft.AspNetCore.StaticFiles": "1.0.0",
        "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
        "Microsoft.Extensions.Configuration.Json": "1.0.0",
        "Microsoft.Extensions.Logging": "1.0.0",
        "Microsoft.Extensions.Logging.Console": "1.0.0",
        "Microsoft.Extensions.Logging.Debug": "1.0.0",
        "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
      },

      "tools": {
        "BundlerMinifier.Core": "2.0.238",
        "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
        "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
      },

      "frameworks": {
        "net452": {
          "dependencies": {
            "DataAccess": {
              "target": "project"
            },
            "Models": {
              "target": "project"
            }
          }
        }
      },

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

      "publishOptions": {
        "include": [
          "wwwroot",
          "Views",
          "Areas/**/Views",
          "appsettings.json",
          "web.config"
        ]
      },
      "runtimes": {
        "win10-x64": {},
        "osx.10.11-64": {} 
      },
      "scripts": {
        "prepublish": [ "bower install", "dotnet bundle" ],
        "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
      }
    }

configure from startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        Mapper.Initialize(config =>
        {
            /*View Models*/
            config.CreateMap<Permit, PermitViewModel>().ReverseMap();
            config.CreateMap<PermitType, PermitTypeViewModel>().ReverseMap();
            config.CreateMap<Property, PropertyViewModel>().ReverseMap();
            config.CreateMap<Region, RegionViewModel>().ReverseMap();
            config.CreateMap<State, StateViewModel>().ReverseMap();
            config.CreateMap<User, UserViewModel>().ReverseMap();

            /*Dtos*/
            config.CreateMap<Permit, PermitDto>().ReverseMap();
            config.CreateMap<Property, PropertyDto>().ReverseMap();
            config.CreateMap<Region, RegionDto>().ReverseMap();
            config.CreateMap<State, StateDto>().ReverseMap();
            config.CreateMap<User, UserDto>().ReverseMap();
        });

        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseApplicationInsightsRequestTelemetry();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseApplicationInsightsExceptionTelemetry();

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
}

program.cs

public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();
        }

my goal is to have this run on iis.

UPDATE

Software: Microsoft Internet Information Services 8.5

Version: 1.0

Date: 2016-12-06 23:49:44

Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus

sc-win32-status time-taken 2016-12-06 23:49:44 fe80::9c6d:a91b:42c:82ea%12 OPTIONS / - 80 - fe80::c510:a062:136b:abe9%12 DavClnt - 200 0 0 1139 2016-12-06 23:49:47 fe80::9c6d:a91b:42c:82ea%12 OPTIONS /website - 80 - fe80::c510:a062:136b:abe9%12 Microsoft-WebDAV-MiniRedir/10.0.14393 - 200 0 0 46 2016-12-06 23:49:47 fe80::9c6d:a91b:42c:82ea%12 PROPFIND /website - 80 - fe80::c510:a062:136b:abe9%12 Microsoft-WebDAV-MiniRedir/10.0.14393 - 404 0 2 62 2016-12-06 23:49:47 fe80::9c6d:a91b:42c:82ea%12 PROPFIND /website - 80 - fe80::c510:a062:136b:abe9%12 Microsoft-WebDAV-MiniRedir/10.0.14393 - 404 0 2 62

this is the log message that i get

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!--
    Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
  -->

  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
  </system.webServer>
</configuration>
JamTay317
  • 1,017
  • 3
  • 18
  • 37
  • Have you installed **.NET Core Windows Server Hosting bundle** on the server? – Sanket Nov 26 '16 at 11:40
  • yes I have done this – JamTay317 Nov 26 '16 at 12:50
  • Did you create an virtual directory/host in IIS? Use it's port, not the port defined by kestrel.The Port 5000 looks like the default kestrel port, which is used only when you runt he application as with kestrel hosting. When you use kestrel with IIS as reverse proxy (using `UseIISIntegration`), then `UseIIISIntegration`will set the kestrel port (for internal communication) and use the IIS Webpages port for external hosting – Tseng Nov 26 '16 at 13:23
  • Additionally, if you use a VM and not run the IIS on your developing machine, you also need to use the VM servers IP instead of localhost. `localhost` means loopback to the machine you are on – Tseng Nov 26 '16 at 13:24
  • no I didn't add anything to iis can you please provide link on how to do this? – JamTay317 Nov 26 '16 at 14:15
  • For Publishing to IIS, refer this link- https://learn.microsoft.com/en-us/aspnet/core/publishing/iis – Sanket Nov 26 '16 at 17:41
  • I have done all of this. it still doesn't work – JamTay317 Nov 27 '16 at 12:58
  • Any clues in the eventvwr? iis logs? does browsing to the vm work (ie not using localhost on it locally)? Tried other browsers? – Jeremy Thompson Dec 05 '16 at 00:47
  • I have tried to look at logs, but the logs do not show anything other than it says 404. eventViewer I have not found much, i will look through them again. I get a 404 if i browse from separate machine or localhost. no i have only tried google chrome – JamTay317 Dec 05 '16 at 03:40
  • When you run `web.exe` from command line - localhost:5000 still return 404? What is written in console window during this? – Dmitry Dec 06 '16 at 12:43
  • yes, it does on server. but not on local machine. – JamTay317 Dec 06 '16 at 22:49
  • I added iis logs to update – JamTay317 Dec 07 '16 at 09:58
  • Can you share `web.config` from published location? and what is the value of `ASPNETCORE_ENVIRONMENT` on server? – Sanket Dec 07 '16 at 18:03
  • I have added web config – JamTay317 Dec 09 '16 at 00:12
  • And how do you set `ASPNETCORE_ENVIRONMENT` variable on server? – Sanket Dec 09 '16 at 16:11
  • I dont know how to check this – JamTay317 Dec 09 '16 at 16:59
  • Refer this post http://stackoverflow.com/questions/31049152/publish-to-iis-setting-environment-variable – Sanket Dec 09 '16 at 17:23
  • can you please tell me what setting i need for this? or how to figure out what i need. – JamTay317 Dec 09 '16 at 18:52
  • This is out in left field a bit but it looks like you are mixing (which is fine) .net core project types (.xproj) w/ traditional class libraries (.csproj). What does your root 'src' folder structure look like? – trevorc Dec 09 '16 at 22:44
  • I don't have a src folder in the project – JamTay317 Dec 10 '16 at 01:17
  • @JamTay317 Update web.config like this- ` ` and check. – Sanket Dec 10 '16 at 07:58

3 Answers3

3

Please check "platform": "anycpu" in platform part:

"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},

and

 "buildOptions": {
   "platform": "anycpu",
   "emitEntryPoint": true,
   "preserveCompilationContext": true
},
Elnaz
  • 2,854
  • 3
  • 29
  • 41
2

This is an issue that would really benefit from more documentation. This is just how I do it and I am not saying this is the only way.

1.Make sure you have the dotnetcore hosting installed

2.Create an app pool that targets "no managed code"

3.Create a website that uses that app pool ( this is where you define your IP Address and Port that IIS will listen on)

4.Publish a web deploy package (Visual Studio) ( which will give you a zip folder)

5.Move that zip folder to the server

6.Go to your website that you created and right click on the website (make sure the site is stopped)

7.I can't remember the exact option but it is something to the effect of "Manage Website" You should get another menu that gives you the option to Import

8.Click it and browse for that zip folder You can set up other options

9.Once that is done start the website again

10.Then you should be able to go to your app in a browser using the IP Address that was configured for the website in IIS

Patrick Mcvay
  • 2,221
  • 1
  • 11
  • 22
  • this is bascily the same that i did before. i still get a 404 – JamTay317 Dec 07 '16 at 00:01
  • One other thing... When you configured the IP Address for the website. Is it the same as the server's IP? If not have you told your DNS where to send requests for that IP? – Patrick Mcvay Dec 07 '16 at 13:25
  • this isn't the issue. i have created many tests and deployed. they all work on server. there is something wrong with the configuration. – JamTay317 Dec 09 '16 at 00:11
0

If I am not mistaking, your project.json has no reference to asp.NET-core, but to the full framework:

"frameworks": {
    "net452": {
      "dependencies": {
        "DataAccess": {
          "target": "project"
        },
        "Models": {
          "target": "project"
        }
      }
    }
  },

I think you are missing this somewhere to target the .NETCore :)

"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},
Jean
  • 4,911
  • 3
  • 29
  • 50