gpt4 book ai didi

c# - 使用自定义 HttpHandler 在 Sharepoint 中重定向用户

转载 作者:行者123 更新时间:2023-11-30 21:21:44 27 4
gpt4 key购买 nike

如果用户访问网络中的特定页面集,我需要将他们重定向到不同的页面。有一个条件:不允许我接触 IIS。我用谷歌搜索了一下,发现了一个名为 WSS 3.0 的自定义 HttpHandler 的东西。这听起来像是我可以用来捕获用户输入的 URL(进入真正应该重定向的页面的最恶意方式)并将他们重定向到另一个页面/网络的东西。但是还没有机会使用它,我想知道我是否在正确的轨道上使用自定义 HttpHandler 使用 C# 将用户重定向到 Sharepoint 中的不同页面?

非常感谢。

最佳答案

HttpHandler IIS 使用 s 来“处理”不同的文档类型,例如您有单独的 .asmx 句柄、.aspx 处理程序、.ascx 处理程序等

查看SPUtility.Redirect

You can use the SPUtility.Redirect method whenever you want to direct the user to a different page. For example, you might create a landing page that determines the user's role membership, and based on that information you can redirect them to an appropriate page. Or, based on the contents of a query string issued by the user's browser, you might redirect them to a page that can process the query string, such as the Search Center results page.

或者,您可以查看 Using Disposable Windows SharePoint Services Objects .

--编辑--

这是对您评论的回应;你的想法是对的

  1. 创建自定义 HttpHandler; Example 1 , Example 2
  2. 每当用户请求 url 时,您的自定义 HttpHandler 都会处理它。
  3. Redirect() 如果您喜欢该网址,否则。

但要让您的自定义 HttpHandler 工作,它应该首先被调用 - 因此在您的配置文件中,您必须在 path 中提供值。通常在此处添加扩展名。但是您可以将其替换为 * 以处理所有请求。我相信那会奏效。

<httpHandlers>
<add verb="*" path="*.aspx" type="MyNameSpace.MyHttpHandler, MyAssemblyName" />
</httpHandlers>

--编辑--

这是对您评论的回应。假设您可以“访问”页面以便您可以在其中编写 javascript,您可以按以下方式使用 javascript。

<script language=JavaScript>
function RedirectIfUnAuthorized()
{
//Get the location of the current page.
var currentUrl = new String( document.location.href )

//See if it belongs to the urls you are looking for; redirect if so.
if (currentUrl == "http://www.thisUrl.com/page1.aspx") {Response.Redirect("http://www.GOOGLE.com")}
if (currentUrl == "http://www.thisUrl.com/page2.aspx") {Response.Redirect("http://www.BING.com")}
if (currentUrl == "http://www.thisUrl.com/page3.aspx") {Response.Redirect("http://www.someother.com")}
}
</script>

你可以在页面的OnLoad事件中调用上面的javascript。

关于c# - 使用自定义 HttpHandler 在 Sharepoint 中重定向用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2598622/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com