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:
- 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
- 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.