I have a rather simple .NET WebApi application which I'm trying to host inside IIS. Followed all of the instructions from MS site about this.
here is the startup method for it.
public static void Main(string[] args)
{
var host = WebHost.CreateDefaultBuilder(args)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
I configured the Application pool to not use any managed code but I'm getting still this error in logs
Application startup exception: System.InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
I'm out of any ideas what can be wrong.
Any suggestions?
Using .NET Core 2.2
For InProcess, it uses IISHttpServer.
For your code, you are configuring UseKestrel() which uses out-of-process.
For solution, remove the .UseKestrel() line.
public static void Main(string[] args)
{
var host = WebHost.CreateDefaultBuilder(args)
//.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
For more details, refer ASP.NET Core Module.
I want to use UseKestrel().
When I create .net core 2.0 or 2.1 project. I can use UseKestrel()
But If I create .net core 2.2 project I couldn't use UseKestrel()
I solved this problem like that
Create new .net core 2.0 or 2.1 project. Then, you can upgrade .net core project to 2.2. It will work.
But it is not effective solution.
Related
I have a .Net Core 3.1 project that uses Serilog and posts messages to Azure Eventhub.
The problems started when we moved it to .Net 5.
Here's how it's configured
in Startup.cs
in ConfigureServices we have section
var eventHubConfig = Configuration.GetSection("Logging").GetSection("eventHub");
string eventHubConnection = eventHubConfig.GetValue<string>("connectionString");
Log.Logger = new LoggerConfiguration()
.WriteTo.AzureEventHub(new JsonFormatter(),
eventHubConnection.Replace(#"\", ""),
eventHubConfig.GetValue<string>("entityName"))
.CreateLogger();
in Configure method we have: loggerFactory.AddSerilog();
and in Program.cs
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseSerilog()
.UseStartup<Startup>();
Very simple and it's working for .Net Core 3.1, but once I change the target framework for the project to .Net 5 it stops working.
Any thoughts?
Has anyone seen the same issue?
Serilog uses an old version of Microsoft.Azure.EventHubs internally
I had the same issue and bumping to 4.3.2 solved the problem
Since then Microsoft.Azure.EventHubs have been deprecated and we have moved to Serilog 6 and Azure.Messaging.EventHubs
I have a .net core 2.2 application configured to run under IIS:
public static void Main(string[] args)
{
ProgramExtensions.ConfigureTypeConverters();
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
And also in .csproj configured to run in process:
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
For some reason when running it under IIS Express I'm getting:
InvalidOperationException: Application is running inside IIS process but is not configured to use IIS server.
What might be the reason of the error?
I have an aspnetcore 2.1 app running on azure.
I now want to view logging information to debug an issue that occurs only on Azure.
In the app, an ILogger<> is injected into the class and used:
this._logger.LogInformation("constructor**********************************************");
If I run the app in VS, I can see the output in both the debug output window, as well as the asp.net core web server output window.
I then publish and go on Azure and enable the Log Stream and view it. I do see information appearing in the log stream, but it is just the request information from IIS. I don't see any other log messages.
Is there anything else I need to do to see the logging information on Azure?
You can use Microsoft.Extensions.Logging.AzureAppServices. The package describes itself as:
Logger implementation to support Azure App Services 'Diagnostics logs' and 'Log stream' features.
Once you've installed the package, you'll need to update the logger configuration to use this new provider, which is usually done in Program.cs, like this:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureLogging(loggingBuilder =>
{
loggingBuilder.AddAzureWebAppDiagnostics();
})
...
.UseStartup<Startup>();
You need to configure Application Insights with your application to see the logs generated.
You can read the steps from Enable diagnostics logging for web apps in Azure App Service
You need to install and configure Azure Application Insights for your project.
By configuring the Instrument Key in your application you can send all the kinds of logs from your application to Application Insights.
Install the below Nuget
Microsoft.ApplicationInsights.AspNetCore 2.2.0 NuGet packages
Configure the Application Insights in you asp.net core application
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
// Change to file post adding Application Insights Telemetry:
.UseApplicationInsights()
//
.UseStartup<Startup>()
.Build();
}
See this step by step instruction on how to configure application insights into your asp.net core
I am trying to override the server url manually with a hosting.json file, however the url never get's used. I am on .net core 2.0.
hosting.json:
{
"urls": "http://localhost:5000"
}
Program.cs:
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
IConfigurationRoot config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.AddCommandLine(args)
.Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.Build();
}
}
Visual Studio gives you two profiles to run application:
IIS Express, which fairly obviously runs the application using IIS Express and
WebApplication2 (or any given name of your app), the name of the web project, which runs the application using dotnet run using Kastrel instead of IIS.
You can try switching and running application from the second profile (it should pick up hosting.config).
If you want to run app on IIS you can change launchSettings.json that is located under project properties
Also, you can find more details how to configure urls here.
I am trying to authenticate my MSSQL connection with Trusted_Connection=True. In order to get that working, I installed NuGet package Impersonate.AspNetCore.Windows (Impersonate), and set it up in my Startup.cs, like so:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseWindowsImpersonation(options => {
options.Enabled = true;
});
}
In my Program.cs I added UseIISIntegration to setup .net core to be hosted in IIS:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
In IIS I created a new Website, changed the ApplicationPool Basic Settings to No managed Code and Classic pipeline mode. In the Advanced Settings I set the Identity under Process Model to an existing Windows User account:
When I use Trusted_Connection=True in my connection string, the application fails to authenticate my connection to the SQL server:
"ConnectionStrings": {
"DashboardDatabase": "Server=<SOME_SERVER>;Database=<SOME_DATABASE>;Trusted_Connection=True"
}
(where and are replaced by the actual names of the server and database, of course).
My question is: Am I forgetting something here?
I had exactly the same setup as you and I got it working. Did you add forwardWindowsAuthToken="true" to your web.config file? You might have to create the web.config file in the root folder of your application if you haven't yet. See the package repo
FYI I also have Integrated Security=true; in my connection string, not sure if that is needed.