maandag 14 november 2011

New blog location

I've recently moved my blogging activities to a new website: http://www.skavi.be because that is the consulting company I founded in september.

Thanks!

donderdag 24 maart 2011

Setting IP restrictions on your central administration server in IIS with PowerShell

To set an IP restriction on your central administration with PowerShell you need to do the following:

- First set deny all
Set-WebConfigrationProperty –Filter system.webServer/security/ipSecurity –PSPath ‘IIS:\’ –Name allowUnlisted –Location “SharePoint Central Administration v4” –Value $false

- Second set allow for a specific IP Address
Add-WebConfiguration system.webServer/security/ipSecurity –location “IIS:\Sites\SharePoint Central Administration v4” –Value @{ipAddress=”$(Get-IPAddress)”;allowed=”true”} –PSPath IIS:\

The Get-IPAddress function is a function to get the IP address of the current PC:

function Get-IPAddress() {

return (gwmi Win32_NetworkAdapterConfiguration |? { $_.IPAddress –ne $null }).IPAddress

}

woensdag 14 juli 2010

SecurityException in WebParts when making SharePoint API calls

Latest webpart I made I had strange problems with the following lines of code:

SPWeb rootWeb = SPContext.Current.Site.RootWeb; 
string siteInfoUnserialized = rootWeb.Properties[Constants.SOMEKEY]; // SecurityException here

Even though I was logged in as System Administrator this exception got thrown. This error is very likely to happen due to a lack of a good nights rest, resulting in placing code in the constructor (I still can’t remember why I did that).

Placing the API code inside the OnInit function (or similar) solves the problem. The cause is that during the constructor call not everything is initialized properly.

Other possible causes (not applicable for me) are that the CAS file is not correct thus not having enough rights or the webpart dll is not in the GAC (if you do it this way, Microsoft recommends bin deployment with CAS policies)

Reference to a deeper blogpost about this by Robert Bogue: http://www.thorprojects.com/blog/archive/2008/04/16/web-part-event-firings-and-why-you-shouldn%E2%80%99t-have-code-in-the-constructor.aspx

dinsdag 25 mei 2010

Debugging Powershell Cmdlets V2

As I was trying to debug my custom powershell commandlets through visual studio I had the problem that it was not hitting the breakpoints automatically when running through F5.

The trick is to create a powershell.exe.cfg in your PowerShell folder (C:\Windows\System32\WindowsPowerShell\v1.0):

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
   <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

The other steps to follow are still quite the same as Bart De Smet has explained in his blogpost here: http://bartdesmet.net/blogs/bart/archive/2008/02/03/easy-windows-powershell-cmdlet-development-and-debugging.aspx

Some things I did differently are setting post build events like this:

@SET GACUTIL="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe"
@SET INSTALLUTIL="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\installutil.exe"

%GACUTIL% -if Shaks.PowerShell.SharePoint.Cmdlets
%INSTALLUTIL% -i Shaks.PowerShell.SharePoint.Cmdlets.dll

In the Debug-tab of the project properties I start an external program (powershell.exe) with the following attributes:

-PSConsoleFile Shaks.PowerShell.SharePoint.Cmdlets.psc1  -noexit

I’ll post my psc1 file here for reference, although you can just generate this:

<?xml version="1.0" encoding="utf-8"?>
<PSConsoleFile ConsoleSchemaVersion="1.0">
  <PSVersion>2.0</PSVersion>
  <PSSnapIns>
    <PSSnapIn Name="shaks.powershell.sharepoint.cmdlets" />
  </PSSnapIns>
</PSConsoleFile>

The commandlet itself will be for a next blogpost.

woensdag 11 februari 2009

Making POP3 & SMTP Server work with windows server 2008

Not so long ago we switched our sharepoint development environments from windows server 2003 to windows server 2008. Everything is working very smooth until we need to start sending and receiving e-mail.

*Shock* No more POP3 available OOTB in 2008. Microsoft has stopped shipping this product with the 2008 version, so the POP service has only been around for one version of windows server. The reason I believe was that it is not necessary for server environments as there are better options available for processing mail etc.

Now a POP3 server is something I need to be able to keep my VPC lightweight (no exchange needed), but still be able to test mail sending (like alerts) locally. Lucky for us the Hannes Preishuber has made an extension for windows server 2008 that makes this possible for us.

http://weblogs.asp.net/hpreishuber/archive/2008/04/30/visendo-smtp-pop3-extender-for-windows-2008-server.aspx

Now how do Install this? There is a small installation procedure available at that blogpost, but for me – being not so experienced in that area – it took a while to get up and running decently.
I will write down the steps I took to get it working here:

 

A) Installing the SMTP feature that is available (optionally) in win2k8 server

  1. Open up your “Server Manager” and go to “Features”
    image
  2. Click on “Add Features”
    image
  3. Select “SMTP Feature” (Already installed in my next screenshot)
    image
  4. Click install and follow the steps (this might take a while)
  5. To manage your SMTP Server you can go to IIS 6.0
  6. Make sure it is started
    image

If you encounter problems later like “Unable to relay” you can fix this by going to IIS6.0

  1. Go to the properties of your SMTP Virtual Server
    image
  2. Go to Access > Relay…
    image
  3. Select “All except the list below”
    image

 

