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

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.

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.

Related

Add entries to web.config file of asp.net core application when web.config does not exist

I have an asp.net CORE project targeting .NET Framework 4.71
There is an appsettings.json file but not web.config.
When I check the binaries of the deployed application service, then I see there is
a file literally called web.config.
I need to put some server header removal entries in that web.config but it seems
only to be available where it is deployed.
So who is creating that web.config file which is not available locally in the
code solution?
In regular .NET world, we have option to save settings in web.config or in app.config file. But in .NET Core, you have option to save them in few other locations like appsettings.json , appsettings.<Environment>.json and in secrets.json.
One of the main reason settings are not saved in web.config file is, to avoid settings getting checked-into repo. By default appsettings.json file are ignored by repo clients.
As Kirk said, the dotnet-cli automatically creates this web.config based on the the csproj settings.

Asp.net Hosted Blazor - Can i use app.config or web.config?

Im looking to add a web.config (or app.config) so that i can have different settings (e.g. DEV build vs RELEASE build, for instance).
Can i simply add a .config file and expect to read from it?
I noticed that there is also an option to add a appsettings.json (App Settings File).
Which one of these should i be using for Blazor Client app (hosted via Asp.net)?
Thanks
Updates
Based on the following thread, i might just go with a settings
file on the Server side and feeding it to the Client via API.
Here is another reference for appsettings.json vs web.config
I was able to find a more concrete example int this article.
I believe you can use appsettings.Development.json and appsettings.json
Hope this helps...

ASP.NET Core Web.Config publish

When publishing a .Net Core app to a server via WebDeploy, a Web.Config file is created, with stdoutLogEnabled=false. This is overwriting the web.config on the server where I have set stdoutLogEnabled=true.
I struggling to find how I set the default value of stdoutLogEnabled prior to publishing. On .Net framework apps I would do this within the web.config file with transformations, however in .Net core I actually don't have a web.config file within my solution.
I've tried to find documentation on how to set the value, but it either doesn't exist, or more likely, I'm not using the correct search term. Can somebody please advise on how to set default values in the web.config.
Create a web.config and put it the root directory of your source, Modify the web.config file to enable logging and any other customization you need.
When you publish, it’ll use that file instead of generating a completely new file.

in the .net core,it has Web.config Transformation Syntax for Web Application Project Deployment?

Like this(this is asp.net web The program):
While web.config transforms are still an option, Asp.Net Core seems to be moving away from them for application-level configuration and instead using things like environment variables and config.json files.
For the JSON configuration file option, you are able to create multiple JSON files for each environment, and use an environment variable at runtime to determine which file is loaded. More information can be found here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration

wcf client configuration

I have wcf client. It uses .NET 3.5.
When I compile the client I get two files:
client.exe and
client.exe.config.
The second file contains configuration for the wcf client.
In my case I need to prevent the user sitting on the computer to see the urls and change some other parameters from the config file.
So the requirements are, the end user not to see and modify the data stored in the config. The config file contains the same data as app.config. I need to forbid the person using the program to see the end point urls so easy.
Also I have a lot of configuration there so I do not like to code in the moment.
Is there any solution for the problem (embedded app.config of something else)?
Edit: I do not need configurable options. The config file is automatically created when adding service reference from the studio.
Regards
You can also create your proxies programatically instead of using the service reference feature.
Every parameter in the serviceModel config section can be represented in code as well.
The ChannelFactory class will help you create proxies to the service.
You can easily encrypt entire parts of your config files - and not just web.config in web scenarios, but also application config's in stand-alone apps.
Check out some resources on how to do this:
Encrypting web.config values
Encrypting passwords in .NET app.config file
Encrypting the app.config file for Winforms application