Can an ASP.NET web app run without web.config - asp.net

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

Related

Overriding web config file at the time of deployment in ASP.NET and IIS

We are using ASP.NET for our web application which is hosted in IIS 8.5. ASP.NET uses a web.config file to store all application and IIS related configurations. Whenever we deploy a new version of code for the web application, we also deploy the web.config file.
Recently the operation team has raised a concern to this deployment process. They say, if someone change some settings in IIS and for that web.config has been updated for that, there is no way for the developers to know that change so that they can update the web.config in codebase (version control system). So eventually at the time of next deployment the web.config changes will be overridden by the old web.config.
There are two possible solutions can be taken:
Merge the web.config with server and codebase before deploy the code everytime.
Decouple the application configuration and IIS configuration in different configuration files.
My question is, what is the best practice to solve these kinds of problems in ASP.NET?
IIS 7+ introduced its distributed configuration which allowed for IIS as well as .NET configuration to live inside of Site/App/Directory web.config files. One of the primary reasons for this is as follows: In IIS 6, whenever an application team needed to deploy their application and make changes to settings like Default Document, they needed the IIS team involved because "Default Document" was an IIS configuration setting. You could argue that Default Document settings for a particular application is not IIS configuration, but instead is Application configuration. As result, the Application Team should own that configuration setting and deploy it as part of the application.
A bit more about IIS7+ configuration system: Administrators are able to configure what settings are allowed to be set inside Web.config files. For example, by default, "Default Document" is able to be set inside Web.config files, and Authentication settings like Windows Authentication are not. The implementation can actually get complex, but if you'd like to read about it, you can see it here: https://learn.microsoft.com/en-us/iis/get-started/planning-for-security/how-to-use-locking-in-iis-configuration.
Ultimately the best practice is for IIS Administrators to configuration the settings they want Application teams to manage (by delegating those settings to Web.config) and then not touch them. In other words, if Default Document needs to be updated, then it is the Application Team's responsibility and they publish a new web.config file. If the IIS team decides they want to manage Default Document, then they need to lock down the IIS configuration system to prohibit Default Document from being managed in the web.config files.

How do you check the ASP.NET sessionsState mode on a web server?

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

Difference between web.config and machine.config?

What is the difference between web.config and machine.config?
I have read that:-
The web.config files specify configuration settings for a particular
web application, and are located in the application's root directory;
the machine.config file specifies configuration settings for all of
the websites on the web server, and is located in
$WINDOWSDIR$\Microsoft.Net\Framework\Version\Config.
Is there anything which I am missing or any other technical aspect? I want to know more about both the files.
Each CLR version has a machine.config file, along with an additional web.config file, which I refer to as the "machine level web.config file".
Additionally, as you note, each web application also has a web.config file. Directories inside a web application can also have web.config files too.
Now, the key point is that config files inherit from each other. That means, a web application will read settings defined in the machine.config file and the machine level web.config file (for its given framework version), and its own web.config file.
A common use case for defining things in the machine.config would be to share values between many applications on the server, like a connection string perhaps, or SMTP server settings, things like that.
Those are some of the most important details; although actually, machine.config goes beyond simply configuration for ASP.NET itself. There is another file you should look into, which (I think) is in the same location as machine.config; that is the 'root' web.config, which goes between machine.config and the site-specific web.config files, and is, of course, ASP.NET specific.
Some of the settings you change at the server level in the IIS management console are performed in the root web.config.
Note that this hierarchy is per-.NET version; (2.0 has one; 4.0 has its own)
Another note: You can have sub web.config files in directories and/or sub-applications off a site's root which further modify the 'base'.
Finally, one caveat: Not all settings can be overridden in sub-level web.config files. It is possible (and some are, by default) to lock down certain settings at any level of the hierarchy described here.
Let me clear it out:-
in ASP.NET, there is a configuration files hierarchy and machine.config file lies at the root
meaning machine.config file contain configuration settings that are applied on each web application, you created. It exists in Windows/Microsoft .NET/Framework/[version]/config
You will find a web.config file in the same physical path(I give it name A).This web.config file inherits configuration settings from machine.config.now you have your application folder in which you have web.config(at root level). This web.config( I name it B) inherits configuration settings from A. If you have web.config in application folder's sub-directories than sub-directory web.config inherits configuration settings from B and that is how the ladder goes down
The machine.config is the ultimate master config file on your system with a lot of default settings. When you use web.config files, which is done in a cascading order, you're actually overwriting these settings with new ones.
Machine.Config
This is automatically installed when you install Visual Studio. Net.
This is also called machine level configuration file.
Only one machine.config file exists on a server.
This file is at the highest level in the configuration hierarchy.
Web.Config
This is automatically created when you create an ASP.Net web application project.
This is also called application level configuration file.
This file inherits setting from the machine.config

Do I need a web config file to run an asp.net hello world on IIS 7?

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.

Where is Vista IIS7 "master" config file stored at?

In IIS7 for Vista, you can select your machine and it gives you several options in which you can use to configure your system. Where is this file stored at? It seems like there's a big master.config file which stores all my settings like the "Connection Strings" which are inherited by the webpages.
Supposedly it's some file named machine.config but nothing I change in the IIS manager for my machine changes there.
If you're talking about machine-wide ASP.NET configuration, look under your .NET framework config directory, e.g. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG - check web.config and machine.config for the settings you've been configuring.
(Note: this is a bit of an educated guess. Don't take it as definitely correct without checking. Unfortunately I can't do so myself at the moment...)
"Connection Strings" do seem to be in the web.config file
There can be multiple web.config files in a single web project (but not in a single directory), but here, you are referring to the configuration system files, including:
windows\microsoft.net\framework\v2.0.50727\config\machine.config: Holds the global defaults for the .NET framework settings, including some of the ASP.NET ones
root web.config: same location, with the rest of the settings.

Resources