B) Installing the POP3 Extender from Visendo

  1. Install the installer found here: http://weblogs.asp.net/hpreishuber/archive/2008/04/30/visendo-smtp-pop3-extender-for-windows-2008-server.aspx
    - note: next steps are copied from the blogpost above, I’ll just add some comments between the lines
  2. Move "visendosmtpextender_sample.config" from "C:\Program Files\ppedv\visendosmtpextender" to "C:\Documents and Settings\All Users\Application Data\ppedv\visendosmtpextender"
    - To easily get to this path just copy it and paste it in Start > Run. Otherwise if you go looking for c:\documents and settings (or just type this in) you might get an Access Denied error
  3. Rename to "visendosmtpextender_sample.config" to "visendosmtpextender.config"
  4. Edit "visendosmtpextender.config"
    - To give you an idea, my config looks like this:
    image 
    This will create a mailbox for
    administrator@moss.localhost, adjust to your own needs
  5. Start service "Visendo SMTP Extender Service 2008"
    image

C) Configuring outlook

  1. Go to Tools > Account Settings
    image
  2. Create a new account
    image
  3. Select manually configure server settings or additional server types > Next > Internet E-mail > Next
    image
  4. Fill in the following settings
    image
    - Note: I have set my IP to 192.168.1.1 because that’s the way I set it in my VPC
  5. Test your settings by clicking “Test Settings”
    image 
    Everything should complete correctly

 

Possible issues:

- Your mails are staying put in c:/inetpub/mailroot/queue
Solution: Define aliases for your hostnames in IIS6.0 SMTP Virtual Server like this:
image

I hope this helps someone. Leave a message if I missed something or if you think something could be done better.

Have a nice day,

Jeroen

maandag 17 november 2008

Access denied while activating publishing features

Not so long ago I encountered a strange error on a sharepoint configuration: a site collection administrator was getting "Access Denied" errors while trying to activate the publishing site collection features.
As his account had nearly every security right available in that company (way too much) this error was very strange to get.
After some research I tried switching the application pool account of the portal to that of the central administration and apparantly this did the trick.

So the access denied was not received from the actual users account, but from the account the user was elevated to: the identity of the application pool (found in ISS > Application Pools > Your Pool > Properties > Identity).
My guess is that this account did not have enough access to the content databases to perform this action.

Note: This sharepoint configuration was installed by the book of the Microsoft configuration and I've heard other reports of configuration problems when doing this.
I'm no configuration expert so I don't know what right exactly was missing or where in this guide it is going wrong.

donderdag 6 november 2008

Using a centrally manageable custom masterpage

The standard microsoft way of deploying a custom masterpage is by making a custom provisioning feature that deploys your masterpage and all of its assets to the _catalogs/masterpages folder of your site collection.

Imagine if at the moment of deployment there is no certainty on how the masterpage will be in a certain amount of time and it is bound to change.

Are you going to manually deactivate and reactivate all these features or should there be another way?

Today I'm going to show you another way to centrally manage your masterpage so you only have to adjust it on one place.. you guessed it right: the layouts folder!

If you try to change one of the 4 masterpage tokens ( ~masterurl/default.master ; ~masterurl/custom.master ; ~site/custom.master ; ~sitecollection/custom.master) to a masterpage located in your layouts directory you get an error (the referenced file is not allowed on this page) telling you that this is an unsupported attribute.
Now how will we solve this issue? We will create a httpModule that will replace the masterpageurl in the pre-init event of the loaded page.

Step 1:
Copy your masterpage in your layouts folder (12/Template/Layouts/MyProject)

Step 2:
Create MasterPageModule.cs
> Let this class inherit from System.Web.IHttpModule
> Implement the Init() and Dispose()


public class MasterPageModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
}

void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
page.PreInit += new EventHandler(page_PreInit);
}

void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (SPContext.Current.Web.WebTemplateId == 10001)
if (page != null)
if(page.MasterPageFile != null && page.MasterPageFile.ToLower().Contains("application.master"))
page.MasterPageFile = "/_layouts/CustomMasterPages/customApplication.master";
else
page.MasterPageFile = "/_layouts/CustomMasterPages/custom.master";
}

public void Dispose()
{
}
}

As you can see I use the PreInit event of the Page to change my masterpage to either the application masterpage or either the normal masterpage. I do this because the application masterpage needs to have 2 more contentplaceholders than in the regular default.master. For more information on this, take a look at Toms blog (references at the bottom of this post)
So what happens when we load a page: The page goes through its cycle and enters the PreInit fase, where this code kicks in and changes the masterpage accordingly.

Note 1: It isn't officially supported to change your default application.master
Note 2: It is possible that your Page already implements the PreInit. If this happens this code won't be run. F.e.: Most (if not all) publishing pages use the PreInit to change the masterpage to that of the currentWebs selected masterpage.

Step 3:
Strong name your dll, build it and put it in your global assembly cache (GAC)

Step 4:
Register your HttpModule in the web.config
Open your web.config and place the following line just before the </httpModules>:
<add name="MyModule" type="MyNameSpace.MasterPageModule, ##### Fully qualified name #####" />
To find your fully qualified name I would recommend using Red Gate's Reflector, I put the link to it in a previous post.

Step 5:
Enjoy.. that's all! Since we changed the web.config, doing an iisreset (or recycling the application pools) is not needed anymore. Whenever a change to the web.config is saved IIS does this automatically for you.

Note:
If you have pages made with the publishing contenttypes chances are very high that there will be an OnPreInit event already firing on the Page itself, thus overriding your own modules onpreinit.. be wary of this!

Some references on masterpages:
- http://jopx.blogspot.com/2007/09/ten-things-you-should-know-about.html
This is a good reference on masterpages in sharepoint in general, very recommended

- http://tomblog.insomniacminds.com/2007/10/29/sharepoint-branding-issues-application-pages/
A good reference on how to customize application masterpages

- http://support.microsoft.com/kb/307996
How to make a httpModule