SharePoint 虚 URL/重定向的最佳实践 [英] Best practice for SharePoint vanity url/redirection

查看:59
本文介绍了SharePoint 虚 URL/重定向的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的雇主将 MOSS 2007 用于我们公司的内部网.它仅在安全的 http 上运行,也通过 ISA 暴露给外界.我目前有一个请求,要向我们的网站添加一个转发 URL,以便发生以下类似的事情:

My employer uses MOSS 2007 for our company intranet. It runs solely on secure http and is also exposed to the outside world via ISA. I currently have a request to add a forwarding URL to our site so that something like the following will occur:

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

intranet.mycompany.com/vanityname
redirects to -> intranet.mycompany.com/somedeeplink/default.aspx

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

I fully expect this sort of thing will become more popular with our users as time goes on. So I am looking for a solution that scales. I have read various articles about creating a /site/ with forwarding meta tags or a forwarding SharePoint page type. I've also seen some that talk about adding virtual directories, etc directly in IIS. All these solutions seem to be overkill and inevitably take up more memory or processing time on the web servers.

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

I am currently leaning towards writing an http module that can be configured in the web.config and perform redirects. I wanted to get feedback to see if anyone else has done something similar in SharePoint 2007 and had any suggestions. Again, I'd like to implement something that scales without making major changes later on and is going to put minimal processing burden on our web servers. Thanks!

推荐答案

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

Ive implemented url redirecting with MOSS using the HTTP module route. I documented the code I used and what parameters worked the best for me here;

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

看看这是否对您有帮助,如果您有任何疑问,请告诉我.

Take a look and let me know if this helps you and if you have any questions.

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

Update: The link above is no longer valid, so here text from the page that I used for URL redirect.

经过一番折腾,我想出了一个好方法.当我在网上寻找示例时,有很多人说它无法完成.但最终它实际上并没有花太多时间来实现它.这是我编写的一个 HttpModule 来完成这项工作.

After messing around for a little bit it, I came up with a good way to do it. When I was looking for examples on the web there were a lot of people saying that it couldnt be done. But in the end it actually didn’t take much to implement it. Here’s an HttpModule that I wrote to do the work.

关键部分是 this.app.BeginRequest += new EventHandler(app_BeginRequest)在请求前面的步骤并允许模块进行重定向.

The key pieces are the this.app.BeginRequest += new EventHandler(app_BeginRequest) which steps in front of the request and allows the module to get its redirect on.

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

And HttpContext.Current.RewritePath(redirect, false); will push the necessary headers n such forward so that the receiving .aspx page will understand how to correctly post back.

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 虚 URL/重定向的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