<?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: Simple registration for files served by EPiServer</title>
	<atom:link href="http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/</link>
	<description>Code and Effect - solving problem with just enough amount of code - by Adam Najmanowicz</description>
	<lastBuildDate>Mon, 06 Sep 2010 03:22:19 +0200</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Adam Najmanowicz</title>
		<link>http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/comment-page-1/#comment-21927</link>
		<dc:creator>Adam Najmanowicz</dc:creator>
		<pubDate>Mon, 22 Jun 2009 14:00:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/#comment-21927</guid>
		<description>Thanks again Øyvind! You&#039;re right about the one time asking - if you want to work around that you can simply delete the cookie when the file is being served, but in my case I wanted to only ask it once because once I have the information provided by the user I don&#039;t want to nag them any longer. In my case I simply extract the email from the EPiServer XForm and use that to track any subsequent downloads.

In my case the code for extracting the email looks as follows:
&lt;pre class=&quot;brush: csharp;&quot;&gt;

string userEmail = e.FormData.GetValue(&quot;Email&quot;);
HttpCookie cookie = new HttpCookie(CookieEnabledVirtualPathProvider.PASS_COOKIE_NAME, userEmail);
&lt;/pre&gt;

So now in every request for a file I have the user&#039;s email and then. when the user requests the file. I check

1) is the user a registered Episerver user - if so i don&#039;t need to use the cookie as I prefer to know it&#039;s our own user. Otherwise I extract the email from the cookie:

&lt;pre class=&quot;brush: csharp;&quot;&gt;

bool isLoggedIn = HttpContext.Current.Profile != null &amp;&amp; 
    !HttpContext.Current.Profile.IsAnonymous;
bool isRegistered = HttpContext.Current.Request.Cookies.AllKeys.Contains(PASS_COOKIE_NAME);
string email = isRegistered 
    ? 
    HttpContext.Current.Request.Cookies[PASS_COOKIE_NAME].Value 
    : 
    (isLoggedIn ? HttpContext.Current.Profile.UserName : &quot;unregistered&quot;);
&lt;/pre&gt;

now once I have the email - it&#039;s stored in the database (in my case a simple Entity Framework context)

&lt;pre class=&quot;brush: csharp;&quot;&gt;
private void LogDownload (UnifiedFile file, string email)
{
    dbCookieProviderEntities context = new dbCookieProviderEntities();
    FileDownloadEntry logEntry = new FileDownloadEntry();
    logEntry.FilePath = file.VirtualPath;
    logEntry.DownloadDate = DateTime.Now;
    logEntry.UserEmail = email;
    context.AddToFileDownloadLog(logEntry);
    context.SaveChanges();
}
&lt;/pre&gt;

Once I have that I can provide nice statistics to the site owners regarding who downloaded what files. Which files have been downloaded how often and when.

