【问题标题】:Best practice for SharePoint vanity url/redirectionSharePoint 虚 url/重定向的最佳实践
【发布时间】:2009-07-29 15:38:57
【问题描述】:

我的雇主将 MOSS 2007 用于我们公司的内部网。它仅在安全的 http 上运行,并且还通过 ISA 向外界公开。我目前有一个向我们的网站添加转发 URL 的请求,以便发生以下情况:

intranet.mycompany.com/vanityname
重定向到 -> intranet.mycompany.com/somedeeplink/default.aspx

我完全希望随着时间的推移,这类东西会越来越受我们的用户欢迎。所以我正在寻找一种可扩展的解决方案。我已阅读有关使用转发元标记或转发 SharePoint 页面类型创建 /site/ 的各种文章。我还看到一些谈论直接在 IIS 中添加虚拟目录等。所有这些解决方案似乎都有些矫枉过正,而且不可避免地会占用更多的内存或 Web 服务器上的处理时间。

我目前倾向于编写一个可以在 web.config 中配置并执行重定向的 http 模块。我想获得反馈,看看是否有其他人在 SharePoint 2007 中做过类似的事情并有任何建议。再一次,我想实现一些可扩展的东西,而无需稍后进行重大更改,并且将对我们的 Web 服务器施加最小的处理负担。谢谢!

【问题讨论】:

    标签: sharepoint sharepoint-2007


    【解决方案1】:

    我已经使用 HTTP 模块路由通过 MOSS 实现了 url 重定向。我在这里记录了我使用的代码以及最适合我的参数;

    http://scaredpanda.com/2008/08/url-rewriting-with-sharepoint-moss-2007/

    看看,如果这对您有帮助,如果您有任何问题,请告诉我。

    更新:上面的链接不再有效,所以这里的文本来自我用于 URL 重定向的页面。

    在搞砸了一点之后,我想出了一个好方法。当我在网上寻找示例时,有很多人说它无法完成。但最终它实际上并没有花太多时间来实现它。这是我为完成这项工作而编写的一个 HttpModule。

    关键部分是 this.app.BeginRequest += new EventHandler(app_BeginRequest) 这 位于请求前面并允许模块进行重定向。

    和 HttpContext.Current.RewritePath(redirect, false);将向前推送必要的标头,以便接收 .aspx 页面了解如何正确回发。

    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Reflection;
    using System.Collections;
    using System.Text;
    using System.Web;
    using System.Web.Caching;
    using System.Web.SessionState;
    using System.Security.Cryptography;
    using System.Configuration;
    using System.Threading;
    using System.IO;
    using System.Security;
    using System.Security.Principal;
    
    namespace ScaredPanda
    {
        public sealed class RewriteHttpModule : IHttpModule
        {
            HttpApplication app = null;
            ///
            /// Initializes the httpmodule
            ///
            public void Init(HttpApplication httpapp)
            {
                this.app = httpapp;
                this.app.BeginRequest += new EventHandler(app_BeginRequest);
            }
    
            public void app_BeginRequest(Object s, EventArgs e)
            {
                try
                {
            //determine if the income request is a url that we wish to rewrite.
            //in this case we are looking for an extension-less request
                    string url = HttpContext.Current.Request.RawUrl.Trim();
                    if (url != string.Empty
                        && url != "/"
                        && !url.EndsWith("/pages")
                        && !url.Contains(".aspx")
                        && url.IndexOf("/", 1) == -1)
                    {
                        //this will build out the the new url that the user is redirected
                        //to ie pandas.aspx?pandaID=123
                        string redirect = ReturnRedirectUrl(url.Replace("/", ""));
    
                //if you do a HttpContext.Current.RewritePath without the 'false' parameter,
                        //the receiving sharepoint page will not handle post backs correctly
                //this is extremely useful in situations where users/admins will be doing a
                       //'site actions'  event
                       HttpContext.Current.RewritePath(redirect, false);
                    }
                }
                catch (Exception ex)
                {
                    //rubbish
                }
            }
        }
    }
    

    【讨论】:

    • 谢谢,在查看反馈后,这是最适合我的情况。我查看了您的代码,并能够对其进行重构以精确地满足我的需求。我很想发布它,但看起来这里的评论系统不允许我发布(没有足够的字符)。再次感谢!
    • 这正是我今天解决问题所需要的。实际上,我最终从我构建的自定义共享点列表中读取了虚荣到 URL 的映射,并且效果很好。 +1
    【解决方案2】:

    您是否研究过备用访问映射?

    http://technet.microsoft.com/en-us/library/cc263208.aspx

    【讨论】:

    • 打败我。使用 AAM 可以轻松完成很多工作。
    • 这似乎仅限于协议、主机和端口。我需要重定向深层链接。虽然我不知道这个功能,但我很感激这些信息!
    【解决方案3】:

    如果您愿意为解决方案付费。看看:

    不是免费的 -> http://www.muhimbi.com/Products/SharePoint-URL-Shortener.aspx

    【讨论】:

      【解决方案4】:

      根据重定向的数量,您可能希望按照说明实现 HTTP 模块)但是如何检查

      免费 -> http://www.codeplex.com/sharepointsmart404

      【讨论】:

        【解决方案5】:

        使用 IIS 中的 URL 重写功能。 (我相信这是一个 IIS 7 扩展)

        http://www.iis.net/download/urlrewrite

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-12-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-12-09
          相关资源
          最近更新 更多