Web API using Web.Config file of another Web API project - c#

I have two web api projects
Yugasat.Authentication.ServiceLayer
Yugasat.User.ServiceLayer
each with its own web.config files
For some reason the Yugasat.Authentication.ServiceLayer project is using the web.config file of the Yugasat.User.ServiceLayer project. When I add invalid text to the web.config file of the Yugasat.User.ServiceLayer project
and run the Yugasat.Authentication.ServiceLayer I can see that it is using the wrong web.config file
Is there any reason why this will happen?

Related

How can I add an app.config or web.config file in Visual Studio Web 2013?

This has been frustrating me for the past hour. My project is like
MySolution
MyTestProject
ClassThatTestsMyRepository.cs
MyMVCProject
App_Data
App_Start
Controllers
.
.
and the root of my problem is that my tests in the other project aren't working because they're trying to access a connection string that is in the MVC project itself. My plan was to add an app.config file and then reference the web.config in the MVC project. However, when I go to Add -> New Item there are no configuration files in Installed or Online.
screenshot
The only reason there's a web config in my MVC project is because it was built from a template that added it. Any ideas how I can add it to my test project if I can't add it through stupid VS Web 2013?
It is just an XML file called "web.config" placed at the root of your MVC project.
Then you can just create a new text file and rename it.
if the project is a console app or a test project, the name is App.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="Default" connectionString="xxxx" />
</connectionStrings>
</configuration>
Right click your project and select Add New Item...
Look for a template called Application Configuration File for local apps or it will be under Web Configuration File for ASP.NET projects.
Choose the default name and press Add
Relevant Microsoft Article

How to call app.config from c# code when using 2 config files

I have 2 config files in my application. When getting values from Web.config, I am using the below in c# and I get the values. But I am not sure how I can get some of the values from app.cofig.
ConfigurationManager.AppSettings[xsdSchema]
Appreciate the help.
App.config file is used in desktop/console applications. Web applications use web.config file. So you cannot use both in the same project.
However you can extract a web.config section into a separate file.

Read web.config from library consumed by the webapplicaion deployed using IIS

I have a web application deployed on IIS. This web application is consuming a library which wants to access the Web.config.
Example :
Foo.dll is the web application deployed on IIS
Foo.Utility.dll is consumed by Foo.dll
There is a piece of code in Foo.Utility namepsace which wants to access the web.config from Foo application and read the config values
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
string cacheDir = config.AppSettings.Settings["abc"].Value;
Currently config.FilePath = C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
Changed my code to :
Configuration config = WebConfigurationManager.OpenWebConfiguration(Assembly.GetCallingAssembly().Location);
string cacheDir = config.AppSettings.Settings["abc"].Value;
Now my Assembly.GetCallingAssembly().Location is : C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\62f5c902\849205ff\assembly\dl3\c28d4647\10e128d3_7449d001\foo.dll
Can someone help me to understand how to read the web.config from the place where my application is deployed using IIS?
For more information or if the question is not clear then comment below. Will update it
You have to use ConfigurationManager from System.Configuration. First, you'll have to add a reference to System.Configuration.dll assembly, and then use it like this:
using System.Configuration;
...
string valueOfAbc = ConfigurationManager.AppSettings["abc"];
ConfigurationManager will read the config file from the application's host. In your case, the web.config file.
Reference:
ConfigurationManager Class
Application Configuration Files

Accessing .net Web.Config in AngularJS project

I have an AngularJS project in "empty" type .net project, which is hosted on IIS with .Net 4.0 framework. I basically don't use any .net dlls but since the project has a web.config file i add some App setting to use in the project. Trying to set development/production setting.
Is there a way to access AppSettings in the .net web.config file from AngularJS, because i am not using a MVC project, I can't use razor (#System.Configuration.ConfigurationManager.AppSettings["url"]).
Is there another way to this?
Thanks
You don't.
The Web.Config file is a server-side configuration file, AngularJS is a client-side framework.
You can't access it from the browser, because IIS will never - for security reasons - serve it to clients.
You may want to expose a WebApi controller or MVC controller that returns JSON that represents web.config file... or at least the JSON object that has the data in the web.config file you need to send to client. The WebApi controller would read from web.config via configuration manager, convert to JSON, and send to client.
I am doing something similar where I am storing my service endpoints that my angular app needs in my web.config, but I want to transform the .config files based upon debug, dev, staging, production etc.

loading dll config file when it is referenced in web services

I have created a WCF web service which has references to some class library (BO.dll,BLL.dll,DAL.dll) ,and invoke their methods . one of the libraries(DAL.dll) need a config file to read some settings like connection string . then the config file is located near to the dll files .
but when I use the service, it has error which the "could not find file C:\windows\microsoft.NET\FrameWork\v4.0.30319\Temporary ASP.NET Files\SampleService(some temp folder)\myConfigFile.config"
I should say that, dll code read the config file as a simple xml file. and extract the settings.
why it looks for in this address ?
where should I put the config file to be accessible by the dll ?
It is because for DLL you need to use your webservice's configuration file for DLL if you are reading connection string using
System.Configuration.ConfigurationManger.AppConfig class.
Otherwise you can reading manually.
This link might help you
Reading dll.config (not app.config!) from a plugin module

Categories

Resources