If you&#039;re interested, I can upload the full solution somewhere for you.</description>
		<content:encoded><![CDATA[<p>Thanks again Øyvind! You&#8217;re right about the one time asking &#8211; if you want to work around that you can simply delete the cookie when the file is being served, but in my case I wanted to only ask it once because once I have the information provided by the user I don&#8217;t want to nag them any longer. In my case I simply extract the email from the EPiServer XForm and use that to track any subsequent downloads.</p>
<p>In my case the code for extracting the email looks as follows:</p>
<pre class="brush: csharp;">

string userEmail = e.FormData.GetValue("Email");
HttpCookie cookie = new HttpCookie(CookieEnabledVirtualPathProvider.PASS_COOKIE_NAME, userEmail);
</pre>
<p>So now in every request for a file I have the user&#8217;s email and then. when the user requests the file. I check</p>
<p>1) is the user a registered Episerver user &#8211; if so i don&#8217;t need to use the cookie as I prefer to know it&#8217;s our own user. Otherwise I extract the email from the cookie:</p>
<pre class="brush: csharp;">

bool isLoggedIn = HttpContext.Current.Profile != null &#038;&#038;
    !HttpContext.Current.Profile.IsAnonymous;
bool isRegistered = HttpContext.Current.Request.Cookies.AllKeys.Contains(PASS_COOKIE_NAME);
string email = isRegistered
    ?
    HttpContext.Current.Request.Cookies[PASS_COOKIE_NAME].Value
    :
    (isLoggedIn ? HttpContext.Current.Profile.UserName : "unregistered");
</pre>
<p>now once I have the email &#8211; it&#8217;s stored in the database (in my case a simple Entity Framework context)</p>
<pre class="brush: csharp;">
private void LogDownload (UnifiedFile file, string email)
{
    dbCookieProviderEntities context = new dbCookieProviderEntities();
    FileDownloadEntry logEntry = new FileDownloadEntry();
    logEntry.FilePath = file.VirtualPath;
    logEntry.DownloadDate = DateTime.Now;
    logEntry.UserEmail = email;
    context.AddToFileDownloadLog(logEntry);
    context.SaveChanges();
}
</pre>
<p>Once I have that I can provide nice statistics to the site owners regarding who downloaded what files. Which files have been downloaded how often and when.</p>
<p>If you&#8217;re interested, I can upload the full solution somewhere for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Øyvind</title>
		<link>http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/comment-page-1/#comment-21910</link>
		<dc:creator>Øyvind</dc:creator>
		<pubDate>Mon, 22 Jun 2009 07:21:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/#comment-21910</guid>
		<description>A couple of things a came across when testing this provider. This provider gives the form one time for the complete directory and not for each file in the folder (by design, but nice to know). 

There are also issues when adding a file to the directory. The public override VirtualFile GetFile(string virtualPath) is executed also when adding files. So the form registration should not be redirected when in editmode. The same method will of course be exceuted when drag n drop of files are done. There are no methods to check this in EpiServer so after taking a look at the querystring this is my check for drag n drop; HttpContext.Current.Request[&quot;islastbits&quot;] and this is for adding files in the File Manager; HttpContext.Current.Request[&quot;plugin&quot;]. Could also check from inheritance from ActionWindow in the last one.

Else, this is working like a charm :D</description>
		<content:encoded><![CDATA[<p>A couple of things a came across when testing this provider. This provider gives the form one time for the complete directory and not for each file in the folder (by design, but nice to know). </p>
<p>There are also issues when adding a file to the directory. The public override VirtualFile GetFile(string virtualPath) is executed also when adding files. So the form registration should not be redirected when in editmode. The same method will of course be exceuted when drag n drop of files are done. There are no methods to check this in EpiServer so after taking a look at the querystring this is my check for drag n drop; HttpContext.Current.Request["islastbits"] and this is for adding files in the File Manager; HttpContext.Current.Request["plugin"]. Could also check from inheritance from ActionWindow in the last one.</p>
<p>Else, this is working like a charm :D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Najmanowicz</title>
		<link>http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/comment-page-1/#comment-18469</link>
		<dc:creator>Adam Najmanowicz</dc:creator>
		<pubDate>Mon, 06 Apr 2009 17:03:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/#comment-18469</guid>
		<description>Thanks Øyvind! Hope you&#039;ll find a use for that again :)</description>
		<content:encoded><![CDATA[<p>Thanks Øyvind! Hope you&#8217;ll find a use for that again :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Øyvind</title>
		<link>http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/comment-page-1/#comment-18307</link>
		<dc:creator>Øyvind</dc:creator>
		<pubDate>Wed, 01 Apr 2009 11:04:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.najmanowicz.com/2009/03/12/simple-registration-for-files-served-by-episerver/#comment-18307</guid>
		<description>Great post, easy to read and easy to understand.  I had this functionality for EPiServer 4, but had not converted the project to to EPiServer CMS5 yet.</description>
		<content:encoded><![CDATA[<p>Great post, easy to read and easy to understand.  I had this functionality for EPiServer 4, but had not converted the project to to EPiServer CMS5 yet.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
