SharePoint虚拟URL/重定向的最佳实践

3
我的雇主在公司内部网站使用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服务器产生最小处理负担的东西。谢谢!
5个回答

3
我使用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
            }
        }
    }
}

谢谢。经过审查反馈,这是最适合我情况的选择。我看了一下你的代码,并且成功地重构了它以满足我的需求。我很想发布它,但似乎评论系统不允许我这样做(字符数不够)。再次感谢! - Scott Fox
这正是我今天解决问题所需要的。实际上,我最终从我建立的自定义SharePoint列表中读取了虚拟路径到URL映射,并且它非常有效。+1 - Hardwareguy

2

你比我先完成了。使用AAMs可以轻松地实现很多东西。 - Chrisb
这似乎仅限于协议、主机和端口。我需要重定向深层链接。虽然我不知道这个功能,所以感谢提供信息! - Scott Fox

1

0

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接