Month: June 2009

ASP.NET Maintenance Mode Module

AM3Web developers at times need to put their web applications in an offline mode so as to prevent visitors from accessing the site while they are updating it. The classic way to do this would be to upload an app_offline.html file to the root of the web application. The limitation of this technique is that even the developer cannot visit the site! A developer might need to ensure if everything is working fine and at the same time prevent other users from accessing the web site.

So I created an HTTP module that helps overcome this issue. Just place a few lines in your web.config file and you are ready to go!

 

The following are the main features of this module:

1. Turn on/off the maintenance mode using a setting in the web.config file.

2. Specify the path to the landing page that will be shown to visitors.

3. Specify path to the login page if available.

4. Specify the allowed user roles.

5. Specify the allowed users.

Since the module is in its primary stage, please report any issues that you may find.

Resources

Share

How to add a tooltip to an ASP.NET DropdownList item

If you want to set a common tooltip for all the items in a DropDownList then you can just set the Title attribute for each item like so:

foreach(ListItem item in ddlScorecards.Items)
    item.Attributes.Add("Title", "YOUR TOOLTIP TEXT");

But if you want to set unique tooltips for each item then you have wrap the text value of the items in a DIV.

foreach(ListItem item in ddlScorecards.Items)
  item.Text = String.Format("<div title='{0}'>{1}</div>", "YOUR_TOOLTIP", item.Text);

Happy Programming!

Share

Programmatically extract body of a web page

The technique used in this article can be used to display the contents of an HTML page inside your ASP.NET pages instead of using IFRAMES.

System.Net.WebRequest req = System.Net.WebRequest.Create(Request.QueryString["url"]);
System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)req.GetResponse();
System.IO.Stream respStream = resp.GetResponseStream();
System.IO.StreamReader sr = new System.IO.StreamReader(respStream);
string responseFromServer = sr.ReadToEnd();
System.Text.RegularExpressions.Regex bodyRegex = new System.Text.RegularExpressions.Regex(@"(]*>[\u0000-\uFFFF]+?)");
System.Text.RegularExpressions.Match bodyMatch = bodyRegex.Match(responseFromServer);
Literal1.Text = bodyMatch.Result("$0");
sr.Close();
respStream.Close();
resp.Close();

Thanks to ClayCo at the ASP.NET Forums for his help. Here is the link to the original thread http://forums.asp.net/t/1023144.aspx

Share