Kevin Dente's Blog

The Blip in the Noise
The trouble with web.config

Am I the only one that has issues with the way web.config is implemented in ASP.NET web apps and web services? The idea of a central, extensible XML config file that automatically detects changes is a great one. But the fact that ASP.NET restarts the application any time the file changes - isn't that a little heavy handed? I realize that it tries to handle the restart as gracefully as possible, spinning up a new instance of the application while allowing the old one to die out after it processes any pending requests. But restarting the application has a couple of nasty effects - namely, the application loses its cache and in-memory session state. In my case, the web service that I work on stores a bunch of data in cache that can be expensive to fetch. Dumping the cache can have a significant performance impact as the server rebuilds it.

Now, I'm sure that there are times when restarting the application is absolutely required. But why should the application have to restart just to add a trace switch, install a trace listener, or tweak some minor application setting? The only solution is to create a separate, custom application configuration file and hooking up the file monitoring by hand.

I can imagine a couple of possible solutions. ASP.NET could support a separate config file that holds configuration settings that don't require a restart. Or, even better, it could know which web.config settings require a restart and act accordingly (flagged by an XML attribute, for example). I haven't looked at Whidbey enough yet to know if they've addressed this issue. I hope so.

 

 


        

        

Published Sunday, November 16, 2003 5:07 PM by kevindente

Comments

# re: The trouble with web.config@ Sunday, November 16, 2003 8:16 PM

The Configuration application block allows you to have an external XML file from the web.config and not require a restart when its modified.

Its available on MSDN where all the rest of the application blocks are.

Paul Glavich

# re: The trouble with web.config@ Sunday, November 16, 2003 8:25 PM

I believe this will also mostly fixed in 2.0 as well. That is, there will be a number of sections where a change will not reset the application.

doug reilly

# re: The trouble with web.config@ Sunday, November 16, 2003 9:02 PM

This is fixed in ASP.NET 2.0.

But in the short-run, why not just store your own items in a custom config file and use your own CacheDependency to monitor changes?

On another note, how often do you really need to make changes? I always thought of the config section as a place to store machine/application related settings that really did not need change all that often.

-Scott

Scott Watermasysk

# re: The trouble with web.config@ Sunday, November 16, 2003 10:27 PM

Paul - I've tended to avoid the app blocks for non-internal applications. I've had the sense (perhaps unfounded) that there's a weaker commitment to ongoing maintenance and backward compatibility. Maybe that's just NIH syndrome silliness. :)

Scott - good news that it's fixed in 2.0. One of these days I hope to have time to really dig into Whidbey. Too busy right now, unfortunately.

Tracing is a good example of where web.config is changed on a running system. Debugging a production server by setting up trace switches to enable diagnostic logging is quite common. Dumping the cache to enable this is not ideal. BTW, that's also an example of where a custom config file isn't useful - the framework always uses web.config to control traceswitch behavior.

I like the idea of using a faux CacheDependency with a callback, though. That's a bit easier than setting up a FileSystemWatcher.

Kevin Dente

# re: The trouble with web.config@ Monday, November 17, 2003 6:05 AM

Not an issue because the use of Session variables is, overall, a bad architectual choice.

Wally

Wallym

# re: The trouble with web.config@ Monday, November 17, 2003 9:03 AM

You can always reference your appSettings from an external file:

http://weblogs.asp.net/pwilson/posts/5261.aspx

Kirk Allen Evans

# re: The trouble with web.config@ Sunday, January 18, 2004 11:34 PM

have problem with web.config

can somebody help me pleaseeeeeeeeeeeeeee??

aljosa

www.runtothe101.com/mail/

aljosa@cox.net

# re: The trouble with web.config@ Monday, January 26, 2004 11:43 PM

tell me how to fix web.conf under taxslayer.com

BrTrac4

# re: The trouble with web.config@ Thursday, May 20, 2004 8:13 PM

I have a small issue with web config.....Everytime I go to a specific location, I get this

http://www.page.com/directory/(oiuoi23oiuoiu23)/index.html

my question is...how do I set up web config so it doesn't show that session ID number
(oiuoi23oiuoiu23) ??

CheX MiX

# re: The trouble with web.config@ Tuesday, June 15, 2004 5:12 PM

You just have to turn off cookieless sessions in the web.config. Beware that this may cause you other problems that you don't want to encounter either. You only need to have cookieless sessions enabled if you don't want to require your users to have cookies enabled on their browsers.

KMPDEV

# re: The trouble with web.config@ Thursday, June 17, 2004 5:12 AM

What about performance issues?

I've written my own procedure to deal with constants in my web application. An xml file are loaded in a static / shared class, and the values can be accessed by specifying XPath. Since it is in a static / shared class, it will be loaded initially only (resided once only in memory over all class instances), except if the file's modified date changes, it will be reloaded - obviously without having to restarting the application.

Here is the code in VB.NET:

