Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a web.config to an owin self-hosted web api?

I actually just created an NServiceBus self-hosted endpoint and bootstrapped owin self-hosted web api 2 by adding the Microsoft.AspNet.WebApi.OwinSelfHost nuget package. It's all up and running fine and I can hit the controller endpoints that I added, but the package didn't add the normal items like the web.config.

I'd like to have the normal web.config available to where I can also add in different build configurations (the transform files like web.debug.config, web.release.config, etc).

How do I add this into my project?

I tried just adding the file, but ConfigurationManager doesn't read it.

like image 896
Sinaesthetic Avatar asked Oct 16 '25 19:10

Sinaesthetic


1 Answers

web.config is used for asp.net web application on a hosted server. As you are using a self-hosted server then web.config is no applicable. You would need app.config which would resolve to the executable name with the .config file extension.

Add app.config to the project and ConfigurationManager should be able to read it.

UPDATE:

It was indicated that the same config transformation was also needed for app.config

The following VS tool fills in the gap left between web.config transformations.

Configuration Transform

Automatically transform app.config or any other config during build process. Once the transformation is set, it will run on other build machines without the extension.

The link includes step by step instructions on how to use it in applying configuration transformations.

like image 93
Nkosi Avatar answered Oct 18 '25 16:10

Nkosi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!