<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Nikhil's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/nikhiln/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/nikhiln/feed.xml</link>
    <description>A .NET dev generalist blog covering pretty much everything under the sun of .NET.</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:51:09 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Commerce Server 2007 Staging Error: CatalogImport failed; _FullTextCatalog' cannot be reused until after the next BACKUP LOG operation</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/commerce-server-2007-staging-error-catalogimport-failed-_fulltextcatalog-cannot-be-reused-until-after-the-next-backup-log-operation</link>
      <pubDate>Sun, 18 Jan 2009 22:46:47 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2009/01/18/commerce-server-2007-staging-error-catalogimport-failed-_fulltextcatalog-cannot-be-reused-until-after-the-next-backup-log-operation/</guid>
      <description><![CDATA[In one of the production commerce server instances of my client, I suddenly found this error getting...]]></description>
      <content:encoded><![CDATA[<p>In one of the production commerce server instances of my client, I suddenly found this error getting logged since a couple of days. Now, the text of the error has nothing to do with Commerce Server 2007 but everything to do with the Sql Server 2005 that forms of the datastore of the commerce server. The full error would look like this:</p>  <table bordercolor="#a9a9a9" cellspacing="0" cellpadding="2" width="100%" border="1"><tbody>     <tr>       <td valign="top" width="400">         <p><font size="2">Event Type: Error              <br />Event Source: Commerce Server Staging               <br />Event Category: None               <br />Event ID: 61993               <br />Date: 10/10/2008               <br />Time: 7:42:13 PM               <br />User: N/A               <br />Computer: PRODUCT-WEB1               <br />Description:               <br />Failed to import business data for 'Catalog' resource for project 'ProductionStaging' : Microsoft.CommerceServer.Staging.StagingSubsystemException:CatalogImport failed. See log for details.369801:File 'sysft_ProductBaseCatalog1_FullTextCatalog' cannot be reused until after the next BACKUP LOG operation.</font></p>          <p><font size="2">Full-Text catalog 'ProductBaseCatalog1_FullTextCatalog' does not exist in database 'ECommOnline_productcatalog' or user does not have permission to perform this action.</font></p>          <blockquote>           <p><font size="2">at Microsoft.CommerceServer.Staging.CatalogHandler.Import(String project, BusinessData businessData, String projectLocation, String destinationSite)</font></p>         </blockquote>          <blockquote>           <p><font size="2">at Microsoft.CommerceServer.Staging.BusinessDataStagingEngine.ImportBusinessData(String projectName, String projectLocation)</font></p>         </blockquote>          <p><font size="2">For more information, see Help and Support Center at </font><a href="https://go.microsoft.com/fwlink/events.asp"><font size="2">https://go.microsoft.com/fwlink/events.asp</font></a><font size="2">.</font></p>       </td>     </tr>   </tbody></table>  <p></p>  <p><font size="2"></font></p> There are a couple of solution to get rid of this depending on the data and the purpose of the Catalog database.   <p></p>  <p><strong>Solution 1: Change the Recovery Model to Simple</strong></p>  <p>This would make sure that the transaction logs aren't included for backup, thereby eliminating the error. </p>  <p><strong>Solution 2: Backup the log before running staging service</strong></p>  <p>Execute the SQL command <strong>BACKUP LOG ECommOnline_productcatalog TO DISK='c:\temp.log'</strong> and get the log backed up. Restart the Staging service. Also, you can include this as a scheduled maintenance so that the backup is performed just before staging is invoked.</p>]]></content:encoded>
    </item>
    <item>
      <title>Commerce Server 2007 Staging Error : "Error occurred with the database StagingLog.mdb"</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/commerce-server-2007-staging-error-error-occurred-with-the-database-staginglog-mdb</link>
      <pubDate>Thu, 13 Nov 2008 05:27:43 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/11/13/commerce-server-2007-staging-error-error-occurred-with-the-database-staginglog-mdb/</guid>
      <description><![CDATA[Yesterday I came across a very strange Commerce Server Staging error at one of the production boxes...]]></description>
      <content:encoded><![CDATA[<p>Yesterday I came across a very strange Commerce Server Staging error at one of the production boxes of the customer am working for. Strangely, for some reason, the Staging server stopped and started to throw out the below error:</p>  <p>&#160;</p>  <table bordercolor="#a9a9a9" cellspacing="0" cellpadding="2" width="100%" border="1"><tbody>     <tr>       <td valign="top" width="100%">         <p>Event Type:&#160;&#160;&#160;&#160;&#160;&#160;&#160; Error            <br />Event Source:&#160;&#160;&#160; Commerce Server Staging             <br />Event Category:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; None             <br />Event ID:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 61208             <br />Date:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 11/10/2008             <br />Time:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 10:33:36 PM             <br />User:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; N/A             <br />Computer:&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; STG1             <br />Description:</p>          <p>Error occurred with the database StagingLog.mdb.&#160; Error is: System.Data.OleDb.OleDbException: System resource exceeded.            <br />&#160;&#160; at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object&amp; executeResult)             <br />&#160;&#160; at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&amp; executeResult)             <br />&#160;&#160; at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object&amp; executeResult)             <br />&#160;&#160; at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)             <br />&#160;&#160; at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)             <br />&#160;&#160; at System.Data.OleDb.OleDbCommand.ExecuteReader()             <br />&#160;&#160; at Microsoft.CommerceServer.Staging.Internal.ProjectDeploymentLog.GetStatusForReplication(String replicationId).</p>          <p>For more information, see Help and Support Center at <a href="https://go.microsoft.com/fwlink/events.asp">https://go.microsoft.com/fwlink/events.asp</a>.</p>       </td>     </tr>   </tbody></table>  <p>&#160;</p>  <p>So the first thing I did was to look up the Internet and found <a href="https://www.architectingwith.net/2007/07/28/CommerceServerStagingErrorOperationMustUseAnUpdateableQuery.aspx" target="_blank">this wadewegner blog</a> entry which perfectly addressed my issue. To make sure that the entry doesn't get lost somewhere, I am reproducing it:</p>  <table bordercolor="#a9a9a9" cellspacing="0" cellpadding="2" width="100%" border="1"><tbody>     <tr>       <td valign="top" width="100%">         <p>While this isn't the most explicit error, it provided enough information to track down the problem. </p>          <p>You might be surprised to see that this error refers to an Access database.&#160; CSS makes use of Access database files to store events and information it audits during the staging process.&#160; Specifically, there are these two Access database files: </p>          <ul>           <li>StagingLog.mdb              <ul>               <li>Found here: C:\Program Files\Microsoft Commerce Server 2007\Staging\Data </li>                <li>Stores internal replication information used by CSS </li>             </ul>           </li>            <li>events.mdb              <ul>               <li>Found here: C:\Program Files\Microsoft Commerce Server 2007\Staging\Events </li>                <li>Stores staging information that is made available to reports </li>             </ul>           </li>         </ul>          <p>Solution: Turns out that the NT AUTHORITY\NETWORK SERVICE has been attempting to open the StagingLog.mdb file to no avail.&#160; After giving the NT AUTHORITY\NETWORK SERVICE the rights to Modify the StagingLog.mdb file </p>          <p>Rather than only giving access to the StagingLog.mdb file, give the NETWORK SERVICE account access to the entire Data folder where the MDB file is located.&#160; Otherwise it will have issues trying to write out an LDF (Access log file) file when updates are made. </p>       </td>     </tr>   </tbody></table>]]></content:encoded>
    </item>
    <item>
      <title>Using HttpModules to perform a SSL switch on web pages</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/using-httpmodules-to-perform-a-ssl-switch-on-web-pages</link>
      <pubDate>Fri, 05 Sep 2008 04:56:36 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/09/05/using-httpmodules-to-perform-a-ssl-switch-on-web-pages/</guid>
      <description><![CDATA[A common requirement of any secure website is to make sure that when a user traverses to a...]]></description>
      <content:encoded><![CDATA[<p>A common requirement of any secure website is to make sure that when a user traverses to a &quot;sensitive&quot; part of the website such the login page, the password reset page or even the personal profile page which might contain contact detail you would want the user to be forced onto a HTTPS secured page. </p>  <p>On the other hand, you might also want the user to be forced off the Secure protocol for general view pages so that the network bottleneck is eliminated at the server end due to unwanted overuse of HTTPS. One of the best ways to achieve this is using HttpModules in ASP.NET which provides a very powerful mechanism to intercept HTTP requests and redirect them as necessary.</p>  <p>To effectively develop HttpModule you need to </p>  <p>1. Hook up the module during the OnInit event</p>  <p>2. Trap the request during the PreRequestHandler event.</p>  <p>Digging into the code, it would be something like this:</p>  <table bordercolor="#d3d3d3" cellspacing="0" cellpadding="2" width="724" border="1"><tbody>     <tr>       <td valign="top" width="722">         <pre class="code"><span style="color: blue">public class </span>SslSwitchModule : IHttpModule
    {
        <span style="color: green">//store your secure pages in a hastable for fast retrieval.
        //this can be populated when the application starts up so that repeated 
        // overhead is avoided.
        </span><span style="color: blue">private static </span><span style="color: #2b91af">Hashtable </span>securePages = <span style="color: blue">null</span>;
        
        
        <span style="color: blue">public void </span>ProcessRequest(HttpContext context)
        {
            Uri requestUri = context.Request.Url;

            <span style="color: green">//if the request is for HTTP, check if HTTPS is needed
            </span><span style="color: blue">if </span>(!context.Request.IsSecureConnection)
            {
                <span style="color: blue">string </span>urlRequested =
 HttpUtility.UrlDecode(context.Request.Path.ToUpper().Replace(context.Request.ApplicationPath.ToUpper(),<br /><span style="color: #a31515">&quot;&quot;</span>));
                <span style="color: blue">if </span>(SecurePages.ContainsValue(urlRequested))
                {
                    <span style="color: green">//switch to HTTPS
                    </span><span style="color: blue">string </span>secureUrl = <span style="color: #a31515">&quot;https&quot; </span>+ context.Request.Url.AbsoluteUri.Substring(4);
                    context.Response.Redirect(secureUrl, <span style="color: blue">true</span>);
                }
            }
            <span style="color: blue">else
            </span>{
                <span style="color: green">//if the url requested is inside the https,
                // determine if its needed to be in that page
                </span><span style="color: blue">string </span>urlRequested =
 HttpUtility.UrlDecode(context.Request.Path.ToUpper().Replace(context.Request.ApplicationPath.ToUpper(),<br /> <span style="color: #a31515">&quot;&quot;</span>));
                <span style="color: blue">if </span>(!SecurePages.ContainsValue(urlRequested))
                {
                    <span style="color: green">//switch to HTTPS
                    </span><span style="color: blue">string </span>unSecureUrl = <span style="color: #a31515">&quot;http&quot; </span>+ context.Request.Url.AbsoluteUri.Substring(5);
                    context.Response.Redirect(unSecureUrl, <span style="color: blue">true</span>);
                }
            }
   
        }        
      

        <span style="color: blue">#region </span>IHttpModule Members

        <span style="color: blue">public void </span>Dispose()
        {
            ;
        }

        <span style="color: blue">public void </span>Init(HttpApplication context)
        {   
             <span style="color: green">// wireup the event for processing
             </span>context.PreRequestHandlerExecute += <span style="color: blue">new </span><span style="color: #2b91af">EventHandler</span>(context_PreRequestHandlerExecute);
            
        }

        <span style="color: blue">void </span>context_PreRequestHandlerExecute(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
        {
            HttpApplication httpApp = (HttpApplication)sender;
            <span style="color: green">//process the request
            </span><span style="color: blue">this</span>.ProcessRequest(httpApp.Context);
        }
       
        <span style="color: blue">#endregion
    </span>}</pre>
        <a href="https://11011.net/software/vspaste"></a></td>
    </tr>
  </tbody></table>]]></content:encoded>
    </item>
    <item>
      <title>Commerce Server 2007: Accessing multi-valued custom properties in UserObject of Profile System</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/commerce-server-2007-accessing-multi-valued-custom-properties-in-userobject-of-profile-system</link>
      <pubDate>Thu, 04 Sep 2008 08:34:46 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/09/04/commerce-server-2007-accessing-multi-valued-custom-properties-in-userobject-of-profile-system/</guid>
      <description><![CDATA[The MSDN's Managing Profiles section of the commerce server gives an in-depth view of the working of...]]></description>
      <content:encoded><![CDATA[<p>The <a href="https://msdn2.microsoft.com/en-us/library/aa545508.aspx" target="_blank">MSDN's Managing Profiles</a> section of the commerce server gives an in-depth view of the working of the profile system and the steps needed to create custom properties for the UserObject. The <a href="https://msdn2.microsoft.com/en-us/library/aa545660.aspx" target="_blank">Extending the Profile System</a> section gives out detailed steps to extend the profile system. </p>  <p>A frequently searched topic is to create, save and access Multi-Valued properties for the UserObject in the profile system. </p>  <p><strong>1. Create Multi-valued profile properties</strong>     <br />This is a straightforward profile editing activity on the commerce server, so would not go into it!</p>  <p><strong>2. Saving into Multi-valued property</strong>     <br />The below code snippet would do the trick for you. The key here is to set the new property value into an array and then assign the array to the Commerce Server Property.</p>  <pre class="code"><span style="color: green">//create a GUID if not present
         </span>emailToAdd.Id = <span style="color: #2b91af">Guid</span>.NewGuid();
         <span style="color: green">//create the custom profile
         </span>Profile emailProfile =
                 commerceContext.CreateProfile(emailToAdd.IdString, <br />CommerceConstants.SAVED_EMAIL_PROFILE);
         <span style="color: green">//save properties first
         </span>emailProfile.Properties[SavedEmailProfilePropertyNames.EmailId].Value 
             = emailToAdd.IdString;
         emailProfile.Properties[SavedEmailProfilePropertyNames.EmailName].Value 
             = emailToAdd.Name;
         <span style="color: green">//update back to the store
         </span>emailProfile.Update();
         <span style="color: green">//refresh the cache
         </span>emailProfile.Refresh();
         
         <span style="color: green">//get the owner profle
         </span><span style="color: blue">using </span>(Profile custProfile =
            commerceContext.GetProfile(CustProfilePropertyNames.Id, <span style="color: blue">this</span>.IdString,
            CommerceConstants.CUST_PROFILE))
         {              
             <span style="color: green">//if found, proceed for update
             </span><span style="color: blue">if </span>(custProfile != <span style="color: blue">null</span>)
             {

                 <span style="color: blue">string</span>[] additionalData;
                 <span style="color: green">//get preexisting multi values
                 </span><span style="color: blue">object</span>[] savedEmails = <br />(<span style="color: blue">object</span>[])custProfile.Properties[CustProfilePropertyNames.ContactEmails].Value;
                 <span style="color: blue">if </span>(savedEmails != <span style="color: blue">null</span>)
                 {
                     <span style="color: green">//expand by 1
                     </span>additionalData = <span style="color: blue">new string</span>[savedEmails.Length + 1];
                     <span style="color: blue">int </span>i = 0;
                     <span style="color: green">//assign back the current data to a new array
                     </span><span style="color: blue">foreach </span>(<span style="color: blue">object </span>item <span style="color: blue">in </span>savedEmails)
                     {

                         <span style="color: blue">if </span>(item != <span style="color: blue">null </span>&amp;&amp; !(item <span style="color: blue">as string</span>).Equals(<span style="color: #a31515">&quot;NULL&quot;</span>))
                         {
                             additionalData[i++] = item <span style="color: blue">as string</span>;
                         }
                     }
                     <span style="color: green">//add the item
                     </span>additionalData[i] = emailToAdd.IdString;

                 }
                 <span style="color: blue">else
                 </span>{
                     <span style="color: green">//if no items preexist, add
                     </span>additionalData = <span style="color: blue">new string</span>[1];
                     additionalData[0] = emailToAdd.IdString;
                 }
                 <span style="color: green">//save the multi valued items
                 </span>custProfile.Properties[CustProfilePropertyNames.ContactEmails].Value = <br />additionalData;
                 <span style="color: green">//update
                 </span>custProfile.Update();
                 <span style="color: green">//refresh
                 </span>custProfile.Refresh();
                 
             }
             <span style="color: blue">else
             </span>{
                 <span style="color: green">//no profile found, something not right!
                 </span><span style="color: blue">throw new </span><span style="color: #2b91af">Exception</span>(<span style="color: #a31515">&quot;No profile found for user&quot;</span>);
             }
         }
     }</pre>

<p><strong>3. Modifying Multi-valued property</strong> </p>

<p>The modifying the multi valued property is quite straight forward. If you are storing the profile Ids as done in the above example, you need to update the real/child profile rather than the multi-valued property. If you are directly consuming the multi-valued property, then you need to pass on the previous value, get the list of values as shown above, modify the required one and assign back the array and update.
  <br /></p>

<p><strong>4. Deleting Multi-valued property</strong> 

  <br /></p>

<p>Again, on the lines above, if you are using profile Ids, then delete the child profile, remove the Id from the array and save it back. If you are using the property itself, skip the item when assigning to the temporary array and save it back. One &quot;GOTCHA&quot; is when the multi-valued property has only one element - in this case use DBNull.Value to assign: </p>

<pre class="code">custProfile.Properties[CustProfilePropertyNames.ContactEmails].Value = <span style="color: #2b91af">DBNull</span>.Value;</pre>
<a href="https://11011.net/software/vspaste"></a>]]></content:encoded>
    </item>
    <item>
      <title>EntLib 3.1 DAAB: Be careful with the ExecuteReader</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/entlib-3-1-daab-be-careful-with-the-executereader</link>
      <pubDate>Tue, 08 Jul 2008 02:40:59 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/07/08/entlib-3-1-daab-be-careful-with-the-executereader/</guid>
      <description><![CDATA[The EntLib 3.1 is simply superb, right?! Well, I would give a typical consultant answer... "It...]]></description>
      <content:encoded><![CDATA[<p>The EntLib 3.1 is simply superb, right?! Well, I would give a typical consultant answer... "It depends!". It depends on the developers who are using it and it depends on motivation of the developers to know the component before "copy-pasting" code and method calls. </p> <p>Case in point is the exceptionally well written Data Access Application Block (a.k.a. DAAB). My team is involved in developing an e-commerce web site for a large automotive retailer and is using this DAAB beauty to ease the development efforts. We integrated the default provided DAAB DLLs into the solution and happily developed the data layers for our system. It was working just fine on each of the dev machines;&nbsp; I put the solution to a production server so that our clients can appreciate the beauty of it! The next thing I know, the site starts timing out for some of the calls. I went into the logs and found that the connection timeout errors were rampant! I started digging in to the code and found that we had used one particular method a lot and this was the only method that did not close the connection "automatically" - the <strong>ExecuteReader</strong> method. </p> <p>If you think about it logically, it makes a lot of sense NOT to close the connection automatically as the DAAB does not have any idea as to when the reader will move out of scope. So the correct code snippet to use is</p> <div class="csharpcode"><pre class="alt"><span class="lnum">   1:  </span>Database db = DatabaseFactory.CreateDatabase();</pre><pre><span class="lnum">   2:  </span>&nbsp;</pre><pre class="alt"><span class="lnum">   3:  </span>DbCommand dbCommand = db.GetSqlStringCommand(<span class="str">"Select Name, Address From Customers"</span>);</pre><pre><span class="lnum">   4:  </span><span class="kwrd">using</span> (IDataReader dataReader = db.ExecuteReader(dbCommand))</pre><pre class="alt"><span class="lnum">   5:  </span>{</pre><pre><span class="lnum">   6:      </span><span class="rem">// Process results</span></pre><pre class="alt"><span class="lnum">   7:  </span>} </pre><pre><span class="lnum"> </span><span class="lnum"></pre></span></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>

<p>The full reasoning is well explained at the <a href="https://msdn.microsoft.com/en-us/library/cc309177.aspx" target="_blank">MSDN Site here</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Commerce Server 2007: Catalog Import Error for Large Files</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/commerce-server-2007-catalog-import-error-for-large-files</link>
      <pubDate>Mon, 16 Jun 2008 07:51:56 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/06/16/commerce-server-2007-catalog-import-error-for-large-files/</guid>
      <description><![CDATA[When you are trying to import a large catalog into the commerce server catalog system you might come...]]></description>
      <content:encoded><![CDATA[<p>When you are trying to import a large catalog into the commerce server catalog system you might come across this error:</p>  <blockquote>   <p><strong><em>The import failed because the import file is larger than the maximum size allowed on your server.&#160; Contact your system administrator.</em></strong></p> </blockquote>  <p>The solution for this to open up the web.config of CatalogWebService and then increase the size limit of uploads to more than the file that you intend to upload. The current default value is 200MB. The steps to increase the size are:</p>  <ol>   <li>Traverse to the path which has the Catalog Web Service (typically <em>C:\Inetpub\wwwroot\CatalogWebService</em> )</li>    <li>Open up the web.config</li>    <li>Set the value of <strong>maxUploadFileSize </strong>attribute to the value which you need</li> </ol>  <p>Now, you should be able to upload the import the file.</p>]]></content:encoded>
    </item>
    <item>
      <title>HttpHandler to Authorize File Downloads - C# Code Sample</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/httphandler-to-authorize-file-downloads-c-code-sample</link>
      <pubDate>Thu, 22 May 2008 00:31:11 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/05/22/httphandler-to-authorize-file-downloads-c-code-sample/</guid>
      <description><![CDATA[Its quite a common scenario to have a feature in a web site to check for the credentials of the user...]]></description>
      <content:encoded><![CDATA[<p>Its quite a common scenario to have a feature in a web site to check for the credentials of the user before allowing a particular download. For example, there might be some documents which should be visible only to a set of users and not to any others. This document might be anything - a PDF file, a zip file, an exe, a .doc,etc. </p>  <p>The situation gets even more complicated when you have certain documents that can be downloaded by everyone on the Internet and have some documents visible only to logged in users. A HttpHandler fits this scenario perfectly. </p>  <p>Before I get into developing the HttpHandler, a couple of points regarding the design is a must:</p>  <ul>   <li>In case you need to distinguish between allowing the users to download publicly visible files and those that need log-in, its a good idea to have the documents in different folders so that security can be enforced more strictly. </li>    <li>For documents that need user's authentication and / or authorization, its advisable to have the document store outside the Web's root to make sure that the folder is not visible to any automated download app. </li>    <li>In cases wherein there is a 1-1 map between the users and his / her documents, a unique way to determine the user's file path needs to be put it to tighten security. This can be in the form of a HashedId for the user which maps onto the path in the store or some other URL rewriting technique. </li> </ul>  <p>To get on with it, there are three major steps that need to be performed to make sure that the file request is routed through the IIS via the ASPNET pipeline and onto your handler.</p>  <ol>   <li>Develop your handler - of course this is obvious :-) </li>    <li>Configure your web site to use this handler for the filetype that you want authorization on and the verbs that you'll need to support (GET , PUT, POST, etc) </li>    <li>Configure the IIS to make sure that the request for the particular filetype is routed through the ASPNET ISAPI dll so that your custom handler is it. </li> </ol>  <p>Lets take it step by step...and to make it more fun, in the reverse order!    <br /></p>  <p><strong><em>Step 3</em>: Configure IIS</strong></p>  <p>This is quite a straightforward step. All you need to do is open up the properties of the Web Application under consideration. </p>  <hr />  <ol>   <li>Under the <strong>Virtual Directory</strong> tab, </li>    <li>click on the <strong>Configuration...</strong> button, </li>    <li>in the new window that opens up, under the <strong>Mappings</strong> tab, </li>    <li>click <strong>Add...</strong>, </li>    <li>click <strong>Browse</strong> and select <strong>C:\&lt;windows root&gt; \Microsoft.NET\Framework\&lt;version&gt;\aspnet_isapi.dll</strong> <em>(the full path looks something like: C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll). </em></li>    <li>Provide the Extension without the dot (i.e just PDF) </li>    <li>Under the <strong>Verbs</strong> section, you can leave it as is or for better security, provide only <strong>GET</strong>. </li>    <li><strong>Uncheck</strong> the <strong>Verify File Exists</strong> checkbox. </li>    <li>Click OK, Apply and finally make sure that you have Execute Permissions to <strong>Scripts Only</strong>. </li> </ol>  <hr />  <p><strong><em>Step 2</em>: Configure your Web Application</strong></p>  <p>All you need to do is add the below line(s) into the web.config of the application you are developing:</p>  <hr />  <pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">system.web</span><span style="color: blue">&gt;
    <strong>&lt;</strong></span><span style="color: #a31515"><strong>httpHandlers</strong></span><strong><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">add </span><span style="color: red">verb</span><span style="color: blue">=</span>&quot;<span style="color: blue">GET</span>&quot; <span style="color: red">path</span><span style="color: blue">=</span>&quot;<span style="color: blue">*.pdf</span>&quot; 
             <span style="color: red">type</span><span style="color: blue">=</span>&quot;</strong><strong><span style="color: blue">Microsoft.Web.PortalFramework.HttpHandlers.PdfDownloadAuthorizationHandler,
             Microsoft.Web.PortalFramework</span>&quot; </strong><strong><span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">httpHandlers</span></strong><span style="color: blue"><strong>&gt;</strong>
&lt;/</span><span style="color: #a31515">system.web</span><span style="color: blue">&gt;</span></pre>

<p>The above states that the HTTP verb GET with all files ending in extenion pdf should be routed to the class mentioned in the type. The type if of format &quot;&lt;Namespace.Classname&gt;, &lt;AssemblyName&gt;&quot;</p>

<p>
  <br /></p>

<hr />

<p></p>

<p></p>

<p><strong><em>Step 1</em>: Develop your Handler</strong></p>

<p>All you need is for your class to implement IHttpHandler interface in the System.Web namespace and that's its! Instead of saying some blah blah blah about the code, here's the full code:</p>

<hr />

<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.IO;
<span style="color: blue">using </span>System.Collections.Generic;
<span style="color: blue">using </span>System.Text;
<span style="color: blue">using </span>System.Web;


<span style="color: blue">namespace </span>Microsoft.Web.PortalFramework.HttpHandlers
{
    <span style="color: gray">/// &lt;summary&gt;
    /// 
    /// &lt;/summary&gt;
    </span><span style="color: blue">public class </span>PdfDownloadAuthorizationHandler: IHttpHandler
    {
        <span style="color: blue">private static string </span>userDocsBaseFolder;
        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Initializes a new instance of the </span><span style="color: gray">&lt;see cref=&quot;DownloadAuthorizationModule&quot;/&gt; </span><span style="color: green">class.
        </span><span style="color: gray">/// &lt;/summary&gt;
        </span><span style="color: blue">public </span>PdfDownloadAuthorizationHandler()
        {
            userDocsBaseFolder = <span style="color: #a31515">&quot;PersonalDocs&quot;</span>;
        }
       

        <span style="color: blue">#region </span>IHttpHandler Members

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Gets a value indicating whether another request can 
        </span><span style="color: gray">/// </span><span style="color: green">use the </span><span style="color: gray">&lt;see cref=&quot;T:System.Web.IHttpHandler&quot;&gt;&lt;/see&gt; </span><span style="color: green">instance.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;value&gt;&lt;/value&gt;
        /// &lt;returns&gt;</span><span style="color: green">true if the </span><span style="color: gray">&lt;see cref=&quot;T:System.Web.IHttpHandler&quot;&gt;&lt;/see&gt;
        /// </span><span style="color: green">instance is reusable; otherwise, false.</span><span style="color: gray">&lt;/returns&gt;
        </span><span style="color: blue">public bool </span>IsReusable
        {
            <span style="color: blue">get </span>{ <span style="color: blue">return false</span>; }
        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Enables processing of HTTP Web requests by a custom HttpHandler
        </span><span style="color: gray">/// </span><span style="color: green">that implements the </span><span style="color: gray">&lt;see cref=&quot;T:System.Web.IHttpHandler&quot;&gt;&lt;/see&gt; </span><span style="color: green">interface.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;param name=&quot;context&quot;&gt;</span><span style="color: green">An </span><span style="color: gray">&lt;see cref=&quot;T:System.Web.HttpContext&quot;&gt;&lt;/see&gt;
        /// </span><span style="color: green">object that provides references to the intrinsic server objects 
        </span><span style="color: gray">/// </span><span style="color: green">(for example, Request, Response, Session, and Server) 
        </span><span style="color: gray">/// </span><span style="color: green">used to service HTTP requests.</span><span style="color: gray">&lt;/param&gt;
        </span><span style="color: blue">public void </span>ProcessRequest(HttpContext context)
        {
            <span style="color: blue">try
            </span>{
                <span style="color: green">//get the url requested by the user
                </span><span style="color: blue">string </span>urlRequested = 
                    HttpUtility.UrlDecode(context.Request.Url.AbsolutePath.ToUpper());
                <span style="color: green">//set the initial flag to false
                </span><span style="color: blue">bool </span>userPersonalDoc = <span style="color: blue">false</span>;
                <span style="color: green">//remove all spaces in the url before checking if the url contains the private path
                </span><span style="color: blue">if </span>(urlRequested.Replace(<span style="color: #a31515">&quot; &quot;</span>, <span style="color: #a31515">&quot;&quot;</span>).Contains(userDocsBaseFolder))
                {
                    <span style="color: green">//once we know that its for the personal folders, set the flag
                    </span>userPersonalDoc = <span style="color: blue">true</span>;
                    <span style="color: green">//we now assume that the cookie is set with the document profile id of the user
                    //and the dynamic link that its generated includes this key
                    //check only for the negative conditions
                    </span>HttpCookie profCookie = context.Request.Cookies[<span style="color: #a31515">&quot;DocId&quot;</span>];
                    <span style="color: blue">if </span>(profCookie != <span style="color: blue">null</span>)
                    {
                        <span style="color: green">//we need to use some sort of encryption (refer my previous post!)
                        </span>TripleDESCryptoHelper helper = <span style="color: blue">new </span>TripleDESCryptoHelper();
                        <span style="color: blue">string </span>profileId = helper.GetDecryptedValue(profCookie.Value);
                        <span style="color: #2b91af">Guid </span>profileGuid = <span style="color: blue">new </span><span style="color: #2b91af">Guid</span>(profileId);
                        <span style="color: green">//check if the docid from the url and the one in the cookie match
                        </span><span style="color: blue">if </span>(!urlRequested.Contains(profileGuid.ToString(<span style="color: #a31515">&quot;B&quot;</span>).ToUpper()))
                        {
                            <span style="color: green">//no match - spoofed request, send 'em back
                            </span>context.Response.Redirect(context.Request.ApplicationPath,<span style="color: blue">true</span>);
                            
                        }
                    }
                    <span style="color: blue">else
                    </span>{                        
                        context.Response.Redirect(context.Request.ApplicationPath);
                    }
                }
                <span style="color: green">//if we have reached till here, we are good to go
                </span><span style="color: blue">this</span>.TransmitRequestedFile(context, urlRequested, userPersonalDoc);
            }
            <span style="color: blue">catch </span>(<span style="color: #2b91af">Exception </span>generalException)
            {
                ExceptionManager.LogException(generalException);
            }


        }


        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Transmits the requested file.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;param name=&quot;context&quot;&gt;</span><span style="color: green">The context.</span><span style="color: gray">&lt;/param&gt;
        /// &lt;param name=&quot;urlRequested&quot;&gt;</span><span style="color: green">The URL requested.</span><span style="color: gray">&lt;/param&gt;
        /// &lt;param name=&quot;forceDownload&quot;&gt;</span><span style="color: green">if set to </span><span style="color: gray">&lt;c&gt;</span><span style="color: green">true</span><span style="color: gray">&lt;/c&gt; </span><span style="color: green">[force download].</span><span style="color: gray">&lt;/param&gt;
        </span><span style="color: blue">private void </span>TransmitRequestedFile(HttpContext context,
            <span style="color: blue">string </span>urlRequested, <span style="color: blue">bool </span>forceDownload)
        {
            <span style="color: green">// as a security considerataion, force the user to download the document
            // if the doc is from the personal folder
            </span><span style="color: blue">if </span>(forceDownload)
            {
                <span style="color: blue">this</span>.StartForcedDownload(context, urlRequested);
            }
            <span style="color: blue">else </span>{
                <span style="color: green">//else let the IE handle the filetype
                </span><span style="color: blue">this</span>.TransmitNormal(context, urlRequested);
            }
        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Transmits the file in 'normal' way.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;param name=&quot;context&quot;&gt;</span><span style="color: green">The context.</span><span style="color: gray">&lt;/param&gt;
        /// &lt;param name=&quot;urlRequested&quot;&gt;</span><span style="color: green">The URL requested.</span><span style="color: gray">&lt;/param&gt;
        </span><span style="color: blue">private void </span>TransmitNormal(HttpContext context, <span style="color: blue">string </span>urlRequested)
        {
            <span style="color: blue">string </span>filePath = HttpContext.Current.Server.MapPath(urlRequested);

            <span style="color: blue">string </span>fileName = System.IO.<span style="color: #2b91af">Path</span>.GetFileName(filePath);

            context.Response.ClearContent();

            context.Response.ClearHeaders();            

            <span style="color: #2b91af">FileInfo </span>pdfInfo = <span style="color: blue">new </span><span style="color: #2b91af">FileInfo</span>(filePath);

            context.Response.AddHeader(<span style="color: #a31515">&quot;Content-Length&quot;</span>, pdfInfo.Length.ToString());

            <span style="color: green">//assuming that the file is pdf, needs to be changed appropriately
            //context.Response.ContentType = &quot;application/zip&quot;;
            </span>context.Response.ContentType = <span style="color: #a31515">&quot;application/pdf&quot;</span>;

            context.Response.TransmitFile(filePath);

            context.Response.End();
        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Starts the forced download.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;param name=&quot;context&quot;&gt;</span><span style="color: green">The context.</span><span style="color: gray">&lt;/param&gt;
        /// &lt;param name=&quot;urlRequested&quot;&gt;</span><span style="color: green">The URL requested.</span><span style="color: gray">&lt;/param&gt;
        </span><span style="color: blue">private void </span>StartForcedDownload(HttpContext context, <span style="color: blue">string </span>urlRequested)
        {
            <span style="color: blue">string </span>filePath = HttpContext.Current.Server.MapPath(urlRequested);

            <span style="color: blue">string </span>fileName = System.IO.<span style="color: #2b91af">Path</span>.GetFileName(filePath);

            context.Response.ClearContent();

            context.Response.ClearHeaders();

            context.Response.AddHeader(<span style="color: #a31515">&quot;Content-Disposition&quot;</span>, <span style="color: #a31515">&quot;inline; filename=&quot; </span>+ fileName);

            context.Response.ContentType = <span style="color: #a31515">&quot;application/pdf&quot;</span>;

            context.Response.BufferOutput = <span style="color: blue">false</span>;

            context.Response.TransmitFile(filePath);
                        
            context.Response.End();

        }

        <span style="color: blue">#endregion
    </span>}
}</pre>

<hr /><a href="https://11011.net/software/vspaste"></a>]]></content:encoded>
    </item>
    <item>
      <title>.NET 2.0 Symmetric Encryption Code Sample</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/net-2-0-symmetric-encryption-code-sample</link>
      <pubDate>Sun, 18 May 2008 11:53:00 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/05/18/net-2-0-symmetric-encryption-code-sample/</guid>
      <description><![CDATA[One of the most common problems when developing any web site if the need to use Symmetric Encryption...]]></description>
      <content:encoded><![CDATA[<P style="align: justify">One of the most common problems when developing any web site if the need to use Symmetric Encryption to save some data in the Cookie so that it can be looped back to the user's session / identity. .NET provides a very robust mechanism in which this can be achieved and supports the most well-known of both, Symmetric and Asymmetric encryption algorithms. <A href="https://msdn.microsoft.com/en-us/library/aa302352.aspx" target=_blank mce_href="https://msdn.microsoft.com/en-us/library/aa302352.aspx">This MSDN article</A> does a phenomenal job of explaining the nittie-gritties of the various algorithms available and the different scenarios in which one should use them. </P>
<P style="align: justify">Though the <A href="https://download.microsoft.com/download/2/a/3/2a363740-3da6-48e9-a5d1-8eca01524372/CryptoSampleCSSample.msi" mce_href="https://download.microsoft.com/download/2/a/3/2a363740-3da6-48e9-a5d1-8eca01524372/CryptoSampleCSSample.msi">CryptoSampleCSSample.msi</A> provides some samples as to how to achieve this. It fails to address one of the most common scenarios of storing the IV (the Initialization Vector) and the Key in an app.config (for Windows / Console Applications) and in web.config (for Web Applications). </P>
<P style="align: justify">This complete code demonstrates how to pickup IV and Key from the web.config / app.config and then use the values in encrypting and decrypting text values. The key thing to note is that the string needs to be converted using: </P><PRE class=code><STRONG><SPAN style="COLOR: #2b91af">Convert</SPAN>.FromBase64String(IV)</STRONG></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<P style="align: justify"><EM><STRONG>NOTE: </STRONG>The IV and Key can be generated by using the CryptoSampleCS.exe provided in the </EM><A href="https://msdn.microsoft.com/en-us/library/aa302352.aspx" target=_blank mce_href="https://msdn.microsoft.com/en-us/library/aa302352.aspx"><EM>MSDN Article</EM></A><EM> mentioned above.</EM></P>
<P style="align: justify">First, the app.config:</P>
<HR>
<PRE class=code><SPAN style="COLOR: blue">&lt;?</SPAN><SPAN style="COLOR: #a31515">xml </SPAN><SPAN style="COLOR: red">version</SPAN><SPAN style="COLOR: blue">=</SPAN>"<SPAN style="COLOR: blue">1.0</SPAN>"<SPAN style="COLOR: blue">?&gt;

&lt;</SPAN><SPAN style="COLOR: #a31515">configuration</SPAN><SPAN style="COLOR: blue">&gt;
    &lt;</SPAN><SPAN style="COLOR: #a31515">appSettings</SPAN><SPAN style="COLOR: blue">&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">add </SPAN><SPAN style="COLOR: red">key</SPAN><SPAN style="COLOR: blue">=</SPAN>"<SPAN style="COLOR: blue">IV</SPAN>" <SPAN style="COLOR: red">value</SPAN><SPAN style="COLOR: blue">=</SPAN>"<SPAN style="COLOR: blue">SuFjcEmp/TE=</SPAN>"<SPAN style="COLOR: blue">/&gt;
        &lt;</SPAN><SPAN style="COLOR: #a31515">add </SPAN><SPAN style="COLOR: red">key</SPAN><SPAN style="COLOR: blue">=</SPAN>"<SPAN style="COLOR: blue">Key</SPAN>" <SPAN style="COLOR: red">value</SPAN><SPAN style="COLOR: blue">=</SPAN>"<SPAN style="COLOR: blue">KIPSToILGp6fl+3gXJvMsN4IajizYBBT</SPAN>"<SPAN style="COLOR: blue">/&gt;
    &lt;/</SPAN><SPAN style="COLOR: #a31515">appSettings</SPAN><SPAN style="COLOR: blue">&gt;
&lt;/</SPAN><SPAN style="COLOR: #a31515">configuration</SPAN><SPAN style="COLOR: blue">&gt;</SPAN></PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A>
<HR>

<P>Now the full code:&nbsp; </P>
<HR>
<PRE class=code><SPAN style="COLOR: blue">using </SPAN>System;
<SPAN style="COLOR: blue">using </SPAN>System.Collections.Generic;
<SPAN style="COLOR: blue">using </SPAN>System.Text;
<SPAN style="COLOR: blue">using </SPAN>System.Security.Cryptography;
<SPAN style="COLOR: blue">using </SPAN>System.IO;
<SPAN style="COLOR: blue">using </SPAN>System.Configuration;
</PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A><PRE class=code><SPAN style="COLOR: blue">    public class </SPAN><SPAN style="COLOR: #2b91af">CryptoHelper
</SPAN>    {</PRE><PRE class=code><SPAN style="COLOR: green">        //private readonly string IV = "SuFjcEmp/TE=";
        </SPAN><SPAN style="COLOR: blue">private readonly string </SPAN>IV = <SPAN style="COLOR: blue">string</SPAN>.Empty;
        <SPAN style="COLOR: green">//private readonly string Key = "KIPSToILGp6fl+3gXJvMsN4IajizYBBT";
        </SPAN><SPAN style="COLOR: blue">private readonly string </SPAN>Key = <SPAN style="COLOR: blue">string</SPAN>.Empty;</PRE><A href="https://11011.net/software/vspaste" mce_href="https://11011.net/software/vspaste"></A><PRE class=code>        <SPAN style="COLOR: gray">/// &lt;summary&gt;
        /// </SPAN><SPAN style="COLOR: green">Initializes a new instance of the </SPAN><SPAN style="COLOR: gray">&lt;see cref="CryptoHelper"/&gt; </SPAN><SPAN style="COLOR: green">class.
        </SPAN><SPAN style="COLOR: gray">/// &lt;/summary&gt;
        </SPAN><SPAN style="COLOR: blue">public </SPAN>CryptoHelper()
        {
            IV = <SPAN style="COLOR: #2b91af">ConfigurationManager</SPAN>.AppSettings[<SPAN style="COLOR: #a31515">"IV"</SPAN>];
            Key = <SPAN style="COLOR: #2b91af">ConfigurationManager</SPAN>.AppSettings[<SPAN style="COLOR: #a31515">"Key"</SPAN>];
        }

        <SPAN style="COLOR: gray">/// &lt;summary&gt;
        /// </SPAN><SPAN style="COLOR: green">Gets the encrypted value.
        </SPAN><SPAN style="COLOR: gray">/// &lt;/summary&gt;
        /// &lt;param name="inputValue"&gt;</SPAN><SPAN style="COLOR: green">The input value.</SPAN><SPAN style="COLOR: gray">&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        </SPAN><SPAN style="COLOR: blue">public string </SPAN>GetEncryptedValue(<SPAN style="COLOR: blue">string </SPAN>inputValue)
        {
            <SPAN style="COLOR: #2b91af">TripleDESCryptoServiceProvider </SPAN>provider = <SPAN style="COLOR: blue">this</SPAN>.GetCryptoProvider();
            <SPAN style="COLOR: green">// Create a MemoryStream.
            </SPAN><SPAN style="COLOR: #2b91af">MemoryStream </SPAN>mStream = <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: #2b91af">MemoryStream</SPAN>();

            <SPAN style="COLOR: green">// Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            </SPAN><SPAN style="COLOR: #2b91af">CryptoStream </SPAN>cStream = <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: #2b91af">CryptoStream</SPAN>(mStream,
                provider.CreateEncryptor(),<SPAN style="COLOR: #2b91af">CryptoStreamMode</SPAN>.Write);

            <SPAN style="COLOR: green">// Convert the passed string to a byte array.: Bug fixed, see update below!
            <SPAN style="COLOR: green">// </SPAN></SPAN><FONT color=#009900><FONT color=#009900><SPAN style="COLOR: blue"><FONT color=#009900>byte</FONT></SPAN>[] toEncrypt = <SPAN style="COLOR: blue"><FONT color=#009900>new</FONT> </SPAN><SPAN style="COLOR: #2b91af"><FONT color=#009900>ASCIIEncoding</FONT></SPAN>().GetBytes(inputValue);</FONT><BR></FONT><FONT color=#008000>            </FONT><SPAN style="COLOR: blue">byte</SPAN>[] toEncrypt = <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: #2b91af"><SPAN style="COLOR: #2b91af">UTF8Encoding</SPAN></SPAN>().GetBytes(inputValue);<BR>
            <SPAN style="COLOR: green">// Write the byte array to the crypto stream and flush it.
            </SPAN>cStream.Write(toEncrypt, 0, toEncrypt.Length);
            cStream.FlushFinalBlock();

            <SPAN style="COLOR: green">// Get an array of bytes from the 
            // MemoryStream that holds the 
            // encrypted data.
            </SPAN><SPAN style="COLOR: blue">byte</SPAN>[] ret = mStream.ToArray();

            <SPAN style="COLOR: green">// Close the streams.
            </SPAN>cStream.Close();
            mStream.Close();

            <SPAN style="COLOR: green">// Return the encrypted buffer.
            </SPAN><SPAN style="COLOR: blue">return </SPAN><STRONG><SPAN style="COLOR: #2b91af">Convert</SPAN>.ToBase64String(ret);</STRONG>
        }

        <SPAN style="COLOR: gray">/// &lt;summary&gt;
        /// </SPAN><SPAN style="COLOR: green">Gets the crypto provider.
        </SPAN><SPAN style="COLOR: gray">/// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        </SPAN><SPAN style="COLOR: blue">private </SPAN><SPAN style="COLOR: #2b91af">TripleDESCryptoServiceProvider </SPAN>GetCryptoProvider()
        {
            <SPAN style="COLOR: #2b91af">TripleDESCryptoServiceProvider </SPAN>provider = <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: #2b91af">TripleDESCryptoServiceProvider</SPAN>();
            provider.IV = <STRONG><SPAN style="COLOR: #2b91af">Convert</SPAN>.FromBase64String(IV);
</STRONG>            provider.Key = <STRONG><SPAN style="COLOR: #2b91af">Convert</SPAN>.FromBase64String(Key);
</STRONG>            <SPAN style="COLOR: blue">return </SPAN>provider;            
        }

        <SPAN style="COLOR: gray">/// &lt;summary&gt;
        /// </SPAN><SPAN style="COLOR: green">Gets the decrypted value.
        </SPAN><SPAN style="COLOR: gray">/// &lt;/summary&gt;
        /// &lt;param name="inputValue"&gt;</SPAN><SPAN style="COLOR: green">The input value.</SPAN><SPAN style="COLOR: gray">&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        </SPAN><SPAN style="COLOR: blue">public string </SPAN>GetDecryptedValue(<SPAN style="COLOR: blue">string </SPAN>inputValue)
        {
            <SPAN style="COLOR: #2b91af">TripleDESCryptoServiceProvider </SPAN>provider = <SPAN style="COLOR: blue">this</SPAN>.GetCryptoProvider();
            <SPAN style="COLOR: blue">byte</SPAN>[] inputEquivalent = <SPAN style="COLOR: #2b91af">Convert</SPAN>.FromBase64String(inputValue);
            <SPAN style="COLOR: green">// Create a new MemoryStream.
            </SPAN><SPAN style="COLOR: #2b91af">MemoryStream </SPAN>msDecrypt = <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: #2b91af">MemoryStream</SPAN>();

            <SPAN style="COLOR: green">// Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            </SPAN><SPAN style="COLOR: #2b91af">CryptoStream </SPAN>csDecrypt = <SPAN style="COLOR: blue">new </SPAN><SPAN style="COLOR: #2b91af">CryptoStream</SPAN>(msDecrypt,
                provider.CreateDecryptor(),
                <SPAN style="COLOR: #2b91af">CryptoStreamMode</SPAN>.Write);
            csDecrypt.Write(inputEquivalent, 0, inputEquivalent.Length);
            csDecrypt.FlushFinalBlock();

            csDecrypt.Close();

            <SPAN style="COLOR: green">//Convert the buffer into a string and return it.
            </SPAN><SPAN style="COLOR: blue">return new </SPAN><SPAN style="COLOR: #2b91af">UTF8Encoding</SPAN>().GetString(msDecrypt.ToArray());
        }
    }
</PRE><PRE class=code>&nbsp;<STRONG>Update</STRONG>: JT Carvalho emailed me about a bug in the code above.<BR>"You are encoding the crypted value with AsciiEncoding and decoding it with UTF8Encoding, so in some special chars (like portuguese chars) they will not match.<BR>I think encoding it with UTF8Encoding it will resolve this."</PRE><PRE class=code>Thanks for pointing this out and thanks for the fix as well!<BR></PRE><PRE class=code>&nbsp;</PRE>]]></content:encoded>
    </item>
    <item>
      <title>Commerce Server 2007 Code Samples - Catalog System and Basic Catalog Search</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/commerce-server-2007-code-samples-catalog-system-and-basic-catalog-search</link>
      <pubDate>Mon, 14 Apr 2008 01:55:00 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/04/14/commerce-server-2007-code-samples-catalog-system-and-basic-catalog-search/</guid>
      <description><![CDATA[I did some qualitative analysis of the referrals of my blog, and found that a majority of the search...]]></description>
      <content:encoded><![CDATA[<P>I did some qualitative analysis of the referrals of my blog, and found that a majority of the search terms are for Commerce Server Code Samples or for Commerce Server API usage samples.Though some very good code samples are available at the <A href="https://blogs.msdn.com/commerce" target=_blank mce_href="https://blogs.msdn.com/commerce">Microsoft Commerce Server Product Unit blog</A>, it is extremely difficult to get hold of them as they have been filed either under Webcasts as attachments or in the context of a different article. </P>
<P>I will try to get hold of some genuine code samples that are spread across the <A href="https://blogs.msdn.com/" target=_blank mce_href="https://blogs.msdn.com/">MSDN blogs</A> including the blogs of key developers who worked on the product. I will be posting more such items as and when I find them (or I find time to find them). I'll also be including code snippets of some real-life searches using the Commerce Server 2007 APIs that am working on.</P>
<P>A terrific set of code samples for the Commerce Server 2007 Catalog System has been uploaded in the e-commerce blog by <A href="https://blogs.msdn.com/vinayakt/default.aspx" target=_blank mce_href="https://blogs.msdn.com/vinayakt/default.aspx">Vinayak Tadas</A> who was a developer in the team that developed the product. the original post is <A href="https://blogs.msdn.com/commerce/archive/2007/06/11/friday-june-15th-2007-7-00am-9-00am-pacific-daylight-time-live-from-redmond-commerce-server-2007-catalog-system-development-by-vinayak-tadas.aspx" target=_blank mce_href="https://blogs.msdn.com/commerce/archive/2007/06/11/friday-june-15th-2007-7-00am-9-00am-pacific-daylight-time-live-from-redmond-commerce-server-2007-catalog-system-development-by-vinayak-tadas.aspx">here</A>. I have attached the same code samples in this entry and can be downloaded for reference <EM>(without any implicit or explicit warranty or support from either me or Microsoft Corp. whatsoever : By downloading you accept all the risks involved without any liability on the part of Microsoft Corp. or myself.)</EM></P>
<P>The attached <STRONG>CatalogWebCast_CodeSamples.zip</STRONG> file contains samples for:</P>
<P>Runtime<STRONG> Commerce Server APIs</STRONG> (those that are used to retrieve info for use in a e-commerce website)</P>
<UL>
<LI>ProductCatalog: Getting products from a catalog along with its child products </LI>
<LI>CatalogContext.GetCatalogs: Getting a set of catalogs from the current context </LI>
<LI>CatalogContext.GetCategory: Getting the details of a category including child categories </LI>
<LI>CatalogContext.GetProduct: Getting the details of a product and product family including the variants </LI>
<LI>CatalogSearch: Searching the catalog with the basic properties specified </LI></UL>
<P>Design-time Commerce Server APIs (those that are used to create products, catalogs etc)</P>
<UL>
<LI>CreateProperty: Creating a CatalogProperty using the CreateProperty method of the CatalogContext </LI>
<LI>CatalogEnumerationProperty: Creating a CatalogEnumerationProperty using the overloaded CreateProperty method </LI>
<LI>CreateDefinition: 
<UL>
<LI>Creating a CatalogDefinition using the CreateDefinition of CatalogContext </LI>
<LI>Creating a ProductDefinition using the CreateDefinition of CatalogContext </LI></UL></LI>
<LI>.... and lots more... </LI></UL>
<P align=justify>Get the attachment: <IFRAME style="BORDER-RIGHT: #dde5e9 1px solid; PADDING-RIGHT: 0px; BORDER-TOP: #dde5e9 1px solid; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 3px; BORDER-LEFT: #dde5e9 1px solid; WIDTH: 240px; PADDING-TOP: 0px; BORDER-BOTTOM: #dde5e9 1px solid; HEIGHT: 26px; BACKGROUND-COLOR: #ffffff" marginWidth=0 marginHeight=0 src="https://cid-2379f43f098b2582.skydrive.live.com/embedrow.aspx/CommerceServer2007CodeSamples/CatalogWebCast_CodeSamples.zip" frameBorder=0 scrolling=no></IFRAME></P>]]></content:encoded>
    </item>
    <item>
      <title>Multi-Threaded Web Service Calls - A C# Code Sample</title>
      <link>https://docs.microsoft.com/archive/blogs/nikhiln/multi-threaded-web-service-calls-a-c-code-sample</link>
      <pubDate>Sat, 12 Apr 2008 11:51:33 GMT</pubDate>
      <dc:creator><![CDATA[nikhiln]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nikhiln/2008/04/12/multi-threaded-web-service-calls-a-c-code-sample/</guid>
      <description><![CDATA[Sometimes it becomes necessary to call an external web service in a multi threaded manner to speed...]]></description>
      <content:encoded><![CDATA[<p>Sometimes it becomes necessary to call an external web service in a multi threaded manner to speed up processing of records that we have in a buffer so that the overall time spent in waiting for the calls to return is reduced. The high-level steps to perform are:</p>  <p>Though we can have a long philosophical discussion as to which design to use, my intention here is to demonstrate and give some code sample as to how to achieve this. Some of the assumption for this are:</p>  <ul>   <li>All the records which contain the info to be submitted to an external web service is in a common buffer </li>    <li>Each thread will process multiple records at a time before getting additional data from the buffer for the next iteration </li>    <li>The code is not optimized for performance and can be worked upon </li> </ul>  <p>Ok, now with the disclaimers out of the way, lets see the basic steps involved in cobbling up a multi thread routine to call a web service. Broadly, we need to perform the following steps:</p>  <ol>   <li><strong>GetData():</strong> Get the data from the buffer for each of the threads that will call the web service </li>    <li><strong>Process():</strong> Call the web service using the web proxy </li>    <li><strong>SetData():</strong> Merge the output obtained by each of the threads to a common output buffer </li> </ol>  <p>The three main things that need to be kept in mind are:</p>  <ol>   <li>Using MUTEX to make sure that no two threads get the same set of data for the input. </li>    <li>Using MUTEX to make sure that no thread overwrites the output of the other. </li>    <li>Making sure that no thread gets zombied and that the main calling thread waits for the others to terminate. </li> </ol>  <p>The complete code</p>  <hr />  <pre class="code"><span style="color: gray">    /// &lt;summary&gt;
    /// </span><span style="color: green">Multi Threaded web processor
    </span><span style="color: gray">/// &lt;/summary&gt;
    </span><span style="color: blue">public sealed class </span>WebProcessingService
    {
        <span style="color: green">// setup the mutex for the input buffer
        </span><span style="color: blue">private readonly static </span><span style="color: #2b91af">Mutex </span>getDataSyncMutex = <span style="color: blue">new </span><span style="color: #2b91af">Mutex</span>(<span style="color: blue">false</span>);

        <span style="color: green">// setup the mutex for the output
        </span><span style="color: blue">private readonly static </span><span style="color: #2b91af">Mutex </span>setDataSyncMutex = <span style="color: blue">new </span><span style="color: #2b91af">Mutex</span>(<span style="color: blue">false</span>);

        <span style="color: green">// this indexer is used to make sure that the input array bounds are not violated
        // when the threads are getting fed the input
        </span><span style="color: blue">private static int </span>indexer = 0;

        <span style="color: blue">string</span>[] inputBuffer = <span style="color: blue">null</span>;
        <span style="color: green">//Assuming that the records to be processed result in a unique output
        </span><span style="color: #2b91af">Dictionary</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">string</span>&gt; outputBuffer = <span style="color: blue">null</span>;

        <span style="color: green">// else we can use the below, but we need to have mechanism to have a unique key for
        // each of the input records. If uniqueness is not necessary, we can just use a List&lt;T&gt;
        //Dictionary&lt;string, SomeClass&gt; outputBuffer = null;

        
        </span><span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Initializes a new instance of the </span><span style="color: gray">&lt;see cref=&quot;WebProcessingService&quot;/&gt; </span><span style="color: green">class.
        </span><span style="color: gray">/// &lt;/summary&gt;
        </span><span style="color: blue">public </span>WebProcessingService(<span style="color: blue">string</span>[] inputRecords)
        {
            <span style="color: blue">this</span>.BuildInternalBuffers(inputRecords);
        }
        

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Builds the internal buffers, both the input and output buffer
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;param name=&quot;inputRecords&quot;&gt;</span><span style="color: green">Input records</span><span style="color: gray">&lt;/param&gt;
        </span><span style="color: blue">private void </span>BuildInternalBuffers(<span style="color: blue">string</span>[] inputRecords)
        {
            <span style="color: blue">this</span>.inputBuffer = inputRecords;
            outputBuffer = <span style="color: blue">new </span><span style="color: #2b91af">Dictionary</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">string</span>&gt;(inputRecords.Length);
            indexer = 0;            
            
        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Method initiates the mutli threaded processing of web calls
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        </span><span style="color: blue">public </span><span style="color: #2b91af">Dictionary</span>&lt;<span style="color: blue">string</span>, <span style="color: blue">string</span>&gt; ProcessRecords()
        {
            
            <span style="color: #2b91af">Thread</span>[] pool = <span style="color: blue">new </span><span style="color: #2b91af">Thread</span>[Settings.Default.maxThreads];

            <span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; pool.Length; i++)
            {
                <span style="color: green">//spawn out a new thread
                </span><span style="color: #2b91af">Thread </span>t = <span style="color: blue">new </span><span style="color: #2b91af">Thread</span>(<span style="color: blue">new </span><span style="color: #2b91af">ThreadStart</span>(ProcessCalls));
                <span style="color: green">//mark it as a non-background thread
                </span>t.IsBackground = <span style="color: blue">false</span>;
                <span style="color: green">//start
                </span>t.Start();
                <span style="color: green">//save the reference so that the main thread waits for its termination
                </span>pool[i] = t;
            }
            <span style="color: green">//make the caller wait for all the threads to terminate
            </span><span style="color: blue">foreach </span>(<span style="color: #2b91af">Thread </span>t <span style="color: blue">in </span>pool)
            {
                t.Join();
            }
            <span style="color: green">//return the output
            </span><span style="color: blue">return </span>outputBuffer;

        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Gets the data.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        </span><span style="color: blue">private string</span>[] GetData()
        {
            <span style="color: green">// apply muetx to make sure that only one thread enter the region
            </span>getDataSyncMutex.WaitOne();
            
            <span style="color: blue">try
            </span>{
                <span style="color: green">//init the temp buffers to copy from the input records</span><span style="color: green">
                </span><span style="color: blue">string</span>[] tempBuffer = <span style="color: blue">new string</span>[Settings.Default.recordsPerThreadPerIteration];
                <span style="color: green">//check if the indexer is withing the array bound and that i is within the bounds
                // of the temp buffer
                </span><span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; tempBuffer.Length &amp;&amp; indexer &lt; <span style="color: blue">this</span>.inputBuffer.Length; 
                    i++, indexer++)
                {
                    tempBuffer[i] = <span style="color: blue">this</span>.inputBuffer[indexer];
                }
                <span style="color: green">//now check if the indexer has gone out of bounds of the length of the buffer
                // this means that all input records have been passed onto the threads
                </span><span style="color: blue">if </span>(indexer &gt; <span style="color: blue">this</span>.inputBuffer.Length)
                {
                    <span style="color: green">//signal end of input
                    </span><span style="color: blue">return null</span>;
                }
                    <span style="color: green">//if the indexer has not yet reached the end, check if it is at the boundary
                    // if so increment it so that the next thread entering gets the signal of 
                    // end-of-input
                </span><span style="color: blue">else if </span>(indexer == <span style="color: blue">this</span>.inputBuffer.Length)
                {                    
                    
                    indexer++;
                }
                <span style="color: green">// the remaining case is when the indexer is &lt; this.inputBuffer.Length
                // which is safe as it means that the next thread will get input records
                </span><span style="color: blue">return </span>tempBuffer;
                
            }
            <span style="color: blue">finally
            </span>{
                <span style="color: green">//even if there is some exception, this will release the lock
                </span>getDataSyncMutex.ReleaseMutex();
            }
        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Processes the web calls.
        </span><span style="color: gray">/// &lt;/summary&gt;
        </span><span style="color: blue">private void </span>ProcessCalls()
        {
            <span style="color: green">//instantiate the proxy
            </span>FooWebService webProxy = <span style="color: blue">new </span>FooWebService();
            <span style="color: green">//instantiate the temp buffer
            </span><span style="color: blue">string</span>[] buffer = <span style="color: blue">null</span>;
            <span style="color: blue">while </span>(<span style="color: blue">true</span>)
            {
                <span style="color: green">//clear it out for the start of each iteration
                </span>buffer = <span style="color: blue">null</span>;
                <span style="color: green">//get the data
                </span>buffer = <span style="color: blue">this</span>.GetData();
                <span style="color: green">//if end-of-input is specified, done!
                </span><span style="color: blue">if </span>(buffer == <span style="color: blue">null</span>)
                {
                    <span style="color: blue">break</span>;
                }
                <span style="color: blue">string</span>[] outTempBuffer = <span style="color: blue">new string</span>[buffer.Length];
                <span style="color: green">// process each of the elem
                </span><span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; buffer.Length; i++)
                {
                    <span style="color: blue">if </span>(buffer[i] != <span style="color: blue">null</span>)
                    {
                        outTempBuffer[i] =
                            webProxy.SomeMetho(buffer[i]);                        
                    }
                }
                <span style="color: green">//once we get the current set out, feed into the output dictionary
                </span><span style="color: blue">this</span>.SetData(outTempBuffer);
            }
            
        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Sets the data.
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;param name=&quot;tempBuffer&quot;&gt;</span><span style="color: green">The output record.</span><span style="color: gray">&lt;/param&gt;
        </span><span style="color: blue">private void </span>SetData(<span style="color: blue">string</span>[] tempBuffer)
        {
            <span style="color: green">//apply lock for mutual exlusion
            </span>setDataSyncMutex.WaitOne();
            <span style="color: blue">try
            </span>{
                <span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; tempBuffer.Length; i++)
                {
                    <span style="color: green">//check if the key isnt already present before trying to add
                    </span><span style="color: blue">if </span>(tempBuffer[i] != <span style="color: blue">null
                        </span>&amp;&amp; !<span style="color: blue">string</span>.IsNullOrEmpty(tempBuffer[i])
                        &amp;&amp; !outputBuffer.ContainsKey(tempBuffer[i]))
                    {
                        <span style="color: green">//add if not present
                        </span>outputBuffer.Add(tempBuffer[i],tempBuffer[i]);
                    }
                }

            }
            <span style="color: blue">finally
            </span>{
                <span style="color: green">//release lock
                </span>setDataSyncMutex.ReleaseMutex();
            }
        }
    } </pre>

<hr />]]></content:encoded>
    </item>
  </channel>
</rss>