Use a dynamically generated file as configSource in web.config - asp.net

Is there a way to use a generated file as a configSource for a web.config section?
In web.config, I tried a simple:
<webParts configSource="webpartsConfig.aspx" />
where webpartsConfig.aspx just spits out XML when accessed normally, but not as a configSource. (The literal source code is included as-is, giving an error.)
Any solutions or alternatives?
Motivation for this solution: I have different configuration variables locally and online, and I don't want to juggle multiple config files.

Hopefully this doesn't come too late to help, but I would suggest looking at an adaption of the source used in Enterprise Library. Details - http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx
Then you would be creating a custom ConfigurationSource that reads HttpWebResponses.

Related

Web.config replacement, missing section

I've spent a day on this 'simple' problem...
I'm using Web Deployment Projects to deploy my MVC3 webapp. I tell it to replace the appSettings section with one in a config file by entering
appSettings=Config\AppSettings.Production.config;
That works perfectly. The resulting (deployed) Web.config file has been correctly transformed and now contains the production settings I told it to use.
But, trying to do the same thing with a custom section 'spring' using exactly the same method
spring=Config\Spring.Production.config;
...I get...
web.config(1): error WDP00002: missing section spring
The spring section is at exactly the same level as the appSettings element, so I don't know why it doesn't work.
There are loads of other people with the same problem, but no satisfactory answers that I can find.
The correct syntax to reference external file is like this:
<spring configSource="Config\Spring.Production.config" />
The file="Config\AppSettings.Production.config" syntax that works with appSettings section won't work with custom sections as far as I remember, as they don't implement such property.

Can I alter an aspx.vb file on the fly on a live website?

I need to know if it recompiles my site at all or if there are any issues doing this. I have tested the changes locally and in a test environment and I don't want to do a full deployment for one tiny change. I'm just not familiar with aspx.vb files and how they interact with a website.
The short answer is yes, it will cause the page to be dynamically recompiled. Dependencies could cause the entire site to be recompiled.
For more information read this MSDN article: Understanding ASP.NET Dynamic Compilation. The "Recompiling on Change" section addresses your question.
You can modify an .aspx.vb file and drop it into its respective location on the server, overwriting the existing file, and it will be dynamically compiled due to the change. However, if you were referring to having code that changed .vb file content on the fly, that sounds like a bad idea and you should reconsider your problem and approach.

What exactly does the staticcontent tag in the web.config file apply to?

I've been reading about the staticContent element in the web.config file but I'm having a bit of trouble figuring out exactly what ASP.Net considers static content. I assume it's going to include images, js files, css and static html files but I can't seem to find any articles that explicitly state this. Does anyone have links to documentation that explains this in detail?
I think this may be the information you're missing - Static Content MimeMap
Whilst this question is rather old and I expect Kiquenet got it sorted out none of the answers actually answer the question, I found this article looking for the answer, I expect others will to. This article answers the question:
IIS and Static content?
To paraphrase, static files are those IIS does not have a specific handler for. i.e. every file type listed in the .Net framework web.config section httpHandlers is NOT static.
Please look at Ben Swayne's most excellent answer, to quote:
You can inspect the list of file handlers in IIS by navigating to your website and then click 'Handler Mappings'. By default these are inherited from the .Net base web.config which is in a different location depending on your .Net framework version.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config
If a file being requested isn't already explicitly mapped to another handler it falls to a catch all handler (*) as the last option (System.Web.DefaultHttpHandler) which determines if it is a static file or a directory browsing request. So Static files are simply files not bound to another handler already.
As I understand it, the staticContent element in the web.config is where you can set how your site should cache it's static resource.
So as to your question of what kind of content can be specified here, it would be any file that you could benefit from caching, i.e. images, video, etc.
Also, just to provide some links I found useful:
How to configure static content cache per folder and extension in IIS7?
http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache
http://www.iis.net/configreference/system.webserver/staticcontent/mimemap says,
The <mimeMap> element of the <staticContent> element is included in the default installation of IIS 7.
IOW the list of 'static' file types is I suppose defined in the server's machine.config and/or overriden using web.config files.
You can select "Mime Types" in IIS Manager to view the list of MIME Types ... I see about 400 of these, from .323 and .aac through to .xslt and .zip, including .htm and .html but not including .aspx.

Modifying Root Web.config in code

I would like to store some meta-information about a given site instance that can (a) be managed by that site instance and (b) persist clobbering of Web.config file.
The site will run in multiple environments (dev,testing,staging and production) and each environment can have different values for this metadata.
Note: All environments are running IIS 7.0+
The Root Web.config seems very appealing, as it is certainly outside of the website. Therefore, both files and databases can be changed while maintaining the metadata. I have seen how to modify the appSettings of the Web.config stored in the website, but is it possible to similarly modify the appSettings in the Root Web.config (Specifically within the proper directive)?
If you have other suggestions of approaching this problem, I would be very happy to hear them. Thank you!
would not use web.config for runtime modifications, that will cause the application to recycle, perhaps some other form of configuration file like app.config
if my assumption is incorrect and the web.config will not be edited after the application is started, then you can use WebConfigurationManager to access the file sections
Yes you can modufy the app settings within your web.config Just use the WebConfigurationManager class in the System.Web.Configuration namespace to create a Configuration object. This object could then be used to read and write changes to the web.config file.
You could then create your own "keys" or attributes that could be read as needed.
Depending upon what your attributes represent or if they need to be picked up by multiple environmnets from that server I would also look into making the modifications within the machine.config file as then those settings would apply to the enter machine and thereby picked up by multiple environments( if you are hosting multiple webapps from the server). This could save you time in modifying multiple web.config files and narrorw the storage or the metadata to one location vs. multiple config files in certain situations.

Drupal's JS and CSS optimization error

I started getting errors after I turned on Drupal's performance improvements which pack all the CSS and JS files into single files. The error looks like this:
The selected file /tmp/fileO4fjBF
could not be uploaded, because the
destination
js/js_8a69e612be02242c2866a4a19223bd12.js
is not properly configured.
I'm not sure how I should configure my server for this to work correctly. There is nothing in the documentation about this.
Check you ' Site Configuration > Files' settings or the report. If it is a file permission issue (or maybe a missing folder) it should be apparent from one of those two places.
Often the report or files-settings also supply information on how to remedy the problem.

Resources