PageViewer WebPart 不会加载带有 GET 参数的 URL

发布于 2024-07-26 19:48:24 字数 563 浏览 5 评论 0原文

我需要在我的 SharePoint 门户中显示外部网站,因此我添加了 PageViewerWebPart。 但 URL 包含登录参数,例如 www.mywebsite.com?login=X&passwd=Y

我尝试在 ContentLink PageViewer 属性中添加 ASP 代码,如下所示:

<WebPartPages:PageViewerWebPart runat="server" ContentLink="<% ="URL" %>" ... />

它返回此错误:服务器标记不能包含 <% ... %> 指示。

是否存在其他允许使用 GET 参数加载 URL 的属性? 我可以将此代码放入 WebPartPage 的 CodeBehind 中吗? 我真的做错了吗...?

任何帮助将非常感激!

蒂莫西·马丁.

I need to show an external website in my SharePoint portal so I have added a PageViewerWebPart. But the URL includes login parameters like www.mywebsite.com?login=X&passwd=Y.

I tried to add ASP code at the ContentLink PageViewer property like that :

<WebPartPages:PageViewerWebPart runat="server" ContentLink="<% ="URL" %>" ... />

It returns me this error : server tags cannot contain <% ... %> instructions.

Does exists other properties which allow to load URL with GET parameters ?
Can I put this code into the CodeBehind of my WebPartPage ?
Am I actually doing it wrong... ?

Any help will be very apreciated !

Timothée Martin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2024-08-02 19:48:24

虽然我认为将用户的凭据放在 URL 中是一个坏主意(任何人都可以通过查看页面的 HTML 源代码来看到这一点),但您可以通过以下方式完成您想要做的事情:

创建一个新的类库项目使用继承自 Microsoft.SharePoint.WebPartPages.WebPartPage 的类。 类似于:

namespace MyNameSpace.WebPagePages
{
    public class MyWebPartPage : Microsoft.SharePoint.WebPartPages.WebPartPage
    {
        protected Microsoft.SharePoint.WebPartPages.PageViewerWebPart myPageViewerWebPart;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // logic to create your URL
            string url = "http://blah/blah";

            // set the URL
            myPageViewerWebPart.ContentLink = url;
        }
    }
}

您需要签署程序集并将其部署到 GAC。 建议使用 SharePoint 解决方案 (WSP) 来执行此操作(但不是本答案的重点)。

现在,您需要修改包含 Web 部件的 ASPX 页面,如下所示:

  1. <%@ Page %> 指令的 Inherits 属性更改为完全限定类型名称上述类的。 它看起来类似于:MyNameSpace.WebPagePages.MyWebPartPage, MyNameSpace.WebPagePages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b538f318242c0b01
  2. 为 Web 部件指定一个 ID 属性其值与代码隐藏类中的 Web 部件名称相匹配。 在此示例中:

应该可以。 如果您以前没有这样做过,那么创建类并将其部署到 GAC 将是比较棘手的部分,但是当您知道如何操作时,它们就会很容易。 VSeWSS 等工具、STSDEVWSPBuilder(先学习一个,然后尝试其他)将帮助您通过创建 WSP 文件(SharePoint 解决方案)来实现这一目标 - 我强烈建议您利用这一点。

While I think it's a bad idea to put the credentials of a user in a URL (anyone will be able to see this by viewing the page's HTML source), here's how you could accomplish what you want to do:

Create a new class library project with a class that inherits from Microsoft.SharePoint.WebPartPages.WebPartPage. Something like:

namespace MyNameSpace.WebPagePages
{
    public class MyWebPartPage : Microsoft.SharePoint.WebPartPages.WebPartPage
    {
        protected Microsoft.SharePoint.WebPartPages.PageViewerWebPart myPageViewerWebPart;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // logic to create your URL
            string url = "http://blah/blah";

            // set the URL
            myPageViewerWebPart.ContentLink = url;
        }
    }
}

You'll need to sign the assembly and deploy it to the GAC. Using SharePoint Solution (WSP) is the recommended way to do this (but not the point of this answer).

You now need to modify the ASPX page containing your web part as follows:

  1. Change the Inherits attribute of the <%@ Page %> directive to the fully qualified type name of the above class. It will look something like: MyNameSpace.WebPagePages.MyWebPartPage, MyNameSpace.WebPagePages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b538f318242c0b01
  2. Give the web part an ID attribute with a value that matches the name of the web part in the code-behind class. In this example: <WebPartPages:PageViewerWebPart runat="server" ID="myPageViewerWebPart">

That should do it. If you've not done it before, creating the class and deploying it to the GAC will be the tricky bits, but they're easy when you know how. Tools like VSeWSS, STSDEV, and WSPBuilder (learn one first and then try the others) will help you accomplish this by creating WSP files (SharePoint Solutions) - something I highly recommend you take advantage of.

明媚殇 2024-08-02 19:48:24

如果布局页面中存在上述代码,那么 <%%> 是的。 布局页面中不允许使用。 我建议您在服务器端代码中设置链接。 但如果您仍然想使用 <%%> 参考这个链接

If the above code is present in the Layout Page, then yes the <%%> are not allowed in Layout Pages. I recommend you to set the Link in the Server Side code. But if you still wanted to use the <%%> refer this link on how to make it work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文