Error 401 Unauthorized Exception with Managed Client Object Model on ASP.NET website

I am trying to access a file permission from a separate ASP.NET web application using Managed Client Object Model. Since I need to get the user’s permission I have to use CredentialCache.DefaultCredentials. Everything runs fine using Visual Studio debug mode but I hit the following error when I host the site on IIS (same as SharePoint but difference web app)


[WebException: The remote server returned an error: (401) Unauthorized.]
DocViewer._default.Page_Load(Object sender, EventArgs e) in C:\Users\administrator\Documents\Visual Studio 2010\Projects\SharePointDocViewer\DocViewer\default.aspx.vb:174
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

Most blogs on the web suggested instantiating a new NetworkCredential but that is not the way to go for my case.

I eventually solved the problem by setting the App Pool of the ASP.NET to be that of the SharePoint app pool. Below is fragment of my code using SPCOM.


Using client As ClientContext = New ClientContext(Request.QueryString("portalUrl"))
Try
client.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim web = client.Web
Dim file As SharePoint.File = web.GetFileByServerRelativeUrl(Request.QueryString("fileUrl"))
Dim item As ListItem = file.ListItemAllFields

client.Load(item, Function(i) i.EffectiveBasePermissions)
client.ExecuteQuery()

User Profile Synchronization Service cannot be started

Just setup a new VM and I was having problem starting User Profile Synchronization Service for the passed few days despite following all the steps outline in TechNet. Finally I figured out the only thing different on my new VM is that the Windows User Account Control feature is enabled.

Everything works flawlessly now after I disable UAC and restart the server! Smile

Missing Microsoft.Web.Infrastructure

Products such as RavenDB which includes an option to deploy it as a IIS web service, however it has dependency on non core .NET Framework assemblies such as in my case Microsoft.Web.Infrastructure.

If you do a clean install of IIS on Windows Server and try to deploy RavenDB, you will encounter a Microsoft.Web.Infrastructure.dll not found error.

To fix this just download the Web Platform Installer (http://microsoft.com/web) on your Windows Server and install the ASP.NET Web Pages component on your Windows Server

ScreenClip(35)

Entity Framework Code First Migrations Beta 1 released

Got the news that the migration tool has been updated 5 days ago by the ADO.NET team.

You can get the package from NuGet using the command Install-Package EntityFramework.Migrations or Update-Package EntityFramework.Migrations if you have Alpha 3 installed. Going forward the migration tool will be RTM’ed as part of Entity Framework 4.3.

For someone coming from Alpha, I see a few changes

1. Settings.cs inside Migration folder has been replaced with Configuration.cs. You have to delete the old Settings.ca file

2. ChangeColumn API is now called AlterColumn