views:

546

answers:

2

Hi everyone.

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.

A: 

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.

Kusek
Thanks for your answer.I already tried to put the code described in the link but it doesn't work. It allows you to put the <% %> everywhere but not in the WebPart tags.The problem is that I don't find the server side code file. My WebPartPage is stored in a library on my TeamSite and I the first tag doesn't refers to a CodeBehind file.With regards, Timothée Martin.
Timothée Martin
+2  A: 

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.

dariom
Thanks a lot ! I'll try to do it now ! =)
Timothée Martin