<?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>Learnings of a Developer - Vamsi KR</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/vamsikr/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/vamsikr/feed.xml</link>
    <description>Quick tips and info on some issues that give sleep less nights to Developers. Blogging them as and when I crack them</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:44:38 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Handling incorrect link propagation in Site Variations in SharePoint 2010</title>
      <link>https://docs.microsoft.com/archive/blogs/vamsikr/handling-incorrect-link-propagation-in-site-variations-in-sharepoint-2010</link>
      <pubDate>Mon, 28 Nov 2011 05:38:00 GMT</pubDate>
      <dc:creator><![CDATA[Vamsi Rallabhandi]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/vamsikr/2011/11/28/handling-incorrect-link-propagation-in-site-variations-in-sharepoint-2010/</guid>
      <description><![CDATA[When we have Site Variation setup in SharePoint 2010 we can run into an issue with the Links on the...]]></description>
      <content:encoded><![CDATA[<p>When we have Site Variation setup in SharePoint 2010 we can run into an issue with the Links on the content pages in Pages Library not pointing to the right location on Target Label.</p>
<p>Consider the following scenario.</p>
<p>&ldquo;EN&rdquo; is the Source&nbsp;Variation Label&nbsp;and we setup a Target Variation Label &ldquo;EN-UK&rdquo;. On the Source Label (EN)&nbsp;there is a page &ldquo;Page1.aspx&rdquo; having content in a <span style="color: black; line-height: 115%; font-family: 'Arial','sans-serif'; font-size: 9pt; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Publishing HTML Field </span>which contains a link to &ldquo;Page2.aspx&rdquo; on Source Label itself. When these pages are approved, published and propagated to the Target Label (EN-UK) the link on &ldquo;Page1.aspx&rdquo; is supposed to take to the &ldquo;Page2.aspx&rdquo; on the Target Label. However the Publishing HTML Field does not resolve them correctly and still points to &ldquo;Page2.aspx&rdquo; on Source Label &ldquo;EN&rdquo;. This situation is depicted in the picture below.</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/43/37/6428.FixLinks.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-43-37/6428.FixLinks.png"><img border="0" alt="" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/43/37/6428.FixLinks.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-43-37/6428.FixLinks.png" /></a><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/43/37/7380.FixLinks.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-43-37/7380.FixLinks.png"></a></p>
<p><strong>Solution</strong>: This situation can be handled by having a ListItem Event Receiver on the Pages Library of &ldquo;EN-UK&rdquo; for ItemAdded and ItemUpdated events. The following code in ItemUpdated shows how to handle such a situation</p>
<pre style="padding-left: 30px;" class="scroll"><span style="font-size: x-small;"><code class="csharp"> public override void ItemUpdated(SPItemEventProperties properties)<br /> {<br /> if (SPImportContext.Current.IsRunning)<br /> {<br /> this.EventFiringEnabled = false;<br /> FixLinks(properties);<br /> this.EventFiringEnabled = true;<br /> }<br /> base.ItemUpdated(properties);<br /> }</code></span></pre>
<p>The FixLinks method&nbsp;is here</p>
<pre class="scroll"><span style="font-size: x-small;"><code class="csharp"> private void FixLinks(SPItemEventProperties properties)<br /> {<br /> ArrayList links = new ArrayList();<br /> // Copy the required SPLink items to a seperate ArrayList so that we do not get the Enumerator modified exception.<br /> foreach (SPLink item in properties.ListItem.ForwardLinks)<br /> {<br /> if (item != null &amp;&amp; item.ServerRelativeUrl != null &amp;&amp; item.ServerRelativeUrl.ToLower().Contains(@"/en/"))<br /> {<br /> links.Add(item);<br /> }<br /> }<br /> <br /> foreach (var link in links)<br /> {<br /> var vLink = link as SPLink;<br /> if (vLink != null)<br /> {<br /> properties.ListItem.ReplaceLink(vLink.ServerRelativeUrl, vLink.ServerRelativeUrl.ToLower().Replace(@"/en/", @"/EN-UK/"));<br /> }<br /> }<br /> }<br /> </code></span></pre>
<p>There are few points to note in the above code.</p>
<ol>
<li>We need to ensure that the links are fixed when the pages are updated/added only&nbsp;in the context of the Variation Page Propagation Job. This is done by using the <a title="SPImportContext.Current.IsRunning" href="https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.deployment.spimportcontext.isrunning.aspx">SPImportContext.Current.IsRunning</a> property. Refer to Stefan Go&szlig;ner's <a title="blog post" href="https://blogs.technet.com/b/stefan_gossner/archive/2010/05/25/write-content-deployment-aware-event-handlers-and-feature-activation-code-in-sp2010.aspx">blog post</a> for more details</li>
<li>We need to make sure that the Event Handler for "after" events like the one in the example above is marked as Synchronous. More info on this <a title="here" href="https://blogs.technet.com/b/stefan_gossner/archive/2011/11/10/using-synchronous-quot-after-quot-events-e-g-itemupdated-in-sharepoint-2010.aspx">here</a>. Otherwise the Event Handler may run asynchronously and SPImportContext.Current.IsRunning property will be false.</li>
<li>Turn off any recursive firing of events by turning off the EnableEventFiring flag just before fixing the links and turning it on once the links are fixed.</li>
</ol>
<p><b>How it works</b></p>
<p>Once the pages are approved on the Source Label the &ldquo;Variation Propagate Page Job&rdquo; gets kicked off as scheduled. This job updates/adds the pages to the Target Label as needed. While the pages are propagated to target the Event Receiver on Pages Library gets triggered and updates the links on the pages accordingly.</p>
<p>Hope that helps</p>
<p>-Vamsi KR</p>]]></content:encoded>
    </item>
    <item>
      <title>Unrecognized configuration section system.web.extensions when upgrading to ASP.NET 4.0</title>
      <link>https://docs.microsoft.com/archive/blogs/vamsikr/unrecognized-configuration-section-system-web-extensions-when-upgrading-to-asp-net-4-0</link>
      <pubDate>Wed, 09 Feb 2011 04:19:00 GMT</pubDate>
      <dc:creator><![CDATA[Vamsi Rallabhandi]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/vamsikr/2011/02/09/unrecognized-configuration-section-system-web-extensions-when-upgrading-to-asp-net-4-0/</guid>
      <description><![CDATA[We recently upgraded our Web application to .NET 4.0 and it seemed to be a straight forward task....]]></description>
      <content:encoded><![CDATA[<div class="WordSection1">
<p class="MsoNormal">We recently upgraded our Web application to .NET 4.0 and it seemed to be a straight forward task. Just open the solution in Visual Studio 2010 and follow the instructions in the wizard and I am done.&nbsp; (Detailed steps of Upgrade can be found <a href="https://msdn.microsoft.com/en-us/library/dd483478.aspx" title="here">here</a>)</p>
<p class="MsoNormal">That&rsquo;s most of the times true. However there could be some surprises to watch out for.</p>
<p class="MsoNormal">You may encounter an error for system.web.extensions at compile time or runtime.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><b><span lang="EN-IN">Unrecognized configuration section system.web.extensions.</span></b></p>
<p class="MsoNormal"><b><span lang="EN-IN"></span></b></p>
<p class="MsoNormal">This error indicates that the system.web.extensions section is not defined anywhere in your web.config or machine.config. However if you check the machine.config in &lt;&lt;Windows Directory&gt;&gt;\Microsoft.NET\Framework\v4.0.30319\Config\machine.config&nbsp; you can see this section declared.</p>
<p class="MsoNormal">Following things are to be taken care for your web app to use the machine config from v4.0 and not earlier versions.</p>
<ol>
<li>
<div class="MsoListParagraphCxSpFirst" style="text-indent:-18.0pt">Make sure that the Target Framework for all the projects in your solution are pointing to &ldquo;.Net Framework 4&rdquo;.</div>
</li>
<li>
<div class="MsoListParagraphCxSpMiddle" style="text-indent:-18.0pt">If your Web App is running on IIS make sure that the application pool is running on a .NET Framework 4 version.</div>
</li>
<li>
<div class="MsoListParagraphCxSpLast" style="text-indent:-18.0pt">Finally there is one more tricky part which usually is missed. Even if the error shows up after taking care of above 2 steps then open .csproj (or .vbproj for VB application) in a text editor and walkthrough to check if there is any hard coded path reference to previous versions. For example something like this</div>
</li>
</ol><span style="color:#1F497D">
<pre class="scroll"><code class="csharp">&lt;Target Name=&rdquo;AfterBuild&rdquo; Condition=&rdquo;&rsquo;$(MvcBuildViews)&rsquo;==&rsquo;true&rsquo;&rdquo;&gt;
<br />    &lt;AspNetCompiler VirtualPath=&rdquo;temp&rdquo; ToolPath=&rdquo;$(WINDIR)\Microsoft.NET\Framework\v2.0.50727&rdquo; PhysicalPath=&rdquo;$(ProjectDir)\..\$(ProjectName)&rdquo; /&gt;
<br />    &lt;AspNetCompiler VirtualPath=&rdquo;temp&rdquo; ToolPath=&rdquo;$(WINDIR)\Microsoft.NET\Framework\v2.0.50727&rdquo; PhysicalPath=&rdquo;$(OutDir)\_PublishedWebsites\$(ProjectName)&rdquo; /&gt;
<br />  &lt;/Target&gt;
<br />
</code></pre>
<pre class="scroll"></pre>
</span>Make sure that the path is rectified to point to v4.0 directory. Even better, make it configurable so that it does not break for any v.Next versions of .NET.</div>
<div class="WordSection1"></div>
<div class="WordSection1">Hope that helps..</div>]]></content:encoded>
    </item>
  </channel>
</rss>