Flaw in ASP.NET execution of App_Offline.htm

2 January 2008 - 12:32 PM by Chris

One of the wonderful features of ASP.NET is a little nugget called App_Offline.htm. With this one amazing little file, you can take a site down for maintenance for those times when upgrading a site just can't be done with the engines still running.

The way it works is simple: create an HTML page, name it App_Offline.htm, place it in the root of the website, and any request to the site will be redirected to this page. When you're ready to bring the site back, simply remove the file, and presto! The site is back.

The trouble is, this page returns a 404 (file not found) response code in the header, which could lead search engines to drop the site from its index. The page should return a 503 (service unavailable) response code.

Thankfully, someone has already submitted a bug report to Microsoft.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Access ASP.NET Application Settings in JavaScript [How-To]

14 November 2007 - 01:17 PM by Chris

Let's suppose you have a value that you are storing in the web.config for a given website. And let's further suppose you have some nifty JavaScript that needs to access that value. Here's how you do it.

First you need to assign that value to a protected string in your C# (or other preferred language) code like this:

protected string myValue = ConfigurationSettings.AppSettings["myValue"].ToString();

Then in JavaScript, you can use the variable just like you would do old-school inline classic ASP:

var myValue = "<%=myValue%>";

Enjoy.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Categories: ASP.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Plot ZIP Codes on Virtual Earth Maps Using ASP.NET

11 October 2007 - 11:27 PM by Chris

Back when I was creating my short-lived bowling tournament locator website, I always thought I would have a tool where the user could see all the tournaments within a given ZIP code (or set of ZIP codes) by displaying them on a map.

How cool would it have been to be able to actually outline and display the ZIP code boundaries on a map? OK, not very if you are not a geek.

Anyway, Matt Berseth has developed a way to do just that using ASP.NET AJAX and Microsoft Virtual Earth. Check it out.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Categories: ASP.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Dynamic meta tags in ASP.NET

29 September 2007 - 09:14 AM by Chris

Rather than go into all the gory details of why I need to do this, let's just say I have a need to determine dynamically to what URL a page will redirect. I'm passing along the destination URL in the querystring, so capturing that is easy enough. But since this page must first display its HTML, I can't just use a Response.Redirect().

So, I decided to use the HTML-based <meta equiv="refresh"> tag. However, I couldn't seem to get ASP.NET to allow me to use inline code to grab the querystring parameter to insert into the content attribute.

What about making the meta tag an object? I slapped a runat="server" and an ID="metaTag" in the meta tag, then in the code behind I could do this:

string url = Request.Querystring["url"];
metaTag.Content = "15;url=" + url;

I still don't know why the inline code wouldn't work, but this way seems cleaner to me anyway. 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Categories: ASP.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed