Duarte Nobrega
 

Page web parts limit exceeded?

30

Dec

Sometimes you might need to add more webparts to a certain page than the default MOSS limit, which is 50 webparts. If so in order to increase the limit follow the following procedure:

 

1. Go to the web.config file & open it.

2. Change the MaxZoneParts value to the new desired limit:

   <WebPartLimits MaxZoneParts="50" PropertySize="1048576" />

3. Save it & go.

 

Duarte Nobrega schreef

Comments (0)

Duarte Nobrega

SharePoint 2007 Timer jobs not working?

19

Dec

Is your Sharepoint Portal suffering from any of the following symptoms?

- Scheduled Audience compilation is not happening anymore?

- Scheduled Index crawll is not happening anymore?

- Scheduled Profile Import is not happening anymore?

- Users Memberships or My Settings properties are not updated anymore?

 

Clearing the file system cache on all servers in the server farm on which the Windows SharePoint Services Timer service is running.

To do this, follow these steps:

  1. Stop the Timer service. To do this, follow these steps:
    1. Click Start, point to Administrative Tools, and then click Services.
    2. Right-click Windows SharePoint Services Timer, and then click Stop.
  2. Clear the cache. To do this, follow these steps:
    1. Open the following folder: %ALLUSERSPROFILE% \Application Data\Microsoft\SharePoint\Config\<GUID>
    2. Open the cache.ini file and change the value to 1. Save the change and close the cache.ini file.
    3. Delete or move all of the XML files.
  3. Start the Timer service. To do this, follow these steps:
    1. Click Start, point to Administrative Tools, and then click Services.
    2. Right-click Windows SharePoint Services Timer, and then click Start.

 

Share:

Duarte Nobrega schreef

Comments (0)

Duarte Nobrega

Sharepoint: How to verify if a user is Site administrator

09

Dec

In many Sharepoint projects the following code has been user to check if a certain user has full control or not over a specific site:

if (!SPContext.Current.Web.CurrentUser.IsSiteAdmin)

But this code only check if a user is a Site Collection administrator. Even if the current user is in the owners group, it will not work. And therefore, problems will happen once implemented live.

Workaround:

I wrote a method that checks if a user belongs to the Owners group:

if(!isCurrentUserOwner())


Method:
private bool isCurrentUserOwner()
        {
            bool currentUserOwner = false;

            SPUser currentUser = SPContext.Current.Web.CurrentUser;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    SPSite currentSite = new SPSite(SPContext.Current.Site.Url);
                    SPWeb currentWeb = currentSite.OpenWeb(SPContext.Current.Web.ID);
                    SPGroup ownersGroup = currentWeb.AssociatedOwnerGroup;

                    //Check if currentuser belongs to owners group of the current web
                    foreach(SPUser user in ownersGroup.Users)
                    {
                        if (currentUser.ID == user.ID)
                        {
                            currentUserOwner = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //blah blah
                }             
            });

            //Not an owner member
            return currentUserOwner;
        }

Share:

Duarte Nobrega schreef

Comments (0)

Duarte Nobrega

Sharepoint: using SPSecurity.RunWithElevatedPrivileges but still prompt's a window login

09

Dec

When your sharepoint portal or internet site prompts windows logins, there can be many reasons but a very typical is that some webpart is trying to access information to which is not authorized.

Using SPSecurity.RunWithElevatedPrivileges, prevents this, but this must be used wisely.

1. SPSecurity.RunWithElevatedPrivileges & opening sites

The following code sample will prompt a login windows for some users:

Example 1:

SPSecurity.RunWithElevatedPrivileges(delegate()

{

      SPSite thisSite = SPContext.Current.Site;

      SPWeb thisWeb = thisSite.OpenWeb();

}

 

One should not use SPContext.Current.Site within RunWithElevatedPrivileges the because this will run under the current user, and not with the high rights account.

 

So the code on Example 1, should be as bellow:

 

Example 2:

SPSecurity.RunWithElevatedPrivileges(delegate()

{

      SPSite thisSite = new SPSite(SPContext.Current.Site.Url);

      SPWeb thisWeb = thisSite.OpenWeb();

}

 

Opening the Site with new SPSite(SPContext.Current.Site.Url); will use the Admin account, and not the current user.

 

 

2.  SPSecurity.RunWithElevatedPrivileges & opening list items

The same problem when using lists.

Example 3:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    SPSite thisSite = new SPSite(SPContext.Current.Site.Url);
    SPWeb thisWeb = thisSite.OpenWeb();
    SPListItem li = SPContext.Current.ListItem;
    PublishingPage page = PublishingPage.GetPublishingPage(li);
}

This might prompt a login window for some users,  using  SPContext.Current.ListItem within RunWithElevatedPrivileges will run under the current user, and not with the high rights account.

So the code on Example 3, should be as bellow:

Example 4:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    SPSite thisSite = new SPSite(SPContext.Current.Site.Url);
    SPWeb thisWeb = thisSite.OpenWeb();
    SPListItem li = web.Lists[SPContext.Current.List.ID].Items[SPContext.Current.ListItem.ID];
    PublishingPage page = PublishingPage.GetPublishingPage(li);
}

Opening the list item with web.Lists[SPContext.Current.List.ID].Items[SPContext.Current.ListItem.ID]; will use the Admin account, and not the current user.

 

 

 

Duarte Nobrega schreef

Comments (1)

Duarte Nobrega

Zoeken

Categorie

Archief


Sign In