Monday, June 19, 2006

Pageviewer webpart customized!

Well this is a solution which i've built a couple of months ago and just want to share it with you. Thought that some people may find this interesting ;) Think of solutions where you have a custom build application on another webserver where only powerusers can view it. Now you want to configure the pageviewer that only powerusers will have the pageviewer on the page and users who are not in the powerusers group will not see the pageviewer.

protected override void OnInit(EventArgs e) { UserGroup.UserGroup usrgrpService = new UserGroup.UserGroup(); usrgrpService.Credentials = new System.Net.NetworkCredential("adminaccount", "password", "domain"); usrgrpService.Url = HostUrl + "/_vti_bin/UserGroup.asmx"; System.Xml.XmlNode ngCrossGroups = usrgrpService.GetGroupCollectionFromUser(@Context.User.Identity.Name.ToString()); XmlNodeList _nodes = ngCrossGroups.SelectNodes("*"); foreach (XmlNode node in _nodes) { foreach(XmlElement _item in node.SelectNodes("*")) { if (_item.Attributes["Name"].Value == Group) { breakiebreakie = true; break; } } if (breakiebreakie) { break; } } if (!breakiebreakie) { this.Visible = false; } }
Make sure you access the webservice with an admin account because otherwise you get access denied errors when you want to retrieve information about the users. Also, don't mind my variablenames ;) Then in the render of the webpart :
protected override void RenderWebPart(HtmlTextWriter output) { try { if (breakiebreakie) { output.Write("just put an iframe here with an URL"); } } catch(Exception error) { output.Write(error.Message.ToString()); } }
So there are three variables : Url = the url you want to display within the pageviewer Group = (cross)sitegroup you want to give rights to view the pageviewer HostUrl = url where the webservice will be referenced to

2 comments:

digital signature sharepoint said...

Grateful to check out your website, I seem to be ahead to more excellent sites and I wish that you wrote more informative post for us. Well done work.

McLean Cleaners said...

Interesting post, I enjoyed read this.