How to Recycle an IIS Application Pool Using a Command Line

Use the following command line in order to recycle an application pool on IIS 7:

[system drive]:\windows\system32\inetsrv\appcmd recycle apppools /apppool.name:”Your Application Pool Name”

 

Works like a charm.

 

See you,

Amadeu.

Showing/Hiding the Ribbon Based on Permissions

I’ve got a task to check why the ribbon was not being displayed for a user with full control on a page on a SharePoint 2010 Publishing site.

Requirements-wise the request made total sense: the user with full control permissions on a page should be able to see the ribbon, check the page out, edit the page, check it back in and publish it. During my tests I noticed the master page had a SPSecurityTrimmedControl control around the ribbon. This control was preventing to ribbon to be shown for the user because it was configure to only show it for users with ManageWeb permissions.

<SharePoint:SPSecurityTrimmedControl
ID=”TrimRibbon”
PermissionsString=”ManageWeb”
runat=”server”>

Checking the list of SPBasePermissions values for the PermissionString property I was able to find the permission I wanted to use: EditListItems. This way all users with permissions to edit items/pages can see the ribbon.

When I changed the SPSecurityTrimmedControl control to use the EditListItems permission and published the master page, the user was still not seeing the ribbon.

After a couple of tests using different permissions, I found an article by Infowise explaining  the details of the SPSecurityTrimmedControl control and the usage of the PermissionContext property. This property controls the scope of the PermissionString property and by default is uses CurrentSite. Some of the values of the SPBasePermissions are scoped to the List or List Item.

In order to my permission check to work, I had to add the PermissionString property to the SPSecurityTrimmedControl control using the CurrentItem value:

<SharePoint:SPSecurityTrimmedControl
ID=”TrimRibbon”
PermissionsString=”EditListItems”
PermissionString=”CurrentItem”
runat=”server”>

After this change, the user was able to see the ribbon on the pages he had full control permission on and the site admins are still able to see it.

 

During my research, I also found this other article explaining a little bit more of the SPSecurityTrimmedControl control. Worth to check it out.

 

 

See you,

Amadeu.

 

Unrecognized attribute ‘targetFramework’.

Some times we receive the following error message when trying to run a .NET 4.0 or 4.5 application:

 

Unrecognized attribute ‘targetFramework’.

 
Error message
 

The cause is normally the application pool configure to run .NET 2.0 application.
 
In order to solve it, go to the application pool for your site and change it to run on .NET 4.0.
 
See you,
Amadeu.

URL Rewriting – Part 3: Integrating with SharePoint 2010

In this series of posts I’m going through the URL Rewriting process using the IIS URL Rewrite feature.

Check the previous posts out:
URL Rewriting – Part 1: The Basics
URL Rewriting – Part 2: Outbound Rule

On the previous posts we installed the feature and configured inbound and outbound rules using the IIS Rewriter. In this article we go further and show how to integrate the IIS URL Rewriter with a SharePoint site.

SharePoint 2010 Support for IIS URL Rewriter

If you search for IIS URL Rewriter on SharePoint you might see some articles about it not being supported on SharePoint 2010. It is kind of true but not completely. It will depend on the type of authentication your site is using. If you want to build a public internet site (anonymous authentication), you can use IIS URL Rewriter on your site with a few tweaks. If you’re building an intranet site (Windows or Claims authentication) you’re not going to be able to use IIS URL Rewriter.

When I first started trying to integrate IIS URL Rewriter and SharePoint 2010 I was building a public internet on my DEV environment and it was configured for both Windows and anonymous authentication. I noticed the anonymous part (mainly content and web part pages) worked fine but the administrative part (list management, user management and settings pages) didn’t. It would always ask me for authentication and it never had a consistent behavior. Every time I tried one of the administrative pages asked for authentication.

Installation

You should install the IIS Rewrite feature on all SharePoint WFE servers. The installation on SharePoint uses the very same process described on the first part of the series.

Tweaks for SharePoint 2010

Disable the LogRewrittenUrlEnabled property

