<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Inconvenient programmatically working with SharePoint users (SPWeb.EnsureUser)</title>
	<atom:link href="http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/</link>
	<description>Innovation Matters &#124; SharePoint Server MVP &#124; ISSN 2210-9390</description>
	<lastBuildDate>Fri, 10 Feb 2012 18:00:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: dotNetFollower</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-88888</link>
		<dc:creator>dotNetFollower</dc:creator>
		<pubDate>Tue, 16 Aug 2011 02:13:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-88888</guid>
		<description>Hello!
Very nice article. I worked with EnsureUser and found out that there are a few other inconveniences. For example, we need almost always to use elevated privileges to deal with EnsureUser, otherwise exception will be thrown. Or for example, if user doesn&#039;t exist in user collection, it will be tried to add to this collection, but this means that spWeb object will be modified and it&#039;s required AllowUnsafeUpdates = true. Eventually, I&#039;ve developed a small method-wrapper for EnsureUser. It&#039;s shown in my blog - &lt;a href=&quot;http://dotnetfollower.com/wordpress/2011/05/sharepoint-wrapper-over-ensureuser/&quot; rel=&quot;nofollow&quot;&gt;http://dotnetfollower.com/wordpress/2011/05/sharepoint-wrapper-over-ensureuser/&lt;/a&gt;
Thanks!</description>
		<content:encoded><![CDATA[<p>Hello!<br />
Very nice article. I worked with EnsureUser and found out that there are a few other inconveniences. For example, we need almost always to use elevated privileges to deal with EnsureUser, otherwise exception will be thrown. Or for example, if user doesn&#039;t exist in user collection, it will be tried to add to this collection, but this means that spWeb object will be modified and it&#039;s required AllowUnsafeUpdates = true. Eventually, I&#039;ve developed a small method-wrapper for EnsureUser. It&#039;s shown in my blog &#8211; <a href="http://dotnetfollower.com/wordpress/2011/05/sharepoint-wrapper-over-ensureuser/" rel="nofollow">http://dotnetfollower.com/wordpress/2011/05/sharepoint-wrapper-over-ensureuser/</a><br />
Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Moninder</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-79849</link>
		<dc:creator>Moninder</dc:creator>
		<pubDate>Thu, 19 May 2011 16:49:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-79849</guid>
		<description>Thanks a lot. This saved me lot of time troubleshooting. You rock! I was struggling getting the user&#039;s added since our web app uses claims based authentication</description>
		<content:encoded><![CDATA[<p>Thanks a lot. This saved me lot of time troubleshooting. You rock! I was struggling getting the user&#039;s added since our web app uses claims based authentication</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Moninder</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-79848</link>
		<dc:creator>Moninder</dc:creator>
		<pubDate>Thu, 19 May 2011 16:48:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-79848</guid>
		<description>Thanks a lot. This saved me lot of time troubleshooting. You rock!</description>
		<content:encoded><![CDATA[<p>Thanks a lot. This saved me lot of time troubleshooting. You rock!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ignacio F</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-63383</link>
		<dc:creator>Ignacio F</dc:creator>
		<pubDate>Tue, 14 Dec 2010 20:53:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-63383</guid>
		<description>You just took my stress away! Great post and the snippets work like a charm. Thank you SO much. Cheers!</description>
		<content:encoded><![CDATA[<p>You just took my stress away! Great post and the snippets work like a charm. Thank you SO much. Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Waldek Mastykarz</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-60996</link>
		<dc:creator>Waldek Mastykarz</dc:creator>
		<pubDate>Mon, 22 Nov 2010 14:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-60996</guid>
		<description>@Dilip V.: great to hear you got it all working. You&#039;re welcome :)</description>
		<content:encoded><![CDATA[<p>@Dilip V.: great to hear you got it all working. You&#039;re welcome :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dilip V.</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-60995</link>
		<dc:creator>Dilip V.</dc:creator>
		<pubDate>Mon, 22 Nov 2010 13:54:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-60995</guid>
		<description>Hi Waldek Mastykarz,

Now I m able to create new user. Thank you very much. You are SharePoint Guru(Teacher).

After replacing SPControl.GetContextWeb with spSite.OpenWeb(); I got error:
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

I refered the site:
http://www.bizsupportonline.net/blog/2008/12/microsoftsharepointspexception-the-security-validation-for-this-page-is-invalid-error-infopath-browser-forms/
and added below code
spWeb.AllowUnsafeUpdates = true;
string userName = \&quot;fbamembership\&quot; + Username.Text;
SPUser spUser = spWeb.EnsureUser(userName);
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);
spWeb.AllowUnsafeUpdates = false;
I wanted to know, r u online every time because I got ur response everytime immediately.

Once again Thank You Guru.</description>
		<content:encoded><![CDATA[<p>Hi Waldek Mastykarz,</p>
<p>Now I m able to create new user. Thank you very much. You are SharePoint Guru(Teacher).</p>
<p>After replacing SPControl.GetContextWeb with spSite.OpenWeb(); I got error:<br />
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</p>
<p>I refered the site:<br />
<a href="http://www.bizsupportonline.net/blog/2008/12/microsoftsharepointspexception-the-security-validation-for-this-page-is-invalid-error-infopath-browser-forms/" rel="nofollow">http://www.bizsupportonline.net/blog/2008/12/microsoftsharepointspexception-the-security-validation-for-this-page-is-invalid-error-infopath-browser-forms/</a><br />
and added below code<br />
spWeb.AllowUnsafeUpdates = true;<br />
string userName = \&quot;fbamembership\&quot; + Username.Text;<br />
SPUser spUser = spWeb.EnsureUser(userName);<br />
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);<br />
spWeb.AllowUnsafeUpdates = false;<br />
I wanted to know, r u online every time because I got ur response everytime immediately.</p>
<p>Once again Thank You Guru.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dilip V.</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-60994</link>
		<dc:creator>Dilip V.</dc:creator>
		<pubDate>Mon, 22 Nov 2010 13:53:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-60994</guid>
		<description>Hi Waldek Mastykarz,

Now I m able to create new user. Thank you very much. You are SharePoint Guru(Teacher).

After replacing SPControl.GetContextWeb with spSite.OpenWeb(); I got error:
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

I refered the site:
http://www.bizsupportonline.net/blog/2008/12/microsoftsharepointspexception-the-security-validation-for-this-page-is-invalid-error-infopath-browser-forms/
and added below code
spWeb.AllowUnsafeUpdates = true;
string userName = &quot;fbamembership&quot; + Username.Text;
SPUser spUser = spWeb.EnsureUser(userName);
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);
spWeb.AllowUnsafeUpdates = false;
I wanted to know, r u online every time because I got ur response everytime immediately.

Once again Thank You Guru.</description>
		<content:encoded><![CDATA[<p>Hi Waldek Mastykarz,</p>
<p>Now I m able to create new user. Thank you very much. You are SharePoint Guru(Teacher).</p>
<p>After replacing SPControl.GetContextWeb with spSite.OpenWeb(); I got error:<br />
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</p>
<p>I refered the site:<br />
<a href="http://www.bizsupportonline.net/blog/2008/12/microsoftsharepointspexception-the-security-validation-for-this-page-is-invalid-error-infopath-browser-forms/" rel="nofollow">http://www.bizsupportonline.net/blog/2008/12/microsoftsharepointspexception-the-security-validation-for-this-page-is-invalid-error-infopath-browser-forms/</a><br />
and added below code<br />
spWeb.AllowUnsafeUpdates = true;<br />
string userName = &#034;fbamembership&#034; + Username.Text;<br />
SPUser spUser = spWeb.EnsureUser(userName);<br />
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);<br />
spWeb.AllowUnsafeUpdates = false;<br />
I wanted to know, r u online every time because I got ur response everytime immediately.</p>
<p>Once again Thank You Guru.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Waldek Mastykarz</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-60990</link>
		<dc:creator>Waldek Mastykarz</dc:creator>
		<pubDate>Mon, 22 Nov 2010 13:09:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-60990</guid>
		<description>@Dilip V.: replace SPControl.GetContextWeb with spSite.OpenWeb(); Additionally if you&#039;re running in the context of a Web Application you don&#039;t need to reset the context.</description>
		<content:encoded><![CDATA[<p>@Dilip V.: replace SPControl.GetContextWeb with spSite.OpenWeb(); Additionally if you&#039;re running in the context of a Web Application you don&#039;t need to reset the context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dilip V.</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-60989</link>
		<dc:creator>Dilip V.</dc:creator>
		<pubDate>Mon, 22 Nov 2010 13:00:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-60989</guid>
		<description>In my code, I have not added \ which came by default before &quot;</description>
		<content:encoded><![CDATA[<p>In my code, I have not added \ which came by default before &#034;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dilip V.</title>
		<link>http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/comment-page-1/#comment-60988</link>
		<dc:creator>Dilip V.</dc:creator>
		<pubDate>Mon, 22 Nov 2010 12:56:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.mastykarz.nl/inconvenient-programmatically-sharepoint-users-spweb-ensureuser/#comment-60988</guid>
		<description>Hi Waldek Mastykarz,
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate
{
string strSiteURL = \&quot;http://ps2010\&quot;;
SPSite spSite = new SPSite(strSiteURL);
SPWeb spWeb = SPControl.GetContextWeb(HttpContext.Current);
if (HttpContext.Current == null)
{
HttpRequest request = new HttpRequest(\&quot;\&quot;, spWeb.Url, \&quot;\&quot;);
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
HttpContext.Current.Items[\&quot;HttpHandlerSPWeb\&quot;] = spWeb;
}
string userName = \&quot;fbamembership\&quot; + Username.Text;
SPUser spUser = spWeb.EnsureUser(userName);
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);
});
Tried the above code but still fails, any other idea.</description>
		<content:encoded><![CDATA[<p>Hi Waldek Mastykarz,<br />
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate<br />
{<br />
string strSiteURL = \&quot;<a href="http://ps2010" rel="nofollow">http://ps2010</a>\&quot;;<br />
SPSite spSite = new SPSite(strSiteURL);<br />
SPWeb spWeb = SPControl.GetContextWeb(HttpContext.Current);<br />
if (HttpContext.Current == null)<br />
{<br />
HttpRequest request = new HttpRequest(\&quot;\&quot;, spWeb.Url, \&quot;\&quot;);<br />
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));<br />
HttpContext.Current.Items[\&quot;HttpHandlerSPWeb\&quot;] = spWeb;<br />
}<br />
string userName = \&quot;fbamembership\&quot; + Username.Text;<br />
SPUser spUser = spWeb.EnsureUser(userName);<br />
SPRoleAssignment roleAssignment = new SPRoleAssignment(spUser);<br />
});<br />
Tried the above code but still fails, any other idea.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

