1

I have a dotnet core application which I can get working behind IIS for :80 requests but I need to access kestrel directly on 6001 since my IIS doesn't support websockets. I can run the exe from the server and it will start a cmd window and listen on 6001 but it doesn't stay up reliably. Is it possible to have it automatically start and stay up on 6001?

here is my startup

var host = new WebHostBuilder()
                .UseUrls("http://::6001", "http://localhost:6001")
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())

                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();

here is my proj file

{
  "dependencies": {

    "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.Binder": "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",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.AspNetCore.Websockets.Server": "0.1.0",
    "Swashbuckle": "6.0.0-beta901",
    "AutoMapper": "5.0.2"
  },

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

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

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

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "runtimes": {
    "win7-x64": {}
  },

  "commands": {
    "run": "run server.urls=http://localhost:6001",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:6001",
    "weblistener": "Microsoft.AspNet.Hosting --server WebListener --server.urls http://localhost:6001"
  }, 
  "publishOptions": {
    "include": [
      "wwwroot",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
matthewdaniel
  • 1,842
  • 4
  • 21
  • 35
  • What do you mean it does not "stay up reliably"? Kestrel should not shutdown on itself. Besides - your project.json seems out of date - "commands" have been removed in RC2 and don't exist in RTM. You also marked this question as IIS-6 - this won't work you need at least IIS 7.5 or newer. – Pawel Aug 19 '16 at 18:46
  • commands was previously not in there. I've been just throwing things at it. Also, i don't need iis 7.5 or newer unless i plan on passing websocket request through iis. I'm currently passing http through iis and accessing kestrel on 6001. Process is to RDP into server every morning and double click MyApp.exe. There then seems to be two myapp.exe in processes. The manually started one goes away every night. I'm sure there is something quite wrong with how i'm doing this. – matthewdaniel Aug 19 '16 at 20:32
  • You do need IIS 7.5 or newer. AspNET Core Module won't work on anything pre-IIS 7.5 and it is required to run ASP.NET Core apps. In this post I described how things work: https://blog.3d-logic.com/2016/06/08/running-asp-net-core-applications-with-iis-and-antares/. – Pawel Aug 19 '16 at 20:42
  • Sorry, just double checked and i am running iis 7.5. However that is working no problem with http currently. However http://stackoverflow.com/questions/14128347/signalr-websockets-on-iis-7-5#14130152 says i cannot use it for the web sockets thus i need the kestrel server to always be running to handle that – matthewdaniel Aug 19 '16 at 20:55
  • With ASP.NET core you always need to use Kestrel. Even when you use IIS it is merely acting as a reverse proxy and passes the requests to Kestrel running out of process. IIS/(ASP.NET Core Module) is starting Kestrel on the first request – Pawel Aug 19 '16 at 21:01
  • I do see that but if i run netstat -a -b -n it doesn't show anything listening on port 6001. If i run my app manually the netstat reports the 6001 listener. When iis reverse proxies, how do i directly access the kestrel server without hitting iis since it doesn't seem to have a port set up when it was started – matthewdaniel Aug 19 '16 at 21:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121389/discussion-between-matthewdaniel-and-pawel). – matthewdaniel Aug 19 '16 at 21:11
  • Read the blog I linked to. IIS starts kestrel on a random port - each time the port will be different. 6001 will be respected only if you run the app directly (i.e. without IIS) – Pawel Aug 19 '16 at 21:27
  • My initial question was "Is it possible to have it (kestrel) automatically start and stay up on 6001" your blog post doesn't address this (unless with a maybe implicit no). I don't mind running two kestrel servers if i have to at the moment. I just can't have my socket one dropping every night. – matthewdaniel Aug 19 '16 at 21:33
  • `.UseIISIntegration()` overwrites `.UseUrls("http://::6001", "http://localhost:6001")` with a dynamic port specified by IIS (ANCM). You should not attempt to bypass IIS for any requests. – Tratcher Aug 19 '16 at 23:34
  • @tratcher - why not if iis cannot handle websocket traffic – matthewdaniel Aug 20 '16 at 11:02
  • Because Kestrel is not yet security qualified to be directly exposed. – Tratcher Aug 20 '16 at 14:49

1 Answers1

0

If you are running it as EXE only because of websocket then you can use the IIS URL rewriting to detect the traffic and if it is websocket upgrade it and pass it to Kestrel and to your application .

have a look at here

Ali Alp
  • 691
  • 7
  • 10