After working in the field for a while, I have ran across some silly stuff I have seen other developers do. Below is a list. I am hoping that between my knowledge, and the experience of others. Some better approaches can be derived. Feel free to comment below to add your own silly issue.
Silly Issue 1: Use a base page to set page title.
Now this issue can be solved in many ways. Overall I go for the simplest approach if it will satisfy the needs. for example;
protected override void Render(HtmlTextWriter writer)
{
Page.Title = string.Format("My site title - {0}", Page.Title);
base.Render(writer);
}
Put that code in your master page. Or even better yet would be to pull the site title from the web.config.
Silly Issue 2: Use a base page to initialize connections to a database.
Simple.... never, never, never, never do this. When the database goes offline, there is no reason that a static page should break. Instead just utilize some data access framework, TableAdapters, Linq.... anything.
Silly Issue 3: Use a base page to enforce a proper URL (www.xyz.com or xyz.com).
This is also simple, fight the temptation to do this via code, and ask the IT guys to do this via DNS or some other technology. There is no reason to muddy up the code of a web site for this reason, and will come back to bite you on DEV and STG environments anyway. So even more code/configuration to support a silly decision in the first place.
Silly Issue 4: Use a base page to handle error handling.
Do not do this. Handle code errors in a standard way, such as per page. And for the unhandled exceptions, utilize a IHttpModule that hooks the context.Error. Such as below maybe;
public class EmailErrorHandler : IHttpModule
{
#region IHttpModule Members
public void Dispose() {}
public void Init(HttpApplication context)
{
// wire global error handle
context.Error += ApplicationError;
}
Then add the type to the web.config in the HttpModules section. Create an ApplicationError method that performs the actions you need. As you can see by the title of my class, mine sends an email.
Hopefully this will save someone some time.