views:

158

answers:

1

I have a WWW filter on all my actions

public class WwwFilter : ActionFilterAttribute, IActionFilter {

    #region IActionFilter Members

    void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext) {

    }

    void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) {

        var request = filterContext.HttpContext.Request;
        var response = filterContext.HttpContext.Response;

        if (request.Url.Host.StartsWith("www")) {
            string newPort = request.Url.IsDefaultPort ? "" : ":" +request.Url.Port.ToString();
            string newUrl = request.Url.Scheme + "://" +request.Url.Host.Replace("www.", "") + newPort + request.Url.AbsolutePath;
            filterContext.Result = new RedirectResult(newUrl);

        }
    }

    #endregion
}

for my site, http://www.tweetMP.org.au

The www is NOT filtered out for the homepage, or some of the other pages

If you visit around the site using the menu, eventually the www will disappear as the filter kicks in.

I have no idea why this happens. Any ideas?

UPDATE: this appears something to do with the OutputCache on each action I'm doing too. What is the correct way to WWW filter in a medium trust environment?

+1  A: 

I would look into using the built in IIS7 URL Rewrite Module's support for redirects. Also, it could also be caching in the client browser... If you do a forced refresh (Shift+F5) does the redirect work?

Beyond this, if you want to do performance optimizations within sub-domains for images, scripts and css, you may want to keep the www. Since cookies set to the parent domain (mydomain.ext), will also be sent to subdomains (images.mydomain.ext).

Tracker1