dstr
dstr

Reputation: 8938

web.config, app.config or both?

I have an ASP.NET Core project targeting .NET 4.5.2. I have some old components in the project that need web.config for configuration and I can't migrate them to the new appsettings.json. Right now I'm in development and running the application in console mode but it will be hosted in IIS in production. My question is, do I have to maintain both app.config and web.config simultaneously? When I build the application I only see MyProject.exe.config in the output folder which has app.config contents, but when I publish it I see both MyProject.exe.config and web.config in the output folder.

Upvotes: 4

Views: 2169

Answers (2)

RonC
RonC

Reputation: 33879

While it's true that you will need a web.config when running Kestrel behind IIS, that web.config will only be used for configuring IIS. If you are running Asp.Net Core there is no easy way for you existing dlls to get access to the settings in the web.config. You can learn more here: Access Web.config settings in Asp.Net Core App?

Upvotes: 1

Daboul
Daboul

Reputation: 2743

web.config will be read by IIS and is mandatory to configure how IIS will behave as a reverse proxy in front of Kestrel (I imagine that how you host it). For instance, if you want IIS to forward the Kerberos identity, that will remain the only place to configure it because it's really an IIS configuration: <aspNetCore ... forwardWindowsAuthToken="true"/> So I would say, yes, you'll have to maintain a web.config if you want to host behind IIS. Then, for everything else that does not concern IIS, I'm using an appsettings.json that is used all the time, in dev when reaching directly Kestrel, but also in stagting when behind an IIS. Supporting both, in your config (IIS as a reverse proxy in front of Kestrel) makes sense and is normal, you just need to separate properly what is driving IIS (->web.config) and what is driving the logic of your website (->appsettings.json).

Upvotes: 0

Related Questions