Custom Control Question - Team Site Navigation
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Custom Control Question - Team Site Navigation

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
Mike Price
Guest





Posted: Sat Oct 22, 2005 12:51 am    Post subject: Custom Control Question - Team Site Navigation Reply with quote

I created a custom control that sites under the
CategoryNavigationWebPart control. This control lists the team sites
under my portal server virtual. It works great for anyone who had
administrative rights to the server but if a user who doesnt have admin
rights tries to load the page they get "Access denied. You do not have
permission to perform this action or access this resource."

I am new to C# and ASP.NET programming so I am hoping someone out there
can point me in the right direction.

impersonate is set to true
authenication mode is set to windows

Source:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.WebControls;

namespace MyCompany.SharePoint.Portal.WebControls
{
/// <summary>
/// Summary description for TeamSiteNav.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:TeamSiteNav runat=server></{0}:TeamSiteNav>")]
public class TeamSiteNav : System.Web.UI.WebControls.WebControl
{

private string _headerText;
private string _portalUrl;
private string _webTemplate;

public string portalUrl
{
get{ return _portalUrl; }
set{ _portalUrl = value; }

}
public string webTemplate
{
get{ return _webTemplate; }
set{ _webTemplate = value; }
}
public string headerText
{
get{ return _headerText; }
set{ _headerText = value; }
}
public string headerHtml
{
get
{
return String.Format(@"<table id=TeamSiteNavBar width=100%
cellpadding=0 cellspacing=0 style=""border-collapse: collapse""
class=Ms-pvnav DisplayType=v1>
<tr>
<td class=ms-navheader>{0}</td>
</tr>", headerText);
}
}
public string footerHtml
{
get{ return String.Format(@"</table>"); }
}


public string GetTeamSites()
{
StringBuilder sWebOut = new StringBuilder();

SPGlobalAdmin oGlobalAdmin = new SPGlobalAdmin();
SPVirtualServer oVirtualServer = oGlobalAdmin.OpenVirtualServer(new
Uri(portalUrl));
SPSiteCollection oSites = oVirtualServer.Sites;
foreach(SPSite oSite in oSites)
{
SPWeb oWeb = oSite.RootWeb;
string WebTemplate = oWeb.WebTemplate;

if(webTemplate == WebTemplate)
{
sWebOut.AppendFormat(headerHtml);
sWebOut.AppendFormat(string.Format(@"<tr>
<td>
<table width=100% cellpadding=0 cellspacing=0
style=""border-collapse: collapse"" class=Ms-pvnavtableone1>
<tr>
<td class=Ms-pvnavtopl1><img
src=""/_layouts/images/trans.gif"" alt=""""></td>
<td class=Ms-pvnavtopc1></td>
<td class=Ms-pvnavtopr1><img
src=""/_layouts/images/trans.gif"" alt=""""></td>
</tr>
<tr>
<td class=Ms-pvnavmidl1></td>
<td class=Ms-pvnavmidc1><a id=NavCatV0_C_0_0
href=""{0}"" target=_self title=""{1}"">{1}</a></td>
<td class=Ms-pvnavmidr1></td>
</tr>
<tr>
<td class=Ms-pvnavbotl1
background=""/_layouts/images/trans.gif"" alt=""""></td>
<td class=Ms-pvnavbotc1></td> <td class=Ms-pvnavbotr1
background=""/_layouts/images/trans.gif"" alt=""""></td>
</tr>
</table>
</td>
</tr>", oWeb.Url, oWeb.Title));
sWebOut.AppendFormat(footerHtml);
}

}
return sWebOut.ToString();
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.Write(GetTeamSites());
}
}
}
Back to top
Mike Price
Guest





Posted: Sat Oct 22, 2005 12:51 am    Post subject: Re: Custom Control Question - Team Site Navigation Reply with quote

Basically all I am trying to do is create navigation which will sit on
the portal home page that will show the team sites each user has access
to. I know there must be a way to do this.
Back to top
Saint
Guest





Posted: Sat Oct 22, 2005 12:50 pm    Post subject: Re: Custom Control Question - Team Site Navigation Reply with quote

Hi mike,
What i have encountered sometimes is that when you try to get the sites
collection or try to get user roles on a site you get the access denied
exception. I think the line giving you this exception is
SPSiteCollection oSites = oVirtualServer.Sites
What you can do is run the following line of code in the context of the
administrator. You can do this using impersonation. Use for programmatic
impersonation so that you can undo it once the code is run. for impersonation
you can go through the link given below
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q306158
HTH

"Mike Price" wrote:

Quote:
Basically all I am trying to do is create navigation which will sit on
the portal home page that will show the team sites each user has access
to. I know there must be a way to do this.

Back to top
Erdogan G.
Guest





Posted: Sat Oct 22, 2005 12:50 pm    Post subject: Re: Custom Control Question - Team Site Navigation Reply with quote

Hi Mike,

It seemed to me, you didn't install web part to GAC (Global Assembly
Cache). Because of the fact that any control registered with GAC has a
full control of the server. However, once you installed the control to
GAC, you need to do ISS-Reset to make changes on the code. There is
another option while you are doing the development, got to web.config
file and find the starts with <trust level=WSS_Medium or <trust
level=WSS_Minimal, and change its value to <trust level=Full. As a last
step you need to reset the ISS so that new changes take effect.

The second option is better, since you don't have to install the
assembly to cache and your assembly has full control over the server.

Take care.
Back to top
Mike Price
Guest





Posted: Sat Oct 22, 2005 4:50 pm    Post subject: Re: Custom Control Question - Team Site Navigation Reply with quote

Saint,

Thanks for your reply. Do you know if the user I impersonate has to
be in the local admin group or could it just be a user that happens to
be the in group that I have setup as the SharePont Administrative
group? The latter would be best.
Back to top
Mike Price
Guest





Posted: Sat Oct 22, 2005 4:50 pm    Post subject: Re: Custom Control Question - Team Site Navigation Reply with quote

Erdogan,

Thanks for your post. I do have the assembly sn'd and it is in the
GAC. I apologize that I didnt mention that in my original post.
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB