<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayub Sourjah on Medium]]></title>
        <description><![CDATA[Stories by Ayub Sourjah on Medium]]></description>
        <link>https://medium.com/@813114402v?source=rss-8b6a710c7f7d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aEvN1XEHLYTf49Nx</url>
            <title>Stories by Ayub Sourjah on Medium</title>
            <link>https://medium.com/@813114402v?source=rss-8b6a710c7f7d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:01:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@813114402v/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Synchronizing Forms Authentication with .NET Framework and .NET Core]]></title>
            <link>https://medium.com/@813114402v/syncronizing-forms-authentication-with-net-framework-and-net-core-4430e07405c6?source=rss-8b6a710c7f7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4430e07405c6</guid>
            <dc:creator><![CDATA[Ayub Sourjah]]></dc:creator>
            <pubDate>Sun, 28 Jul 2024 02:19:14 GMT</pubDate>
            <atom:updated>2024-07-28T03:10:42.490Z</atom:updated>
            <content:encoded><![CDATA[<h3>Synchronizing Forms Authentication with .NET Framework and .NET Core</h3><h3>Background</h3><p>Navigating the labyrinth of documentation and sample applications to synchronize forms authentication between .NET Framework and .NET Core is no easy feat. The available resources are often scattered, outdated, and entangled with specific business needs that obscure the core solution. My journey to achieve seamless authentication synchronization involved sifting through numerous examples, piecing together critical, yet missing, information, and adapting older methodologies to fit the latest versions of .NET. This article aims to cut through the noise and provide a clear, focused guide with a straightforward sample application, tailored specifically for this purpose. If you’ve been struggling to find a concise and updated resource, you’re in the right place — let’s get started.</p><p>Before we begin, you need to clone the following sample code from my github repository below:</p><p><a href="https://github.com/AyubSourjah/SharedCookieAuth">AyubSourjah/SharedCookieAuth: Synchronizing forms authentication between .NET Framework and .NET Core (github.com)</a></p><p>Within the solution you will find two projects namely:</p><ol><li>SharedApp2 (.NET Core 8)</li><li>SharedApp3 (.NET 4.8 Framework Application)</li></ol><p>Remember, these were empty projects created from scratch to reduce the boilerplate code.</p><p>Some of the key dependencies that needed to be added to these projects were:</p><ol><li>SharedApp2 has nuget package <a href="https://www.nuget.org/packages/Microsoft.AspNetCore.DataProtection.Extensions/">https://www.nuget.org/packages/Microsoft.AspNetCore.DataProtection.Extensions/</a> installed.</li><li>SharedApp3 has nuget package <a href="https://www.nuget.org/packages/Microsoft.Owin.Security.Interop/">https://www.nuget.org/packages/Microsoft.Owin.Security.Interop/</a> installed.</li></ol><h3>Configuration</h3><p>Once you have the solution opened in Visual Studio, make sure the two projects are hosted in IIS as so:</p><p><strong>shareauth3.localhost.com</strong> (Require HTTPS) point the path to the project folder of the SharedApp3. This is the .NET Framework application.</p><p><strong>shareauthcore.localhost.com</strong> (Require HTTPS) point the path to the project folder of the SharedApp2. This is the .NET Core application.</p><p>The managed pipeline mode for both pools need to be running in Integrated mode and NOT Classic.</p><p>Make sure your host file (“C:\Windows\System32\drivers\etc\hosts”) reflect these changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*xP9pwqTc1TLDYQZeXi_5Sg.png" /></figure><p>Simply browse the following URL <a href="https://shareauth3.localhost.com/">https://shareauth3.localhost.com</a> and follow the screen. <strong>Dont forget to BUILD you solution.</strong></p><p><em>For those who didn’t know, since this solution uses OWIN to authenticate and share authentication between apps. Having a break point in the Startup.cs -&gt; Configuration method will not fire.</em></p><p>Based on the articles I have read the debugging system only kicks-in after the Startup.cs has been initialed. So if you want to know whether your Startup.cs -&gt; Configuration method actually works. Put in a throw exception to see it working.</p><p><strong>This is how it should look when you open the solution file in Visual Studio. <em>Project SharedApp3 should be set as the startup application</em>:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*8r6YkzrqjsKKm0tgMZ3nbw.png" /></figure><h3>Import Points:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvnDGUFbGQlQHRz3noD4-A.png" /><figcaption>The most important configurations in both applications. The image above is from the .NET Core Application.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3H_FJY80Zp05t4kJk-qJQ.png" /><figcaption>The above image is from the .NET Framework Application.</figcaption></figure><ol><li>Application Name should be the same in both applications.</li><li>Cookie Name should be the same in both applications.</li><li>Make sure the cookie attributes such as the path are also similar.</li></ol><p>4. I am using the local storage to store and share the encryption key between both applications. This is for the purpose of getting the authentication working for this sample.</p><h3>Whats all the fuss about?</h3><p>The motivation behind this project stems from the challenge of migrating a 27-year-old application developed in .NET Framework to .NET Core. As many developers know, such a migration is a complex endeavor with numerous considerations to ensure success. One significant concern was how to synchronize authentication between the two applications running on different platforms.</p><p>In the .NET Framework, the encryption pattern for the ASP.NET authentication cookie differs from that of .NET Core. The key was to enable .NET Core to recognize and understand the authentication cookie from the .NET Framework. The solution lay in using OWIN, which allows us to switch from the standard .NET Framework Encryption Provider to the new DataProtection Provider used in .NET Core.</p><p>Previously, the forms authentication ticket was encrypted using the old data protection system of the .NET Framework. Now, in this sample application, we employ the new DataProtection system used in .NET Core. Here’s a key insight from Microsoft’s documentation:</p><p><a href="https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey?view=aspnetcore-8.0"><em>You can tell if the new data protection system is active by inspecting fields like </em></a><a href="https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey?view=aspnetcore-8.0"><em>__VIEWSTATE, which should begin with &quot;CfDJ8&quot; as in the example below. &quot;CfDJ8&quot; is the base64 representation of the magic &quot;09 F0 C9 F0&quot; header that identifies a payload protected by the data protection system.</em></a></p><p>Below are a few screenshots to demonstrate this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*YKupx9MOfH6i7MeAPHCKLA.png" /><figcaption>Old Data Protection System used in .NET Framework</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*4Nqixx5J3Pv_okWu7aN6vg.png" /><figcaption>New Data Protection System used in .NET Core and now within the .NET Framework application</figcaption></figure><h3>Relevant Articles and Resources:</h3><p><a href="https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/compatibility/replacing-machinekey?view=aspnetcore-8.0">Replace the ASP.NET machineKey in ASP.NET Core | Microsoft Learn</a></p><p><a href="https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-8.0#share-authentication-cookies-between-aspnet-4x-and-aspnet-core-apps">Share authentication cookies among ASP.NET apps | Microsoft Learn</a></p><p><a href="https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-8.0">Configure ASP.NET Core Data Protection | Microsoft Learn</a></p><p><a href="https://github.com/blowdart/idunno.CookieSharing">blowdart/idunno.CookieSharing: Project demonstrating how to share authentication cookies between ASP.NET 4.5 and ASP.NET Core applications. (github.com)</a></p><p><a href="https://learn.microsoft.com/en-us/aspnet/core/migration/inc/overview?view=aspnetcore-8.0">Incremental ASP.NET to ASP.NET Core update | Microsoft Learn</a></p><p><a href="https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig">Strangler Fig pattern — Azure Architecture Center | Microsoft Learn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4430e07405c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>