There is an ASP.NET application. It is referenced to a .NET project which has web reference to an asmx web service (for example this project is MyApp.Utility).
The URL to web service is stored in the application settings. There is such section in app.config for MyApp.Utility project.
<applicationSettings>
<MyApp.Utility.My.MySettings>
<setting name="MyApp_Utility_ExternalServices_SomeService" serializeAs="String">
<value>http://localhost:17455/ExternalServices/SomeService.asmx</value>
</setting>
</MyApp.Utility.My.MySettings>
</applicationSettings>
I want to change this URL in web.config for my ASP.NET application. Can I redefine application settings of MyApp.Utility without recompiling the code?
yes, you have stuff in .config files exactly so that you don't have to recompile to change stuff.
Depending on what kind of app and setup you have you might have to restart the application in order for it to read in the new values, but no recompile is necessary.
however:
if the .config file is for a non-website project (web.config) it will be called app.config and be placed in the project root. This is not the file being read runtime, the file actually being used is called ProjectName.dll.config and will be in the /bin folder next to the ProjectName.dll, when you compile the code msbuild copies and renames the app.config file into this location.
Related
OK, I'm totally confused. I need to update an old ASP.NET Web Application but I'm totally unfamiliar with Visual Studio...
The updated web app uses some DLLs which are compiled as part of the solution and placed in the web app 'Bin' folder. Two of these DLLs require other files in the same folder.
My problem is that, even though I publish the web app (locally for now) with the option "Precompile during publishing", at run time these DLLs are copied to the "Temporary ASP.NET Files" folder without their supporting files.
Is there a way to have ASP.NET use the DLLs in the 'Bin' folder without copying them somewhere else? Or is there a way to 'attach' the supporting files to the DLLs so that they get copied as well?
And no, I have no idea what I'm doing at this point...
I found this unanswered question that is essentially the same thing (answers talk about properties I don't have).
We ended up adding an appSettings key/value to web.config that the DLL use to find the required files.
<configuration>
...
<appSettings>
<add key="sExeFolder" value="C:\Project\Support_Files"/>
</appSettings>
...
</configuration>
I have a Visual Studio solution with 2 proyects:
Web Application
Library project for logging
My Web Application project doesn't have Log4Net reference. The Logging Project is the one that has the reference to the Log4Net dll and it has a Manager Class where I have all the methods for logging.
Now, I want to know what do I have to do in the Web Application WEb.Config file, I saw on the internet that I have to add a Section:
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net"/>
But my concern is that my web project doesn't have the Log4Net dll reference. Is there I way I can do that without adding Log4Net dll to my web project?
Yes, you can add the section element for log4net without referencing log4net.dll in your web application project.
To be sure, I double checked this with a scratch web application project (WebApplication1) and class library (ClassLibrary1) targeting .NET 4.0 in Visual Studio 2013. ClassLibrary1 referenced log4net.dll, but WebApplication1 did not; it just referenced ClassLibrary1 and had a log4net section element & related log4net element in its Web.config: logging to a text file via log4net worked beautifully.
It seems you have forgotten to configure log4net. Best practice is to add a configure attribute in your assably.cs:
// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
// Configure log4net using the .log4net file
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.ex
You can add the attribute in your log4net dll, there is no need for a reference to log4net in you web project.
I want to replace web.config with transformed for debug config file when running in Visual Studio( I am NOT interesting in publishing project to some output directory). I want to keep original web.config in the root of web application in TFS, but on runtime (on IIS or Cassini) I want to use transformed debug version.
The best approach that I found so far (in Use Visual Studio web.config transform for debugging and ASP.NET Web Projects: web.debug.config & web.release.config ) is to use web.template.config as a master file, and web.config as derived transformed file.
I am not fully happy with it, because developers use to consider web.config as a master file.
I have an idea to output transformed file to ASP.Net temporary files directory, that ASP.NET used for cached files.
Does ASP.NET use web.config file from temporary cache folfder?
Will ASP.NET allow to have web.config file in cache directory different to web.config in original folder?
I found a couple properties, related to ASP.Net temporary files directory.
MSBuild tempDirectory property of the CompilationSection can be used to replace root folder of ASP.Net temporary files.
ClientBuildManager.CodeGenDir Property gives access to specific folder where current cache is located.
However I could not find, how to access path of the folder from MSBuild and will it allow me to output transformed web.config to cached folder.
Any suggestions/considerations will be appreciated.
The debug and release templates of the config file are used when you deploy the application. Can you use the publish option to publish the application to another virtual directory on your machine for debugging purposes? Then, you would have the transformed config file.
I am working on an ASP.NET project in Visual Studio .NET 2010 and attempting to make an MSI installer using a Web Setup Project. I added the Primary output from the project (which seems to pull in the relevant dependencies) and the Content Files from the project (which pulls in the Web.config and the .svc files).
The issue is that rather than applying the XDT transform and creating the Web.config using the Web.Release.config, it just copies the Web.config, the Web.Release.config, and the Web.Debug.config into the installer without doing any transformation at all.
How do I get it to apply the Web.config transformation before creating the installer?
I found a workaround that works for me:
Create needed configurations (Dev,QA,Production etc.) and associated web config transformations.
Use notepad or other text editor and include following in your web application project file (.csproj file) before tag (near the end of the project file):
<Target Name="AfterBuild">
<TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="Web.Transformed.config" />
</Target>
Do not include Web.Transformed.config in the web application project - if you do visual studio will alert you about the changes after every build which is pretty annoying.
In the web setup project:
select Content files - > Exclude Filter and add Web.config (and all other Web.*.config files containing transformation rules).
In the web setup project:
select file system editor icon -> web application folder -> Add File
and select Web.Transformed.config in the root of your web application project folder.
In the same screen: right click Web.Transformed.config and rename it to Web.config
Now you are able to generate .msi files with selected configuration and root web.config file is transformed!
Please note that this does not affect web.config files in the sub folders.
The answer ended up being located on another SO post which I missed when I was searching through before asking because it wasn't exactly what I wanted:
MSBuild Script and VS2010 publish apply Web.config Transform
A co-worker suggested using that to place the transformed Web.config in the project's bin directory and a Web Setup Project configured to grab the Web.config out of the bin directory and put it in the installer. This ended up being the most workable solution without installing any add-ons into Visual Studio.
You have to make a deployment project (I think this is a separate download), then your Web Setup project take the precompiled output of the deployment project as it input. One neat thing is that you can have it change a section of your Web.config when it builds.
when building a desktop app in wpf can you read documentation of problems and safely subsititute 'app.config' when people's answer's refer to 'web.config'?
if so are there any glaring GOTCHAS you have to look out for?
tnx
Read the Documentation:
Web.config and App.config
The choice of the
configuration file name is determined by the hosting environment you
choose for the service. If you are using IIS to host your service, use
a Web.config file. If you are using any other hosting environment, use
an App.config file.
In Visual Studio, the file named App.config is used to create the
final configuration file. The final name actually used for the
configuration depends on the assembly name. For example, an assembly
named "Cohowinery.exe" has a final configuration file name of
"Cohowinery.exe.config". However, you only need to modify the
App.config file. Changes made to that file are automatically made to
the final application configuration file at compile time.
In using an App.config, file the configuration system merges the
App.config file with content of the Machine.config file when the
application starts and the configuration is applied. This mechanism
allows machine-wide settings to be defined in the Machine.config file.
The App.config file can be used to override the settings of the
Machine.config file; you can also lock in the settings in
Machine.config file so that they get used. In the Web.config case, the
configuration system merges the Web.config files in all directories
leading up to the application directory into the configuration that
gets applied.
Web.Config is used for asp.net web projects / web services.
App.Config is used for Windows Forms, Windows Services, Console Apps and WPF applications
Your question isn't providing all the information as to where the gotcha's may lie for you.
Can you give us more info on what you are trying to do in terms of these config files?
Here's a link...
Problems with Web.config and App.config