Does ASP.NET really do that?

A coworker told me that he noticed slow performance on our website when folders were deleted in the solution. We do not usually need to delete folders during production use, but he wanted me to look into it.

Sure enough, I was able to reproduce this behavior, furthermore I found others that had experienced the same problem, and a workaround.

void Application_Start(object sender, EventArgs e)
{
    // prevent file changes monitoring on subdirectories
    PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty(
        "FileChangesMonitor",
        BindingFlags.NonPublic | 
        BindingFlags.Public | 
        BindingFlags.Static);

    FieldInfo f = p.GetValue(null, null).GetType().GetField(
        "_dirMonSubdirs",
        BindingFlags.Instance |
        BindingFlags.NonPublic |
        BindingFlags.IgnoreCase);

    object monitor = f.GetValue(p.GetValue(null, null));
    MethodInfo m = monitor.GetType().GetMethod(
        "StopMonitoring",
        BindingFlags.Instance | BindingFlags.NonPublic);

    m.Invoke(monitor, new object[] { }); 
}
Advertisements

How to I modify my ASP.NET website look and feel?

I do a reasonable amount of ASP.NET website or web application construction and have not found many websites that post sample ASP.NET masterpages or themes or skins. Generally, I end up modifying a sample css template. Here are some of the sites I have found useful.

One major difference about the templates is in how they utilize screen space. Some templates use only the center of the screen and would use, say only 50%, of a widescreen monitor.

These templates are free. Some require attribution.

Starter Kits

Open Source Templates

Open Web Design

Open Source Web Design

Free CSS Templates

Good Luck!

Redirect with ASP.NET

On several occasions I have needed to redirect a user from one place to another in ASP.NET. I like to do this with code similar to the following, which doesn’t require code-behind.

<%@ Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","/public/Default.aspx");
}
</script>

<html>
<head runat="server">
    <title>Redirecting...</title>
</head>
<body>
</body>
</html>