Set the controls to lightly toasted muffins... RSS 2.0
 Tuesday, April 04, 2006

This is a pretty handy feature for taking your ASP.NET 2.0 app offline (for maintenance or whatever) and displaying a friendly message explaining why the site is down.

Just place a file called 'App_offline.htm' in the root of your site with whatever message you want to give your users and bingo your app shuts down and the contents of App_offline.htm are served. Just delete or rename App_offline.htm to something else to bring the app back online again.

 

Tuesday, April 04, 2006 12:31:19 AM UTC  #    Comments [0] -
.NET
 Monday, March 13, 2006

I don't know what the Attorney General is so upset about, isn't this what the Home Office wants for all our good citizens anyway? They just happen to be starting from the top.

Monday, March 13, 2006 12:34:20 PM UTC  #    Comments [0] -
Other

Wow...this guy had some imagination. One of my favourites is 'Earth Orbital Bombs As Nuclear Deterrents'.

Via: The Register

Monday, March 13, 2006 12:29:24 PM UTC  #    Comments [0] -
Other

You may know this already but if you're running ASP.NET 1.1 and ASP.NET 2.0 on the same box then make sure you create a separate application pool for ASP.NET 2.0. You can just clone the Default Application pool if you want, but that can have security implications if you're box is a shared hosting environment because re-using NETWORK SERVICE as the process identity will leave your 2.0 sites open to file harvesting by Full Trust 1.1 apps (that said you are encrypting your connection strings, aren't you? :-) ).

Once you've created the app domain, goto the site or vdir that needs to run ASP.NET 2.0, open the property pages, choose ASP.NET 2.0 from the ASP.NET tab then choose the new ASP.NET 2.0 Application Pool in Home Directory Tab -> Application Settings: Application Pool drop down.

Failure to run ASP.NET 2.0 in it's own app pool will result in the evil 'Server Application Unavailable' message because the ASP.NET 1.1 and 2.0 runtimes can't co-reside in the same worker process.

Monday, March 13, 2006 12:55:59 AM UTC  #    Comments [1] -
.NET
 Sunday, March 12, 2006

This is old hat and more of a bookmark for me when I bump into this each time I'm working with XML documents that have default namespace declared. But I thought I'd share anyway.

Take the following simple XML document:

<?xml version="1.0" encoding="utf-8" ?>
<
products xmlns="urn:backoffice:products"
>
   <
product id="100-1100"
>
      <
description>JVC CD Player</description
>
      <
price>120.99</price
>
      <
category>100</category
>
   </
product
>
   <
product id="100-1101"
>
      <
description>Sony CD Player</description
>
      <
price>122.99</price
>
      <
category>100</category
>
   </
product
>
   <
product id="100-1102"
>
      <
description>LG DVD Player</description
>
      <
price>109.99</price
>
      <
category>110</category
>
   </
product
>
   <
product id="100-1103"
>
      <
description>Technics DVD Player</description
>
      <
price>199.99</price
>
      <
category>110</category
>
   </
product
>
</
products>

You might expect that the code to select all the product nodes would look like:

XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace("", "urn:backoffice:products");
XmlNodeList productList = products.SelectNodes("/products/*", nsm);

The above seems the logical thing to do because the default namespace doesn't have a prefix so you naturally go ahead and specify String.Empty (or "", whichever) when adding it to the namespace manager. Additionally if you execute the code and breakpoint after setting adding the namespace and inspect the DefaultNamespace property of 'nsm' you'll see that it's even set to "urn:backoffice:products". However, the XmlNodeList returned from products.SelectNodes has no nodes.

This confused the hell out of me when I first encountered it way back when and I tripped up on it again last week. What's going on?

Basically XPath expressions select nodes that are either in a namespace or in the empty namespace. The XPath expression '/products/*' is selecting nodes from the empty namespace (xmlns="") but the document above is defining a default namespace of 'urn:backoffice:products' which is not the empty namespace. We have to tell XPath to select nodes from the namespace 'urn:backoffice:products' otherwise no nodes will be returned.

So how do we do this?

XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace(
"p", "urn:backoffice:products");
XmlNodeList productList = products.SelectNodes("/p:products/*", nsm);

We add the namespace with an arbitrary prefix and the XmlNamespaceManager is used to expand 'p' to the default namespace name which then brings the nodes we're interested in into scope.

One thing still puzzles me though is the purpose of the DefaultNamespace property in the XmlNamespaceManager and I guess some digging around will uncover it's intentions because the MS docs are pretty vague.

 

Sunday, March 12, 2006 4:49:49 AM UTC  #    Comments [3] -
.NET
Now Playing
Top Artists This Week
Fluff

Powered by FeedBurner
Categories
Archive
<April 2006>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Kevin Kenny
Sign In
Statistics
Total Posts: 194
This Year: 41
This Month: 0
This Week: 0
Comments: 101
All Content © 2008, Kevin Kenny
DasBlog theme 'Business' created by Christoph De Baene (delarou)