------------------------

Public Class INIHandler

Private Const strINIFile As String = "c:\Wherever\INI.XML"
Private Shared objFile As File
Private Shared INIFileLastModifiedDateTime As Date
Private Shared oXMLTextReaderINI As New XmlTextReader(strINIFile)

Public Shared oXmlDocumentINI As New XmlDocument()

Shared Sub New()
oXmlDocumentINI.Load(oXMLTextReaderINI)
oXMLTextReaderINI.Close()
INIFileLastModifiedDateTime = objFile.GetLastWriteTime(strINIFile)
End Sub

Public Shared Function GetFromINI(ByVal SubXPath As String) As String
If objFile.GetLastWriteTime(strINIFile) <> INIFileLastModifiedDateTime Then 'Refresh the INI XML File contents
oXMLTextReaderINI = New XmlTextReader(strINIFile)
oXmlDocumentINI.Load(oXMLTextReaderINI)
oXMLTextReaderINI.Close()
INIFileLastModifiedDateTime = objFile.GetCreationTime(strINIFile)
End If
Return XMLHandler.GetValue(oXmlDocumentINI, XPath) 'Returns the value from the xpath reference
End Function

End Class

------------------------

Then I will use the web.config purely for configuration settings only.

This works very confeniently, the question(s):
What are the differences in performances / confenience or ease of use between this procedure, and the web.config? ...if say, for instance I rather use the web.config to add all these constants or not?

Ferdie@Cipro

# re: The trouble with web.config@ Thursday, June 17, 2004 5:24 AM

Sorry, the code for line in the function decleration of function GetFromINI reads:

Public Shared Function GetFromINI(ByVal XPath As String) As String

and not

Public Shared Function GetFromINI(ByVal SubXPath As String) As String

Ferdie@Cipro

# re: The trouble with web.config@ Tuesday, July 06, 2004 3:08 AM

Hi,

We have used your "URL Rewriter" Program on some of our websites to convert Dynamic URLs into static URLs. I mean that in global.asax file Application_BeginRequest calls the function of the "ThunderMain.dll" which interprets the Rules written in web.config file.


We are using it for the past 10 months and it runs correct with almost all the site except one for which we have lot of Rules in web.config though it was running ok for last month as and when we added some rules its behavior become strange.

When i upload it or restrats the application, runs very well with all rules but after 10-12 hours it automatically fails for the URL added last and says resources not found 404 Error which indicates the Rule written for that URL is not being interpreted.

Please Help. Is there any way to refresh the web.config after sometime because it runs when i upload the same web.config file again or restarts the server.


The type of URLs added are as:

<rule>
<url>/(.*)/mBoatsbyCategory\.aspx</url>
<rewrite>/mboats_category.aspx?manufacturer=$1</rewrite>
</rule>

It is run with the URL http://www.boatquest.com/Sea-Ray/mBoatsbyCategory.aspx

A single word from you may help me, Please respond.

Shri Pal

# re: The trouble with web.config@ Monday, December 17, 2007 11:39 AM

airlines quantas australia <a href= quantasairlines.eamped.com >airlines quantas davies</a> [url=quantasairlines.eamped.com]airlines quantas davies[/url]

ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname

# re: The trouble with web.config@ Friday, February 08, 2008 5:53 PM

formula sell annuity <a href= sellannuity.forumvila.com >information sell annuity</a> [url=sellannuity.forumvila.com]information sell annuity[/url]

ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname

# re: The trouble with web.config@ Thursday, February 21, 2008 4:53 PM

airlines quantas air <a href= quantasairline.forum5.com >quantas australia airlines</a> [url=quantasairline.forum5.com]quantas australia airlines[/url]

ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname

# re: The trouble with web.config@ Friday, April 04, 2008 1:59 AM

corporation experian <a href= http://experian.2page.de >experian credit</a> [url=http://experian.2page.de]experian credit[/url]

ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname

# re: The trouble with web.config@ Saturday, January 03, 2009 9:50 AM

power car amplifier audio <a href= klasaqw2009.blogspot.com >1 amplifier car audio</a> [url=klasaqw2009.blogspot.com]1 amplifier car audio[/url]

ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname

# re: The trouble with web.config@ Monday, February 16, 2009 1:05 AM

tonik health plans <a href= community.fotopic.net/.../yyom9z.html >plans health tonik</a> [url=community.fotopic.net/.../yyom9z.html]plans health tonik[/url]

ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname

# re: The trouble with web.config@ Wednesday, July 29, 2009 2:22 PM

So where it to find?,

name

# re: The trouble with web.config@ Wednesday, July 29, 2009 5:50 PM

I bookmarked this guestbook.,

name

# re: The trouble with web.config@ Wednesday, July 29, 2009 9:09 PM

Where it is possible to buy the,

name

# re: The trouble with web.config@ Thursday, July 30, 2009 3:50 AM

Your Site Is Great,

name