I have a web.config file defined in my asp.net web application. I have many different settings configured there.
I have another project, this time a console application. I'd like to read several configurations from my web.config file. How can this be done?
Thank you
Check out this article.
Does exactly what you want.
Basically you "delegate" sections of your config file to another file.
In your case you would delegate sections of your config file in your console app, to read the settings from the web.config in your web app.
Related
I have a ASP.NET 4.0 web application that doesn't specify the sessionState mode in any of its web.config files.
This application is running on my company's web server, which I have very limited access to. Is there any way I can check which sessionState mode my web application is running in?
I am aware that 'InProc' is the default sessionState mode in ASP.NET. But I uncertain if anyone has overwritten the root config files (machine.config or root web.config, etc) on the company's web server. Note that I don't have direct access to the server, so I need write a list of places/files to try. And obviously, I can't put in any test code in there to find out.
I also tried search in the config files where the default 'InProc' mode is specified, but I couldn't find it anywhere. Any help would be much appreciated. Thanks!
Server-level configuration is stored in the following configuration files:
Machine.config. This file is located in %windir%\Microsoft.NET\Framework\framework_version\CONFIG.
Root Web.config for the .NET Framework. This file is located in %windir%\Microsoft.NET\Framework\framework_version\CONFIG.
ApplicationHost.config. This file is located in %windir%\system32\inetsrv\config.
And finally you would want to check the Web.config of your application.
Source
Can my asp.net web application run without a web.config?
For argument's sake lets say that I'm not connecting to a Database or explicitly reading any
configuration information .
I have tried it out and I'm able to run a web app successfully in VS 2008 without a web.config.
This brings me to the question as to how are authentication and session modes configured now ?
The machine.config and the root web.config files ( in the framework folder) do not have any authentication/session modes configured explicitly .
Any ideas ?
Thanks.
yes we can run asp.net application without web.config file,if u r not configure any settings in web.config file then it will take machine.config file for default configurtaons.This config file will automatically installed when your application getting executed.
Because all the configuration settings will be available under MACHINE.CONFIG file by default these settings will be applied to all asp.net applications.
You'd have to read the documentation to see the defaults, which for authentication is probably windows, and session mode would be in process.
Yes, you will be able to run an ASP.NET application without a WEB.CONFIG file in its root folder.
If the application doesn’t find a WEB.CONFIG file in its root folder, then it will take MACHINE.CONFIG file for default configurations. But you will not be able to debug the application as debugging is turned off by default in MACHINE.CONFIG file.
Find more information about machine.config files over here
I am using a 3rd party component which creates settings files based on hard-coded file paths i.e. they are compiled into the DLL e.g.
%APPDATA%\Vendor\Settings.ini
I have created a few console/service applications that use this and work very well. However, I am now trying to use a similar approach via my ASP.NET MVC web application and the settings file never seems to write out!
Usually if the application is running under my acconut for example the file would be written to somewhere like:
C:\Documents and Settings\James\Application Data\Vendor\Settings.ini
So I thought if the website AppPool was running under the same account the file would be saved to the same place....However, it never appears. The account is an admin account running under Windows server 2003.
Any ideas?
Thanks.
Have you checked to see if the settings file is created in the App_Data folder in the web application? If not, could you put an existing settings file there and see if it uses it?
It's not about the webpool account, it's about guest user's account.
Go to the properties of your site in IIS, Directory Security and in the anonymous access click on the Edit button, there you'll see wich account is been used when someone access your site.
Couldn't find a solution to this, so I decided to develop a local WCF service (which would create the settings file in the correct directory path) and just accessed it via my web application.
I have uploaded a simple hello world on my IIS server 7 (shared hosting). It doesn't work. Is it necessary to add a web config and what's the minimum in that case ?
Thanks.
Error says:
Server Application Unavailable
The web application you are attempting
to access on this web server is
currently unavailable. Please hit the
"Refresh" button in your web browser
to retry your request.
Here's the script, very basic :)
<%# Page Language="VB" %>
<html>
<head>
<title>ASP.NET Hello World</title>
</head>
<body bgcolor="#FFFFFF">
<p><%= "Hello World!" %></p>
</body>
</html>
A individual, site-specific web.config is not required to be present in order to get a basic "Hello World" site up and running in IIS7, however, it's rather unusual not to have one.
IIS7, unlike previous versions, effectively has the ASP.NET worker process component "built-in". This allows web.config files to specify configuration of not only your ASP.NET site itself, but also how the IIS server hosting your site should be configured (i.e. you can specify (for example) the default document type in an ASP.NET web.config file).
If you don't specify an individual web.config for your ASP.NET site, the IIS7 server will use the "default" web.config, which is usually located in your "windows" folder within the system-wide configuration of the .NET framework itself.
This article:
Working With Configuration Files in IIS 7
from the MSDN library states:
Configuration Files
Configuration exists in a physical
directory in either server-level
configuration files or in Web.config
files. Every configuration file maps
to a specific site, application, or
virtual directory.
Server-level configuration is stored
in the following configuration files:
Machine.config. This file is located in
%windir%\Microsoft.NET\Framework\framework_version\CONFIG.
Root Web.config for the .NET Framework. This file is located in
%windir%\Microsoft.NET\Framework\framework_version\CONFIG.
ApplicationHost.config. This file is located in
%windir%\system32\inetsrv\config.
Site, application, and virtual and
physical directory configuration can
be stored in one of the following
locations:
A server-level configuration file. When configuration for a site,
application, directory, or URL is
stored in a server-level configuration
file, you must use a location tag to
specify the site, application,
directory, or URL to which the
configuration applies.
A parent-level Web.config file. When configuration for an application,
directory, or URL is stored in a
parent-level configuration file, you
must use a location tag to specify the
child at which the configuration
applies.
The Web.config file for the site, the application, or the directory.
When you configure settings for an
application, directory, or URL, the
configuration is stored in the same
directory as the site, application, or
directory. You do not need to use
location tags.
Storing configuration settings in a
parent configuration file is helpful
when:
You want to store configuration settings in a configuration file that
is accessible by only certain users or
groups. For example, the
ApplicationHost.config file is
available only to the Administrator
account and to the members of the
Administrators group on a specific
computer, as well as to domain
administrators when a computer is part
of a domain.
You want to configure a feature at the URL-level (also known as
file-level).
Also, see the following article for further information:
The new Configuration System in IIS 7
EDIT:
Regarding the specific error message that you're getting, I've seen this before on an IIS7 server, and the problem turned out to be the Application Pool that the site was set to use wasn't "running". Going into the IIS7 admin gui and starting the Application Pool cured the problem.
I have also seen this error caused wen the relevant permissions have not been set on the folder containing your website code.
See here, here, and here for further information.
Of course, since you're testing a shared hosting environment, you probably don't have access to the web server itself, and it's difficult to know exactly what you do have access to, administration-wise, through your hosting provider, but they probably have some kind of interface to set permissions on folders/files, so I'd look there first.
Failing that, you may have to include a web.config file in your "test" site as that will allow you to set configurations within IIS7 that you may otherwise have no access to.
Failing that, you may need to speak to your web host's support team.
It should be enough to inherit from machine.config. What's the exception?
I am not sure about the shared Hosting environment. But If you try to create a web application ( try ASP.Net Empty web application template) and just use Response.write("Hello World !") . it will work without any web.config.
I tried my self and it work successfully.
Only problem is that It may ask you if you wanted to debug your application then it requires to add "compilation = true" attribute in web.config.
I have an ASP.NET application.
It resides within another ASP.NET application.
I put my DLL in the other apps bin folder and have a subdirectory with my aspx files.
I can't edit the main app's Web.config.
So where can I store configuration settings?
For example, this is an app that will get deployed to various clients. I want to store the client name used for display in the headers and such. And the location of a logo file.
You can put a web.config file on the folder your ASPX files reside and .NET will take care of nesting them and aggregate its contents.
You can also just create a Settings.config XML file and put it wherever you want (the .config extension will prevent it from being viewable through an HTTP request), then wrap it with a Settings class and talk to that Settings class from your application.
You can use Settings.Settings to store it. This example might help. You can have multiple settings files and access any of them, just as you would for any other class.