Blog posts by Erik Engstrand2015-09-16T08:27:00.0000000Z/blogs/Erik-Engstrand/Optimizely WorldCreate empty database in EPiServer 8http://erikengstrand.blogspot.com/2015/09/create-empty-database-in-episerver-8.html2015-09-16T08:27:00.0000000Z<until a="" br="" center.="" clean="" create="" database="" deployment="" episerver="" from="" i="" it="" possible="" recently="" to="" was=""></until><div>Since I started with Windows 8 my Deployment Center doesn't work anymore. Even after trying the <a href="http://dotnetcake.blogspot.se/2012/06/installing-episerver-6-r2-on-windows-8.html">regedit fix</a>.</div><h2>Cmdlet Initialize-EPiDatabase</h2><div>Since EPiServer version 8,8 a cmdlet "Initialize-EPiDatabase" is shipped with the nuget package EPiServer.Framework.</div><div><br /></div><div>When running this command in Package Manager Console in Visual Studio an .mdf file with the database will be created in the App_Data folder. If you want to run the database on a remote server just place the .mdf and .ldf files on in the SQL Server data\ folder and run the "Attach" command in Management Studio.</div><div><br /></div><div>But, there is a catch! The mdf database is created with the version of SQL you are running on your local computer. It's then impossible to attach the database to an older version.</div><div><br /></div><div>You will get something like this error message:</div><blockquote class="tr_bq">The database cannot be opened because it is version 782. This server supports version 706 and earlier.</blockquote><h2>Create the databse directly on the remote SQL Server </h2><div>After som digging and also asking EPiServer I found that Initialize-EPiDatabase is capable to create a database on a remote server.</div><div>Open the file \packages\EPiServer.Framework.8.10.1\tools\Upgrade.psm1 and search for "Function Initialize-EPiDatabase". You will find some useful documentation.<br /><br /><br /></div><pre class="language-csharp"><code> .Description<br /> Deploy all sql schema that can be found under nuget package. The pattern to find sql files is nugetpackage.id.version\tools\nugetpackage.id.sql.<br /> By default uses EPiServerDB connection string name and if the connection string name is different from default (EPiServerDB)<br /> then it needs a settings.config as: <br /> <settings><br /> <connectionstringname>MyConnectionString</connectionstringname><br /> </settings><br /> .SYNOPSIS <br /> Deploy epi database schema.<br /> .EXAMPLE<br /> Initialize-EPiDatabase<br /> This command deploy all epi database schema that can be found in the nuget packages. <br /> .EXAMPLE<br /> Initialize-EPiDatabase -sqlFilePattern:c:\data\mysql.sql -connectionString:MyConnectionString<br /> This command deploy mysql.sql into database by using MyConnectionString. The -connectionString can be both connection string name inthe application web config or connection string.</code></pre><div>The way I used Initialize-EPiDatabase to create a database on a remote SQL Server was to:<br /><br /><ol><li>Create an empty database on the SQL Server</li><li>In Web.config have a proper connectionstring named EPiServerDB which points to your empty database.</li><li>Run Initialize-EPiDatabase in Package Manager Console</li></ol><div>One more catch. The cmdlet Initialize-EPiDatabase did not work in Visual Studio 2015 and nuget Package Manager version 3.1.60724.766. It worked in Visual Studio 2013.</div></div><div><br /></div><div>Error message in VS 2015 (something wrong with detection of packed folders):</div><pre class="language-csharp"><code>copy-Item : Cannot find path 'C:\projects\Borlange.se\Main\Source\Borlange\packages\EPiServer.Framework.8.0.0\EPiServer.Framework.8.0.0\tools\epidepl<br />oy.exe' because it does not exist.<br />At C:\projects\Borlange.se\Main\Source\Borlange\packages\EPiServer.Framework.8.0.0\tools\upgrade.psm1:157 char:2<br />+ copy-Item $epiDeployPath -Destination $exportRootPackageName<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : ObjectNotFound: (C:\projects\Bor...s\epideploy.exe:String) [Copy-Item], ItemNotFoundException<br /> + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand<br /></code></pre>Create clean empty database in EPiServer 8http://erikengstrand.blogspot.com/2015/09/create-empty-database-in-episerver-8.html2015-09-16T08:27:00.0000000Z<until a="" br="" center.="" clean="" create="" database="" deployment="" episerver="" from="" i="" it="" possible="" recently="" to="" was=""></until><br /><div>Since I started with Windows 8 my Deployment Center doesn't work anymore. Even after trying the <a href="http://dotnetcake.blogspot.se/2012/06/installing-episerver-6-r2-on-windows-8.html">regedit fix</a>.</div><h2>Cmdlet Initialize-EPiDatabase</h2><div>Since EPiServer version 8,8 a cmdlet "Initialize-EPiDatabase" is shipped with the nuget package EPiServer.Framework.</div><div><br /></div><div>When running this command in Package Manager Console in Visual Studio an .mdf file with the database will be created in the App_Data folder. If you want to run the database on a remote server just place the .mdf and .ldf files on the SQL Server data\ folder and run the "Attach" command in Management Studio.</div><div><br /></div><div>But, there is a catch! The mdf database is created with the version of SQL you are running on your local computer. It's then impossible to attach the database to an older version.</div><div><br /></div><div>You will get something like this error message:</div><blockquote class="tr_bq">The database cannot be opened because it is version 782. This server supports version 706 and earlier.</blockquote><h2>Create the database directly on the remote SQL Server </h2><div>After som digging and also asking EPiServer I found that Initialize-EPiDatabase is capable of creating a database on a remote server.</div><div>Open the file \packages\EPiServer.Framework.8.10.1\tools\Upgrade.psm1 and search for "Function Initialize-EPiDatabase". You will find some useful documentation.<br /><br /><br /></div><pre class="language-csharp"><code> .Description<br /> Deploy all sql schema that can be found under nuget package. The pattern to find sql files is nugetpackage.id.version\tools\nugetpackage.id.sql.<br /> By default uses EPiServerDB connection string name and if the connection string name is different from default (EPiServerDB)<br /> then it needs a settings.config as: <br /> <settings><br /> <connectionstringname>MyConnectionString</connectionstringname><br /> </settings><br /> .SYNOPSIS <br /> Deploy epi database schema.<br /> .EXAMPLE<br /> Initialize-EPiDatabase<br /> This command deploy all epi database schema that can be found in the nuget packages. <br /> .EXAMPLE<br /> Initialize-EPiDatabase -sqlFilePattern:c:\data\mysql.sql -connectionString:MyConnectionString<br /> This command deploy mysql.sql into database by using MyConnectionString. The -connectionString can be both connection string name inthe application web config or connection string.</code></pre><div>The way I used Initialize-EPiDatabase to create a database on a remote SQL Server was to:<br /><ol><li>Create an empty database on the SQL Server</li><li>In Web.config have a proper connectionstring named EPiServerDB which points to your empty database.</li><li>Run Initialize-EPiDatabase in Package Manager Console</li></ol><div>One more catch. The cmdlet Initialize-EPiDatabase did not work in Visual Studio 2015 and nuget Package Manager version 3.1.60724.766. It worked in Visual Studio 2013.</div></div><div><br /></div><div>Error message in VS 2015 (something wrong with detection of packege folders):</div><pre class="language-csharp"><code>copy-Item : Cannot find path 'C:\projects\Borlange.se\Main\Source\Borlange\packages\EPiServer.Framework.8.0.0\EPiServer.Framework.8.0.0\tools\epidepl<br />oy.exe' because it does not exist.<br />At C:\projects\Borlange.se\Main\Source\Borlange\packages\EPiServer.Framework.8.0.0\tools\upgrade.psm1:157 char:2<br />+ copy-Item $epiDeployPath -Destination $exportRootPackageName<br />+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br /> + CategoryInfo : ObjectNotFound: (C:\projects\Bor...s\epideploy.exe:String) [Copy-Item], ItemNotFoundException<br /> + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand<br /></code></pre>Custom rendering of EPiServer.Url image property with figcaptionhttp://erikengstrand.blogspot.com/2013/11/custom-rendering-of-episerverurl-image.html2013-11-21T10:31:00.0000000ZI'm back blogging after some years of absense. Let's see if I'll continue.<br />For some time I have been developing a new EPiServer 7 CMS site in ASP.NET MVC. I got stuck into a problem last week. I tried the forum, but no answer! <a href="http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=77240&epslanguage=en">http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=77240&epslanguage=en</a><br /><h2>The problem</h2><div>I had an Url-property for images in my page type. The property was marked with [UIHint(UIHint.Image)]. The display template Image.cshtml rendered the image nicely. </div><div>But, I wanted to render the Image with some extra functionality:</div><div><ul><li>A Css classon the img-tag.</li><li>Image caption, text fetched from the file summary of the EPiServer image file. This caption should be inside the property to be edited in edit mode.</li></ul><h3>First test</h3></div><div>Code placed right in the page view, adding EditAttributes to tell EPiServer that the whole <figure> tag will be clickeable to edit the property.</figure></div><div><div><span style="font-family: Courier New, Courier, monospace;"><figure tml.editattributes="" x=""> x.CurrentPage.Image)></figure></span></div><div><span style="font-family: Courier New, Courier, monospace;"> @Html.DisplayFor(x => x.CurrentPage.Image, new {CssClass = "img-responsive"})</span></div><div><span style="font-family: Courier New, Courier, monospace;"> @if (!string.IsNullOrEmpty(@Model.CurrentPage.Image.GetFileSummary().Description))</span></div><div><span style="font-family: Courier New, Courier, monospace;"> {</span></div><div><span style="font-family: Courier New, Courier, monospace;"> <figcaption>@Model.CurrentPage.Image.GetFileSummary().Description</figcaption></span></div><div><span style="font-family: Courier New, Courier, monospace;"> }</span></div></div><div><span style="font-family: inherit;"><br /></span></div><div><span style="font-family: inherit;">A display template Image.cshtml</span></div><div><div style="font-family: 'Courier New', Courier, monospace;">@model EPiServer.Url</div><div style="font-family: 'Courier New', Courier, monospace;"><br /></div><div style="font-family: 'Courier New', Courier, monospace;"><img src="@Model.Path" class="@ViewData["CssClass"]" /></div><div style="font-family: 'Courier New', Courier, monospace;"><br /></div><div><span style="font-family: inherit;">The GetFileSummary extension</span></div></div><div><div><span style="font-family: Courier New, Courier, monospace;"> public static FileSummary GetFileSummary(this Url url)</span></div><div><span style="font-family: Courier New, Courier, monospace;"> {</span></div><div><span style="font-family: Courier New, Courier, monospace;"> var summary = new FileSummary();</span></div><div><span style="font-family: Courier New, Courier, monospace;"> if (url != null)</span></div><div><span style="font-family: Courier New, Courier, monospace;"> {</span></div><div><span style="font-family: Courier New, Courier, monospace;"> var file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(HttpUtility.UrlDecode(url.ToString())) as UnifiedFile;</span></div><div><span style="font-family: Courier New, Courier, monospace;"> if (file != null)</span></div><div><span style="font-family: Courier New, Courier, monospace;"> {</span></div><div><span style="font-family: Courier New, Courier, monospace;"> var description = file.Summary.Dictionary["Description"];</span></div><div><span style="font-family: Courier New, Courier, monospace;"> summary.Description = description != null ? description.ToString() : "";</span></div><div><span style="font-family: Courier New, Courier, monospace;"> summary.Title = file.Summary.Title;</span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"> }</span></div><div><span style="font-family: Courier New, Courier, monospace;"> }</span></div><div><span style="font-family: Courier New, Courier, monospace;"> return summary;</span></div><div><span style="font-family: Courier New, Courier, monospace;"> }</span></div></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><div>public class FileSummary</div><div> {</div><div> public string Description { get; set; }</div><div><br /></div><div> public string Title { get; set; }</div><div> } </div></span></div><div><br /></div><div>This looks right att the first glance, but in edit-mode when editing the property the css class dissappears.</div><h2>The solution</h2><div>To solve this I will create a new display template which will render the whole <figure> with caption.</figure></div><div>In the page view I add a Html.ProertyFor to take care of the whole rendering. The Image view including image caption will the be rerendered when editing the property.</div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;">@Html.PropertyFor(x => x.CurrentPage.Image, new { CssClass = "img-responsive" })</span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: inherit;">Create a new image display template named ImageWithCaption.cshtml</span></div><div><span style="font-family: inherit;"><br /></span></div><div><div><span style="font-family: Courier New, Courier, monospace;">@model EPiServer.Url</span></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: Courier New, Courier, monospace;"><figure></figure></span></div><div><span style="font-family: Courier New, Courier, monospace;"> <img src="@Model.Path" class="@ViewData["CssClass"]" /></span></div><div><span style="font-family: Courier New, Courier, monospace;"> @if (!string.IsNullOrEmpty(@Model.GetFileSummary().Description))</span></div><div><span style="font-family: Courier New, Courier, monospace;"> {</span></div><div><span style="font-family: Courier New, Courier, monospace;"> <figcaption>@Model.GetFileSummary().Description</figcaption></span></div><div><span style="font-family: Courier New, Courier, monospace;"> }</span></div></div><div><span style="font-family: Courier New, Courier, monospace;"><br /></span></div><div><span style="font-family: inherit;">To tell EPiServer that the property will be rendered with this display template "ImageWithCaption" mark the property in the model like this:</span></div><div><span style="font-family: inherit;"><br /></span></div><div><div><span style="font-family: Courier New, Courier, monospace;">UIHint("ImageWithCaption")]</span></div><div><span style="font-family: Courier New, Courier, monospace;">public virtual Url Image { get; set; }</span></div></div><div><span style="font-family: inherit;"><br /></span></div><div><span style="font-family: inherit;">One problem left, when cliking to edit the property the wrong dialog for Url will show.</span></div><div>By adding a second attribute to the property we will tell EPiServer to use the Image dialog in the presentation layer = edit mode instead of the classic Url dialog.</div><div><span style="font-family: 'Courier New', Courier, monospace;"><br /></span></div><div><span style="font-family: 'Courier New', Courier, monospace;">UIHint("ImageWithCaption")]</span></div><div><div><span style="font-family: 'Courier New', Courier, monospace;">UIHint(UIHint.Image, PresentationLayer.Edit)]</span></div><div><span style="font-family: Courier New, Courier, monospace;">public </span><span style="font-family: 'Courier New', Courier, monospace;">virtual </span><span style="font-family: Courier New, Courier, monospace;">Url Image { get; set; }</span></div></div><h2>One problem still left, the caption don't update</h2><div>If I edit the property and click to open the dialog for choosing a file in the EPiServer file manager and then change the description by right clicking the file and edit file summary. The rendered image caption will not update! I don't know if it is possible to solve without adding an ugly FullRefreshPropertiesMetaData. Help if you know.</div><div><span style="font-family: inherit;"><br /></span></div>Subscription job deadlock on site with large number of users/blogs/Erik-Engstrand/Dates/2010/2/Subscription-job-deadlock-on-site-with-large-number-of-users/2010-02-08T14:03:24.0000000Z<p>On web sites with large number of users you may get a deadlock in the SQL-server when executing the EPiServer subscription job.</p> <p>The error message is something like this: <strong>Exception has been thrown by the target of an invocation. [Transaction (Process ID 105) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.]</strong></p> <p><a href="/link/d134a235dcd1449c989f5280e94fa277.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="/link/c321c42f30914a72884b10bc51b22f41.png" width="567" height="77" /></a> </p> <h2>Cause of the error</h2> <p>The error comes from the SQL-server when the subscription job executes the method ProfileManager.GetAllProfiles(). From my investigations the error appears when users are registering to the site during this method is executed. On large sites this is a very common situation. Users do register all the time. </p> <h2></h2> <h2>Solution</h2> <p>I have used Reflector to copy all code in EPiServer’s class SubscriptionJob to a new customized subscripttion job.</p> <p>I made some changes to the code. First of all there are some code that could be optimized. In my application the execution time for the subscription job has gone from 30 to 6 minutes, by implementing this fix.</p> <p>In the method protected virtual int SendSubscriptions(EPiServerProfile profile) there is no check if the user does subscribe to any pages or not. When you have large number of users and also a custom membership provider this will cause the job to run very slow. The PrincipalInfo of the users is fetched for all users. The method GetUser will be called for all users in the membership provider. <br />Some small changes to the code will fix this issue. Just check if the profile does subscribe to more than zero pages.</p> <div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 151.15%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; height: 166px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"> <pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">int</span> SendSubscriptions(EPiServerProfile profile)</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">int</span> num = 0;</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">if</span> (profile.SubscriptionInfo.SubscribedPages.Count > 0)</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> {</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> IPrincipal principal = PrincipalInfo.CreatePrincipal(profile.UserName);</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #0000ff">foreach</span> (SubscriptionDescriptor descriptor <span style="color: #0000ff">in</span> profile.SubscriptionInfo.SubscribedPages)</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> {</pre>
<!--CRLF--></div>
</div>
<p> </p>
<p>The solution to the real problem is more difficult. I have been able to get rid of many deadlocks but not all.</p>
<p>The profiles are fetched in blocks of 1000 in the subscription job. Between every 1000 some work is done for sending subscription emails to the users. This takes some time. For the next 1000 users it can be a deadlock. I think this occurs if a new user have registered during this time.</p>
<p>I tried to increase the pageSize for the methodProfileManager.GetAllProfiles() to decrease the time between the first and the last profile. The deadlocks are almost gone. Is there any reason why EPiServer do this job in page sizes of 1000? Is there a better solution to this problem?</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 150.56%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; height: 210px; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">string</span> InternalExecute()</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">int</span> num3;</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> ProfileInfoCollection infos;</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">int</span> num = 0;</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff">int</span> num2 = 0;</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #0000ff">int</span> pageSize = 200000;</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> Label_0004:</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> infos = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All, num2++, pageSize, <span style="color: #0000ff">out</span> num3);</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff">if</span> (infos.Count != 0)</pre>
<!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> {</pre>
<!--CRLF--></div>
</div>Users statistics gadget/blogs/Erik-Engstrand/Dates/2009/11/Users-statistics-gadget/2009-11-07T23:59:00.0000000Z<p>After installing the EPiServer CMS 6 CTP I saw the Gadget contest on EPiSerer world. Here is my contribution to the contest. The users statistics gadget.</p>
<p>It simply displays a chart with the number of users and subscription users you have registered on the site. It’s also possible to show a chart of the users in a specific role. All settings is done in the Edit menu.</p>
<p>The chart is created in SIlverlight (<a href="http://visifire.com/" target="_blank">Visifire</a>). The Silverlight application accesses the users statistics from a WCF service. All wcf configurations is in the Gadget web.config. And therefore no need to update the web project’s web.config.</p>
<p><a href="/link/6f5ebc4507734b12816667726027d552.png"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="/link/db131a8070114cd2b50e9271f4795975.png" width="361" height="362" /></a> </p>
<p> </p>
<h1></h1>
<h2>Configuration</h2>
<p>By clicking the Edit in the menu you will see some configuration options. You can choose to show statistics for one role of all roles in the RoleMembershipProvider.</p>
<p><a href="/link/06895f5775044e98afcc3f9f952c5f30.png"><img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="image" border="0" alt="image" src="/link/dda4fe13af8c477486ad9db6c0e174ec.png" width="362" height="371" /></a> </p>
<h2>Save history data</h2>
<p>The history data is stored in the DynamicDataStore. I have created a scheduled job which should be executed once a day. </p>
<p>As seen in the image above I have made it possible to generate dummy data for the statistics. This is just for demo purposes.</p>
<h2>Installation</h2>
<p>If you have problems with the Silverlight chart. Add mime type to IIS: .xap application/x-silverlight-app. <a href="http://learn.iis.net/page.aspx/262/configuring-iis-for-silverlight-applications/" target="_blank">Configuring IIS for Silverlight Applications</a>.</p>
<p>The clientaccesspolicy.xml must be placed in the root of your project to get the Silverlight wcf reference running. This is done by the installer below.</p>
<div style="PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; FLOAT: none; PADDING-TOP: 0px" id="scid:12CF4F9E-00D5-4d59-A727-42B7641FBD93:96653902-0650-4dbe-9efd-61a5c6906761" class="wlWriterEditableSmartContent">
<div>Download <a href="/link/6a4916ebc01b4c9a805f4bd10c11a088.zip" target="_blank">UsersStatistics</a></div></div>
<h2>Source code</h2>
<div style="PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; FLOAT: none; PADDING-TOP: 0px" id="scid:12CF4F9E-00D5-4d59-A727-42B7641FBD93:238bdecb-cc7d-441a-9fb1-2bb3cdfad4b4" class="wlWriterEditableSmartContent">
<div>Download <a href="/link/db76a11cb8df45f9bc99870045464f44.zip" target="_blank">UsersStatistics</a></div></div>EPiServer Community and user attributes/blogs/Erik-Engstrand/Dates/2009/8/EPiServer-Community-and-user-attributes/2009-08-20T09:28:56.6370000Z<p>This article will give some examples of how to work with attributes on users in the EPiServer Community. Attributes can also be used on other objects in the commnuity, such as blogs, but this will not be discussed here.</p> <h3>Adding attributes</h3> <p>To get it possible to work with an attribute, you must first add it. Click on the Attributes link in the Community tab. You will get this dialog:</p> <p><a href="/link/5b283aad53a64110ba2ff382f2036fcf.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="183" alt="image" src="/link/a09f492005384d8782771aaac5ff9b7d.png" width="446" border="0" /></a> </p> <p>I will here create an attribute “ServiceIdentifier” of type string for the IUser class. It will now be possible to set this attribute on all users.</p> <p><a href="/link/4a42f43831894a5c81115c04e327a58c.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="274" alt="image" src="/link/688bcb6963684ba0947d7297ffb22761.png" width="430" border="0" /></a> </p> <p>It is also possible to create custom attribute types. You can read about it here: <a title="http://world.episerver.com/en/Articles/Items/Creating-a-Custom-EPiServer-Community-Module---Attribute-Data-Types/" href="http://world.episerver.com/en/Articles/Items/Creating-a-Custom-EPiServer-Community-Module---Attribute-Data-Types/">http://world.episerver.com/en/Articles/Items/Creating-a-Custom-EPiServer-Community-Module---Attribute-Data-Types/</a></p> <h3>Set attribute value on the user</h3> <p>I will here set a guid to this newly created attribute. CurrentUser is a property of type IUser.</p> <div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 100.21%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; height: 210px; background-color: #f4f4f4; text-align: left"> <div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"> <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060"> 1:</span> Guid guid = Guid.NewGuid();</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060"> 2:</span> <span style="color: #0000ff">if</span> (CurrentUser != <span style="color: #0000ff">null</span> && String.IsNullOrEmpty(CurrentUser.GetAttributeValue<<span style="color: #0000ff">string</span>>(<span style="color: #006080">"ServiceIdentifier"</span>)))</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060"> 3:</span> {</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060"> 4:</span> <span style="color: #008000">// Create a clone of the user to enable edit</span></pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060"> 5:</span> IUser currentUserClone = CurrentUser.Clone() <span style="color: #0000ff">as</span> IUser;</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060"> 6:</span>  </pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060"> 7:</span> currentUserClone.SetAttributeValue<<span style="color: #0000ff">string</span>>(<span style="color: #006080">"ServiceIdentifier"</span>, guid.ToString());</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060"> 8:</span>  </pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum9" style="color: #606060"> 9:</span> <span style="color: #008000">// Save everything to the user</span></pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum10" style="color: #606060"> 10:</span> CommunitySystem.CurrentContext.DefaultSecurity.UpdateUser(currentUserClone);</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum11" style="color: #606060"> 11:<font color="#000000"> </font></span>}</pre>
<!--CRLF--></div>
</div>
<h3>Get attribute value from the user</h3>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 100.06%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; height: 148px; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">if</span> (CurrentUser != <span style="color: #0000ff">null</span>)</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060"> 2:</span> {</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060"> 3:</span> <span style="color: #0000ff">return</span> CurrentUser.GetAttributeValue<<span style="color: #0000ff">string</span>>(<span style="color: #006080">"ServiceIdentifier"</span>);</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060"> 4:</span> }</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060"> 5:</span> <span style="color: #0000ff">return</span> String.Empty;</pre>
<!--CRLF--></div>
</div>
<h3>Search, find, query users given an attribute</h3>
<p>You can create very advanced queries to search for users. The method IsServiceUser checks if there exists a user with the attribute “ServiceIdentifier” set to the value of guid. I don’t know know fast this kind of queries are on a huge number of users. Does anyone know?</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 99.63%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; height: 202px; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum1" style="color: #606060"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> IsServiceUser(<span style="color: #0000ff">string</span> guid)</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum2" style="color: #606060"> 2:</span> {</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum3" style="color: #606060"> 3:</span> <span style="color: #008000">//Create a new BlogQuery</span></pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum4" style="color: #606060"> 4:</span> UserQuery uq = <span style="color: #0000ff">new</span> UserQuery();</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum5" style="color: #606060"> 5:</span> StringCriterion strCriterion = <span style="color: #0000ff">new</span> StringCriterion();</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum6" style="color: #606060"> 6:</span> strCriterion.Value = guid;</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum7" style="color: #606060"> 7:</span> uq[<span style="color: #006080">"ServiceIdentifier"</span>] = strCriterion;</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span id="lnum8" style="color: #606060"> 8:</span> <span style="color: #0000ff">return</span> CommunitySystem.CurrentContext.DefaultSecurity.GetQueryResult(uq).Count > 0;</pre>
<!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span id="lnum9" style="color: #606060"> 9:</span> }</pre>
<!--CRLF--></div>
</div>ImageVault and EPiServer page provider does not work together/blogs/Erik-Engstrand/Dates/2009/5/ImageVault-and-EPiServer-page-provider-does-not-work-together/2009-05-12T09:04:36.1300000Z<p>I have an an EPiServer CMS 5 R2 installation with ImageVault 3.3.0.541 installed. Yesterday I tried to add a custom page provider to the project. I used the XML page provider found here: <a href="http://world.episerver.com/en/Articles/Items/Introducing-Page-Providers/#download " target="_blank">http://world.episerver.com/en/Articles/Items/Introducing-Page-Providers/#download </a></p> <p>You will get the error: </p> <p><a href="/link/05f7774aa1d3485bb57b52f3d88d1889.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="332" alt="image" src="/link/f93f9f287d9548fc899bcd9557832065.png" width="365" border="0" /></a> </p> <p><em>EPiServer.BaseLibrary.ClassFactoryException: ClassFactory not initialized</em></p> <p>and</p> <p><em>[TypeInitializationException: The type initializer for 'EPiServer.DataFactory' threw an exception.]</em></p> <p>EPiServer made some changes to the startup events of the application in R1 SP3. ImageVault does not implement the startup in this new way. If you look deeper in the stack trace you will see:</p> <p><em>[Exception: Error initializing CreatedPageEvent in PluginStartup] ImageStoreNET.PluginStartup.get_CreatedPageEvent() +126</em></p> <p>ImageVault hookes up the <strong>CreatedPageEvent</strong> to early and therefore the DataFactory.Instance isn’t instantiated. </p> <h3>Get the web site running</h3> <p>The problem is with the handler <add name="ImageVault" type="ImageStoreNET.PluginStartup, ImageVault.EPiServer5" />. Just comment this line and the application will start. I don't' know what this handler does but probably ImageVault will come up with a solution soon.</p>Silverlight + EPiServerhttp://erikengstrand.blogspot.com/2009/03/silverlight-episerver.html2009-03-10T13:45:00.0000000ZFör ett tag sedan lanserade vi en site gjord i Silverlight och EPiServer CMS 5 R2. Det fungerar mycket bra och vi har gjort en hel del smarta funktioner för att hämta och spara data i EPiServer.<br /><br />Lösningen som är lite av ett Community använder mycket personalisering i .NET. Silverlight har fullt stöd för .Net profiles, authorization och authentication via WCF (Windows Communication Foundation). Detta är helt grymt bra och lätt att jobba med.<br /><br />Kanske kommer det lite mer information om siten i fråga vid ett senare tillfälle.EPiServer Scheduled jobs not working - solutionhttp://erikengstrand.blogspot.com/2009/02/episerver-scheduled-jobs-not-working.html2009-02-10T13:27:00.0000000ZHi<br /><br />You may get an error like this: Object reference not set to an instance of an object in your scheduled job. This only occurs when executing the job as scheduled, not manually.<br /><br />I had big problems with this and found the solution.<br />The HttpContext.Current is null when running the job scheduled.<br /><br />I'm using HttpContext.Current.Cache a lot when caching data in .Net. E.g. when reading from a file I usully place it in the cache with a CacheDependency attached to it.<br /><br /><strong>Example:</strong> (Does not work in EPiServer scheduled jobs)<br />public static XDocument AreaExtraItemXDocument<br />{<br />get<br />{<br />XDocument areaExtraItemXpath = (XDocument)HttpContext.Current.Cache["CacheKey"];<br />if (areaExtraItemXpath == null)<br />{<br />string xmlPath = "c:\file.xml";<br />if (File.Exists(xmlPath))<br />{<br />CacheDependency cacheDep = new CacheDependency(xmlPath);<br />areaExtraItemXpath = XDocument.Load(xmlPath);<br />HttpContext.Current.Cache.Insert("CacheKey", areaExtraItemXpath, cacheDep);<br />}<br />}<br />return areaExtraItemXpath;<br />}<br />}<br /><br /><strong>Solution:</strong><br /><br />public static XDocument AreaExtraItemXDocument<br />{<br />get<br />{<br />XDocument areaExtraItemXpath = null;<br />if (HttpContext.Current == null HttpContext.Current.Cache["CacheKey"] == null)<br />{<br />string xmlPath = "c:\file.xml";<br />if (File.Exists(xmlPath))<br />{<br />areaExtraItemXpath = XDocument.Load(xmlPath);<br />if (HttpContext.Current != null)<br />{<br />CacheDependency cacheDep = new CacheDependency(xmlPath);<br />HttpContext.Current.Cache.Insert("CacheKey", areaExtraItemXpath, cacheDep);<br />}<br />}<br />}<br />else<br />{<br />areaExtraItemXpath = (XDocument)HttpContext.Current.Cache["CacheKey"];<br />}<br />return areaExtraItemXpath;<br />}<br />}SSL redirect komponenthttp://erikengstrand.blogspot.com/2009/01/ssl-redirect-komponent.html2009-01-29T15:15:00.0000000ZJag har på en site haft behovet att redirecta mellan http och https och vice versa. Detta gäller på vissa sidor som innehåller känslig information för den inloggade användaren, tex personnummer. Kravet har då varit att det alltid måste vara https på känsliga sidor och http på övriga sidor. En lösning kan ju vara att köra https på alla sidor på siten, men det ökar trafiken väsentligt om bara en liten del av siten egentligen behöver https.<br /><br />Det finns vissa lösningar med javascript och en redirect.htm. Dock så har denna metod inte fungerat med EPiServers friendly url rewriter.<br />Lösningen var detta projekt som sköter allt det jag vill: <a href="http://www.codeproject.com/KB/web-security/WebPageSecurity_v2.aspx">http://www.codeproject.com/KB/web-security/WebPageSecurity_v2.aspx</a><br /><br />Man kan även göra alla inställningar om vilka sidor som ska vara säkra och inte i web.config, vilket är väldigt smidigt.<br /><br />Har man ISA-server så måste en del inställningar göras, enligt denna: <a href="http://goatly.spaces.live.com/blog/cns!ED869F22AB5C24A8!267.entry">http://goatly.spaces.live.com/blog/cns!ED869F22AB5C24A8!267.entry</a>EPiServer CMS Certified Developerhttp://erikengstrand.blogspot.com/2009/01/episerver-cms-certified-developer.html2009-01-28T10:48:00.0000000ZYesterday, I passed the certification for EPiServer CMS 5. The test was quiet easy and my final result was 85%.EPiServer CMS 5 R2 and 4 on the same serverhttp://erikengstrand.blogspot.com/2009/01/episerver-cms-5-r2-and-4-does-not-work.html2009-01-23T12:40:00.0000000ZI thought EPiServer CMS R2 wouldn't work on the same server as EPiServer 4. The problem was the scheduler that did not work on the EPiServer 4 site. After some testing this was not the case. Se old blog post below.<br /><br />The solution is to follow this: <a href="/link/2acac8fbf8cb4884a84bc2d48b22104e.aspx">http://world.episerver.com/en/FAQ/Items/Running-the-scheduler-on-machines-with-both-EPiServer-CMS-4-and-5-installations/</a><br />Use version 5.1.422.4, not 5.1.422.172. It seems odd, but EPiServers scheduler in R2 uses the 5.1.422.4 version.<br /><br />Also check this if you have problems that the jobs i not executed: <a href="/link/669556c5febd41a090869b4d26cbb1e4.aspx">http://world.episerver.com/FAQ/Items/Scheduler-does-not-run-scheduled-jobs-automatically/</a><br />You can found the xml file here: C:\Program Files\EPiServer\Shared\Services\Scheduler Service<br /><br />Old post:<br /><em>Today I encoutered a huge problem with EPiServer.<br />You can't have EPiServer CMS 5 R2 and EPiServer 4 on the same production server. The reason is the EPiServer scheduler. R2 has a new scheduler which is not compatible with EPiServer 4.<br />When you install the installation package for R2, it will uninstall the old scheduler. Very bad.<br /><br />To get the EPiServer 4 scheduler back to work you have to do the following:<br />- Uninstall "EPiServer Shared"<br />- Install an EPiServer 4 site from EPiServer Manager. This will install the scheduler service again.<br /><br />If you are running EPiServer CMS 5 R1 and EPiServer 4 on the same server. These two versions does work together with some tweaks. Follow these two FAQ:s after installing an EPiServer CMS 5 R1 site from EPiServer Manager:<br /><br />http://world.episerver.com/en/FAQ/Items/Running-the-scheduler-on-machines-with-both-EPiServer-CMS-4-and-5-installations/<br />(5.1.422.4 can be 5.1.422.172 depending on which SP of EPiServer you have installed)<br /><br />http://world.episerver.com/FAQ/Items/Scheduler-does-not-run-scheduled-jobs-automatically/<br /><br />If anyone knows a solution to have EPiServer 4 and EPiServer 5 R2 on the same server, please let me know.</em>This installation contains only core fileshttp://erikengstrand.blogspot.com/2008/11/this-installation-contains-only-core.html2008-11-07T08:35:00.0000000ZWhen installing a new EPiServer CMS 5 website without a database you will get this message when browsing the site:<br />"This installation contains only core files"<br /><br />Just delete the file default.htm from your webroot.Dynamically add custom page providerhttp://erikengstrand.blogspot.com/2008/11/dynamically-add-custom-page-provider.html2008-11-06T13:02:00.0000000ZThe page provider functionality is a great feature in EPiServer CMS 5 R2. The providers can easily be added through Web.config as described here:<br />http://world.episerver.com/en/Documentation/Items/Tech-Notes/EPiServer-CMS-5/EPiServer-CMS-5-R2/Page-Providers/<br /><br />If you want to add the page provider programmatically, this is one solution:<br /><br /> protected void Application_BeginRequest(Object sender, EventArgs e)<br /> {<br /> //Only add page provider if it does not exist<br /> if (DataFactory.Instance.ProviderMap.GetPageProvider("xml") == null)<br /> {<br /> //Create page provider<br /> XmlPageProvider pageProvider = new XmlPageProvider();<br /><br /> //Add page provider settings<br /> NameValueCollection valueCol = new NameValueCollection();<br /> valueCol.Add("filePath", "~/XmlPageProvider/externalPages.xml");<br /> valueCol.Add("entryPoint", "16");<br /> valueCol.Add("capabilities", "Create,Edit,Delete,Search");<br /> pageProvider.Initialize("xml", valueCol);<br /><br /> //Add page provider to the provider map<br /> DataFactory.Instance.ProviderMap.AddPageProvider(pageProvider);<br /> }<br /> }<br /><br />I'm here adding the same xml page provider which is described in the link above.EPiServer 5 upgrade to R2http://erikengstrand.blogspot.com/2008/10/episerver-5-upgrade-to-r2.html2008-10-31T09:59:00.0000000Z<span style="FONT-WEIGHT: bold">Upgrade crashes</span><br />In your development EPiServer project some files may be source controlled. The files may then be read only and therefore the upgrade crashes.<br />Set the following directories to writeable:<br />- App_Browsers<br />- App_Themes/Default<br />- Util<br />- WebServices<br /><br /><span style="FONT-WEIGHT: bold">Clean up your project after upgrading</span><br />Delete the assembly bindings and to these assamblies:<br />- EPiServer.WebParts.dll<br />- EPiServer.WorkflowFoundation.UI.dll<br />- EPiServer.ContentChannelService.dll<br />- EPiServer.SchedulerSvc.dll<br />- EPiServer.LogService.dll<br />- EPiServer.IndexingService.dll<br />- ElektroPost.Win32.dll<br /><br />Also delete references from your project to the above assemblies.<br /><br />Delete these files in the bin\ directory:<br />- EPiServer.LogService.exe.config<br />- EPiServer.SchedulerSvc.exe.config<br /><br /><span style="FONT-WEIGHT: bold">Missing references</span><br />In your development project sometimes some EPiServer references are missing after the upgrade. The best is to delete these references from the project. Then add them back by browsing to c:\<program>\EPiServer\CMS\5.2.375.7\bin<br /><br /><span style="FONT-WEIGHT: bold">IIS 6 Page not found on .htm files</span><br />When you upgrade an EPiServer site to R2 some code is not added to the web.config.<br />The location UI should be like this:<br /><location path="UI"></location></program>XForms EPiServer does not submithttp://erikengstrand.blogspot.com/2008/09/xforms-episerver-does-not-submit.html2008-09-09T10:27:00.0000000ZI got some problems with XForms in EPiServer 4.62 today. Earlier the forms have worked great and no problem at all. But suddenly all newly created forms did not work. They were impossible to submit.<br /><br />The problem turned out to be that I saved the XForms in the XForm editor i Internet explorer 8 beta 2. There might some other browsers that have the same problem.<br /><br />The solution is to open the form and save it in Internet explorer 7.<br /><br />When saving in IE8 i get this code for the submit button:<br /><strong>input onclick="return(false)" value="Submit" type="submit" action="http://localhost/sql"</strong><br /><br />This should be:<br /><strong>input type="submit" value="Submit" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();"</strong>EPiServer Migration tool problemshttp://erikengstrand.blogspot.com/2008/06/episerver-migration-tool-problems.html2008-06-04T13:20:00.0000000ZWhen migrating an EPiServer site to EPiServer CMS 5 some problems may occur.<br /><br /><br />When following the procedure at <a href="http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-SP2/Migration-Tool-RC1/">http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-SP2/Migration-Tool-RC1/</a> you may get some problem before you start the Migration Tool.<br /><br /><strong>Upgrading to EPiServer 4.62</strong><br />One step is to upgrade the site to EPiServer 4.62.<br />If you are connecting to the SQL via Integrated Security SSPI you will get this error:<br /><strong>Failed to connect to SQL database: Login failed for user ''. The user is not associated with a trusted SQL Server connection</strong><br /><strong></strong><br />I think the problem is that EPiServer Manager does not deal with integrated security.<br />The solution for me was to create an SQL user and change the Web.config to connect to the SQL database with this user. After the installation is finished you should change back to Intagrated security again.<br /><br /><strong>EPiServer Migration Tool</strong><br />When running the migration tool you may get this error:<br /><strong>System.Transactions.TransactionManagerCommunicationException: Network access for Distributed Transaction Manager (MSDTC) has been disabled.</strong><br /><strong></strong><br />and<br /><br /><strong>The partner transaction manager has disabled its support for remote/network transactions</strong><br /><br />The problem occurs when running transactions (e.g. TransactionScope) via DTC. You can read about how to fix this problem here:<br /><a href="http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/7172223f-acbe-4472-8cdf-feec80fd2e64/">http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/7172223f-acbe-4472-8cdf-feec80fd2e64/</a><br /><br />You may get this error after the above problem is solved:<br /><p><strong>System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed.</strong></p><p>The transactions will timeout if the transactions are too large. You should add the following to the bottom of the machine.config to increase the timeout (iisreset is required):</p><p><system.transactions><br /><machineSettings maxTimeout="02:00:00" /><br /></system.transactions></p>You should also open port 134 in the firewall between the webservers and the SQL server.<br /><br /><span style="FONT-WEIGHT: bold">This seem to work in development environment. But when applied in production you can get other problems with e.g. Upload directory. The best is to get the MSDTC tp work properly</span><br /><span style="FONT-STYLE: italic">You can also try to add Enlist=false; to the end of the connection string. Remember to set the connection string back to what is was before the migration when the migration is finished. Enlist=false disables the MSDTC in some way.</span><br /><br /><br /><strong>System.Data.SqlClient.SqlException: Cannot find the object 'RetrieveCompletedScope', because it does not exist or you do not have permission.</strong><br />This occurs due to a bug in Microsofts SQL-scripts for Windows Worklflow Foundation. A store procedure in this script is not created as dbo. Therefore it will get the schema of the user you are using.<br />The file to change is placed here: C:\WINDOWS\microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN<br /><br />Add a [dbo]. before RetrieveCompletedScope at the line 370 "CREATE PROCEDURE RetrieveCompletedScope".<br />It should be "CREATE PROCEDURE [dbo].RetrieveCompletedScope"EPiServer custom property with AJAXhttp://erikengstrand.blogspot.com/2008/03/episerver-custom-property-with-ajax.html2008-03-19T10:46:00.0000000ZI EPiServer CMS 5 är det rätt enkelt att göra custom properties. Om man vill ha AJAX-funktionalitet i dessa så har jag ett sätt man kan göra detta på.<br /><br />public override void CreateEditControls() {<br />//Add scriptmanager <br />if (ScriptManager.GetCurrent(this.Page) == null) {<br /> this.Controls.Add(new ScriptManager()); <br />}<br /> updatePanel = new UpdatePanel();<br /> updatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;<br /> updatePanel.ChildrenAsTriggers = true;<br /><br />//Add content to UpdatePanel<br />updatePanel.ContentTemplateContainer.Controls.Add(/* control to add */);<br />this.Controls.Add(updatePanel);<br /><br />I detta exempel kommer allt som läggs till i updatePanel.ContentTemplateContainer att göra asynkron postback.EPiServer CMS 5 + .Net 3.5 + Ajax = santhttp://erikengstrand.blogspot.com/2008/02/episerver-cms-5-net-35-ajax-sant.html2008-02-15T08:21:00.0000000ZI EPiServer 4.x behövdes det en hel del handpåläggning för att på Microsofts AJAX att fungera. I senaste EPiServer-versionen är det riktigt enkelt att få igång, speciellt om man kör .Net 3.5 där Microsofts AJAX-ramverk är inbyggt.<br /><br /><br /><br /><br />Det enda man behöver göra är att starta upp EPiServer-projektet i Visual Studio 2008 och sedan välja att köra med framwork .Net 3.5. Efter detta är det bara att tuta och köra med UpdatePanels eller andra kontroller i <a href="http://ajax.asp.net/ajaxtoolkit/">AjaxToolkit</a>.<br /><br />När man startar upp ett EPiServer projekt i VS 2008 så vill den konvertera projektet, detta måste man såklart göra.<br /><br /><br /><br />Sedan kommer nog en dialog ruta som säger att virtuella katalogen PublicTemplates inte finns i IIS. Vill man ha sitt EPiServer-projekt som en virutell katalog så ska man såklart skapa denna virtuella katalog och sedan köra på det.<br /><br /><br /><br /><br /><br /><img id="BLOGGER_PHOTO_ID_5163767070412908066" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 551px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_1BuiPkqaQr4/R6liyq7SJiI/AAAAAAAAAAU/pheVN6vcR9A/s400/publictemplates_dialog.png" width="452" border="0" /><br />Jag brukar klicka Ja här och sedan göra följande: <ol><li>Gå in på Properties på projektfilen i Visual Studio.</li><li>Under fliken Web, ändra Use IIS Web Server till <a href="http://localhost/">http://localhost/</a></li><li>Ta bort den virtuella katalog med namn PublicTemplats som skapades i IIS.</li></ol><p>Detta löser även det felmeddelande som annars ligger i varje fil:</p><p>ASP.NET runtime error: The configSource file 'connectionStrings.config' is also used in a parent, this is not allowed.</p><p>Kör hårt med EPiServer, Ajax och .Net 3.5</p>VirtualPathProvider EPiServerhttp://erikengstrand.blogspot.com/2008/02/virtualpathprovider-episerver.html2008-02-06T14:17:00.0000000ZHar senaste tiden grejat lite med VirtualPathProvider i EPiServer CMS 5. Kom på några till synes enkla ting man kan göra.<br /><br />För att läsa in en bild som Stream kan man göra det på följande sätt:<br />Stream fileStream = VirtualPathProvider.OpenFile(imagePath);<br /><br />Sedan om man vill tex läsa ut när en fil senast är ändrad kan man göra så här:<br />UnifiedFile file = (UnifiedFile)HostingEnvironment.VirtualPathProvider.GetFile(imagePath);<br />DateTime lastUpdated = file.Changed;<br /><br />Kolla om en fil finns VPP:<br />if (HostingEnvironment.VirtualPathProvider.FileExists(imagePath))<br /><br />Detta kan tex kanske vara intressant om man vill skala ner bilder eller på något sätt ändra dem innan de renderas ut till klienten.