我已经使用 HTTP 模块路由通过 MOSS 实现了 url 重定向。我在这里记录了我使用的代码以及哪些参数最适合我;
http://scaredpanda.com/2008/08/url-rewriting-with-sharepoint-moss-2007/ http://scaredpanda.com/2008/08/url-rewriting-with-sharepoint-moss-2007/罢工>
请看一下,如果这对您有帮助以及您是否有任何疑问,请告诉我。
Update:上面的链接不再有效,因此这里的文本来自我用于 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
}
}
}
}