Can we have multiple web.config files in a single project in c#?
if yes then what is its benefit?
Say I have a project ABC that has three folders under it.
Now ABC has its web.config file, so does each folder under ABC.
so there are total 4 web.config files.
So what will be the output when I run the project?
Yes you can have multiple web.config files in the separate folders. They can be used to enable/disable modules on a per folder basis. You can even set up each of those folders as separate web sites, even sub-sites, that use some modules from the parent web.config and some from the sub-site web.config.
I wrote up a blog post in the past about using BlogEngine.NET as the main site and configuring the web.config file in sub-sites. It might be of some help to you: http://markschlegel.com/post/2011/11/26/BlogEngineNET-a-sub-site!.aspx
Sure you can. An example of what this is used for is the default MVC 3 project template. There is one web.config for the site, and there is one inside the Views folder to deal with rendering the views.
Yes you can. The ASP.NET MVC project templates do this to restrict browsing the Views folder.
Related
Normally an ASP.NET MVC application can be deployed by placing the application folder in the virtual Directory.
The application folder contains
bin folder
Scripts Folder(If needed)
Views folder
Global.asax file
web.config file
But, I want to place the bin folder outside the application folder so that I can deploy more applications in a single application folder. All applications share the bin folder and session also get shared.
What I want to do
..Virtual Directory
..\bin
..\App1Name\App1Contents
..\App2Name\App2Contents
..\App3Name\App3Contents
..web.config
I already achieved this for web application with web forms without Global.asax file. But in MVC application I am unable to shared the bin folder.
How to achieve it?
Where I need to place the Global.asax file?
How the route all the applications with bin folder placed outside the Applications?
Thanks in advance
This is not possible. You were able to achieve this with Web Forms because each individual page is in effect it's own application. However, MVC works differently. Many factors, not the least of which is the routing framework, requires that the web application be secluded. You cannot deploy multiple MVC applications to the same document root. You can deploy a second MVC application to a virtual directory within the first, but be advised that the web.config of the outermost application will affect the inner application as well.
Based on the fact that your applications are sharing common binaries already, you may want to look into using MVC Areas to facilitate a logical separation between applications (but have them all as part of a single application). The following link describes this in more detail: MVC Areas
I am doing some research on how to make web.config dynamic per environment and brand. We have web.config different for different environments and brands.
Right now we make copy of it store a separate files and finally pick it manually and deploy.
I am finding various arcticles to do this and one the below has one solution.
http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx
I don't want any code or anything like but need some references if there are any other best industry practices
See http://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx for web.config transformations. Same concept. You have a base config file and then have specific nested config files per environment, brand or both. Depending how you deploy your application can affect how many web.config you have. In newer visual studio you cannpreview the changes as well by clicking on the nested web.config in solution explorer
App.config transformations aren't supported out of the box but with some msbuild events that's how wendo these ones
I have two separate solutions with web projects. I need to use one app setting in both. I don't want to duplicate this value in two web.config files - want to store it in one place (and not in machine.config!). These two web projects have other different appSettings and their web.config files are completely different.
Is it some way to share somehow just one appSetting between two web projects?
This link
explains how you can refer to another config file for some of the settings. The config file doesn't have to be stored in the same folder as your web.config file so you can share it with other projects.
At this moment I have 2 project that use the same content directory (scripts, static html, images etc etc). Is there a way to share this directory between the two projects instead of maintaining both duplicate directories?
When I publish one of the projects it needs to include that directory.
The two options that come to mind are mapping a static asset folder as an application within the website in IIS, or creating a virtual path provider.
Some VPP related links:
http://weblogs.asp.net/scottgu/archive/2005/11/27/431650.aspx
http://www.codeproject.com/KB/aspnet/Virtual_Path_Provider.aspx
http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx
I would like to have App_LocalResources folder outside web application folder, so that I could deploy updated resx files and web app. independent of each other.
Reasons: We do not want to change current deploy tool.
Any way to achieve this?
Way the default resource manager works in asp.net is it picks the resex entries for the respective aspx file from the App_LocalResources folder in the current directory. As far as I know this behavior is not something you can configure (i.e to ask it to pick entries from a different folder!) But there is a workaround, that you could implement your own Resource Manager and let it picks entries from a location you specify it to. Found this and this while googling. Hope that helps.