sharepoint - SharePoint 个性化 url/重定向的最佳实践

标签 sharepoint sharepoint-2007

我的雇主将 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 服务器带来最小的处理负担。谢谢!

最佳答案

我已经使用 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);将向前推送必要的 header ,以便接收 .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
            }
        }
    }
}

关于sharepoint - SharePoint 个性化 url/重定向的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1201180/

相关文章:

css - 将 CSS 应用于单个 Web 部件上的 Sharepoint 站点

c# - 获取域名

asp.net - 如何从网站及其子网站中获取不同的用户?

Sharepoint - 字段在 View /新项目上出现两次

sharepoint - 将状态指示器添加到自定义 Web 部件

javascript - 使用 SP2010 中的按钮更改页面,奇怪的行为

c# - 将 SPWeb 作为按值参数传递会导致内存泄漏吗?

javascript - 增加 Sharepoint 网站中的文本大小字体

sharepoint - 根据他们拥有的权限查询列表项

sharepoint - 在 Windows Sharepoint Services 3.0 中仅编辑拥有的列表项