Marcin Zablocki
Marcin Zablocki

Reputation: 10683

Deploy ASP.NET 5 on Azure WebApps behind IIS

I have a problem with obtaining IP address of client who sent a request to a ASP.NET 5 application hosted on Azure WebApps.

My project uses ASP.NET 5 + MVC6 and runs on full CLR runtime (not CoreCLR). I've searched through the net for the answer, but haven't found any solution.

Using sugggestion from Get the client's IP address I've tried:

HttpContext.Connection.RemoteIpAddress

but the properties from HttpContext.Connection are all either false or null, so no luck here.

I've noticed the following: when I run my app via Visual Studio with IIS Express, the IP from Connection.RemoteIpAddress is available. Property is null when i run dnx web via command line. It seems that azure runs my app in the on dnx, not IIS.

So my question is: How to configure and deploy project to Azure WebApps, so it will run behind IIS and therefore HttpContext.Connection will have it's values filled ?

My current configuration (excerpt of project.json):

(...)
    "compilationOptions": {
        "emitEntryPoint": true
      },
    "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel",
        "ef": "EntityFramework.Commands"
      },

      "frameworks": {
        "dnx451": { }
      },
(...)

and the Configure method of Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{  
    app.UseIISPlatformHandler();
    //rest of the method...

}

Upvotes: 0

Views: 231

Answers (1)

Benjamin Talmard
Benjamin Talmard

Reputation: 1810

Azure Web App always uses IIS.

However, for ASP.NET 5 code, IIS is configured to use HttpPlatformHandler to redirect requests to Kestrel, the ASP.NET 5 web server. This is the way to run ASP.NET 5 application from ASP.NET Beta 8. You will see that configuration by opening your web.config file.

References :

There are some open issues related to obtaining client IP adress when using Kestrel, and they seem to be resolved in RC2 release:

Upvotes: 2

Related Questions