On the WFE servers execute the following command:
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\Rewrite /v LogRewrittenUrlEnabled /t REG_DWORD /d 0


Edit the web.config file

Add the following node under configuration/system.webServer in order to change compression settings:

<urlCompression doStaticCompression=”false” doDynamicCompression=”true” dynamicCompressionBeforeCache=”false” />

Restart IIS

Execute an IISRESET command on all WFE servers.

Testing Inbound and Outbound Rules

Edit the web.config file for your site on all WFE servers.

Add a new inbound and outbound rules to test on your site. Here is a simple example you can add to your web.config under the configuration/system.webServer node:

<rewrite>
  <rules>
    <rule name="Home Page Rewrite" stopProcessing="true">
      <match url="^(/$|$)" />
      <action type="Rewrite" url="/pages/default.aspx" />
    </rule>
  </rules>
  <outboundRules>
    <rule name="Home Page Outbound Rewrite" stopProcessing="true">
      <match filterByTags="A, Link" pattern="(/?)pages/default\.aspx$" />
      <conditions>
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </conditions>
      <action type="Rewrite" value="{R:1}" />
    </rule>
  </outboundRules>
</rewrite>

These rules will remove the home page redirect from the browser’s address bar and rebuild all the links to the home page to point to /.

References

http://codeblog.shawson.co.uk/iis7-urlrewrite-outbound-links-with-compression-enabled/

http://blogs.msdn.com/b/danielvl/archive/2010/01/07/registry-values-for-iis-url-rewrite.aspx

On the next articles of this series we will talk about custom IIS Rewriter providers and how to implement them.

See you,

Amadeu.

How to Schedule a Powershell Script to Run on Windows 2008

It is a little bit tricky to configure a Powershell  script to run on the task scheduler on Windows 2008.

The separation between the powershell.exe command and the arguments makes a little confusion.

The way I did it was:

  • Create a new task.
  • Define a schedule.
  • Add an action:
    • Program/script: Powershell
    • Add arguments: -command &{E:\scripts\ClearIISLogs.ps1}

Now you just need to run your script and make sure it works as expected.

 

See you,

Amadeu.

How to Check if .NET 4.5 Is Installed on a Server

In order to check if your server has .NET Framewrok 4.5 installed you can go to the Registry and look for the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client

Check the Version value. If it starts with “4.0” you are running on the 4.0 runtime, if it starts with “4.5” you are running on the 4.5 runtime.

See you,
Amadeu.

Retrieve a List of All Items Checked Out in a Site using Powershell

Hi there!

This is a scripts to list files which are currently checked out on a site collection. Some times users check files out and forget to check them back in. It was based on a script found at http://www.thorntontechnical.com/tech/powershell-tech/powershell-tip-find-all-checked-out-files.

$webAppURL = "http://yourwebapplication.com" 

function ReportCheckedOutItems() {
	$webapp = Get-SPWebApplication $webAppURL

	foreach ($site in $webapp.Sites) 
	{
		write-host "Site Collection: $($site.Url)"
		$allwebs = $site.allwebs
		foreach($web in $allwebs)
		{
			$count = 0
			write-host "--Site: $($web.Url)"
			foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
				Write-Host "-----List: $($list.RootFolder.ServerRelativeUrl)..."
				foreach ($item in $list.CheckedOutFiles) 
				{
					if (!$item.Url.EndsWith(".aspx")) 
					{ 
						continue 
					}
					write-host "File: $($item.Url) - checked out by $($item.CheckedOutBy)" -ForeGroundColor Red
					$count++
				}
				foreach ($item in $list.Items) 
				{
					if ($item.File.CheckOutStatus -ne "None") 
					{
						if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) 
						{ 
							continue 
						}
						write-host "File: $($item.Url) - checked out by $($item.CheckedOutBy)" -ForeGroundColor Red
						$count++
					}
				}
			}
			if ($count -gt 0)
			{
				write-host "Found $count checked out files for site $web" -ForeGroundColor Red
			}
		}
	}
}

ReportCheckedOutItems

 

You can download the script file here

I hope it is useful for you as it is for me.

 

See you,

Amadeu.