Deployed IIS7 MVC does not redirect despite WWWfilter
I have a WWW filter for 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
WWW is not filtered for home page or some other pages
If you visit the site using the menu, eventually the www will disappear when the filter starts working.
I have no idea why this is happening. Any ideas?
UPDATE: This has something to do with the OutputCache for every action I do too. What is the correct way to filter WWW in a medium trust environment?
a source to share
I would consider using the built-in IIS7 URL Rewrite Module to support redirection. Also, it could also be caching in the client's browser ... If you do a forced refresh (Shift + F5), does the redirect work?
Other than that, if you want to do performance optimizations within subdomains for images, scripts and css, you might want to keep www. Because cookies set to parent domain (mydomain.ext) will also be sent to subdomains (images.mydomain.ext).
a source to share