简体   繁体   English

尽管有WWWfilter,但已部署IIS7的MVC仍未重定向

[英]IIS7 deployed MVC doesn't redirect despite WWWfilter

I have a WWW filter on all my actions 我的所有动作都有WWW筛选器

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 对于我的网站, http://www.tweetMP.org.au

The www is NOT filtered out for the homepage, or some of the other pages 没有为主页或其他一些页面过滤掉www

If you visit around the site using the menu, eventually the www will disappear as the filter kicks in. 如果您使用菜单访问该站点,最终,随着过滤器的启动,www将会消失。

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. 更新:这似乎也与我执行的每个动作上的OutputCache有关。 What is the correct way to WWW filter in a medium trust environment? 在中等信任环境中进行WWW筛选的正确方法是什么?

I would look into using the built in IIS7 URL Rewrite Module 's support for redirects. 我将研究使用内置的IIS7 URL重写模块对重定向的支持。 Also, it could also be caching in the client browser... If you do a forced refresh (Shift+F5) does the redirect work? 另外,它也可能在客户端浏览器中进行缓存...如果执行强制刷新(Shift + F5),重定向是否起作用?

Beyond this, if you want to do performance optimizations within sub-domains for images, scripts and css, you may want to keep the www. 除此之外,如果您想在子域中对图像,脚本和CSS进行性能优化,则可能需要保留www。 Since cookies set to the parent domain (mydomain.ext), will also be sent to subdomains (images.mydomain.ext). 由于cookie设置为父域(mydomain.ext),因此也会发送到子域(images.mydomain.ext)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM