<?xml version="1.0" encoding="UTF-8" standalone="no"?><rss version="2.0">
  <channel>
    <title>Rick Strahl's Web Log</title>
    <link>https://weblog.west-wind.com/</link>
    <image>
      <url>ImageUrl</url>
      <title>Rick Strahl's Weblog</title>
      <link>https://weblog.west-wind.com/</link>
    </image>
    <description>Wind, waves, code and everything in between</description>
    <copyright>(c) West Wind Technologies 2006-2026</copyright>
    <pubDate>2026-06-01T00:48:41.9019391Z</pubDate>
    <lastBuildDate>2026-05-31T18:49:58.8878909Z</lastBuildDate>
    <generator>Rick Strahl's West Wind Weblog</generator>
    <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" content="noindex" name="robots"/><item>
      <title>Lost ASP.NET Cookies on IIS Application Pool Restarts</title>
      <description><![CDATA[<p><img src="https://weblog.west-wind.com/imageContent/2026/Lost-ASP-NET-Cookies-on-IIS-Restarts/CookieMonsterAttackOnIis.jpg" alt="Cookie Monster Attack On Iis"></p>
<p>Last week I finally updated my blog and moved it to .NET 10 from the ancient WebForms based engine I built 20 years ago. The app is deployed onto a Windows server running IIS and I ran into a snag related to cookie authentication in ASP.NET.</p>
<p>The problem showed up in my Admin panel login where the login would persist across browser sessions, but would not persist across <strong>IIS or ASP.NET application restarts</strong>. In other words, I could sign in and the cookie worked fine for the current session and even in subsequent sessions after shutting down and restarting the browser, but it would eventually fail after an application update, or the nightly scheduled IIS recycle ignoring the full cookie persistence expiration.</p>
<p><a href="https://markdownmonster.west-wind.com?ut=weblog"  target="_blank"
	  title="Markdown Monster - Easy to use, yet powerfully productive Markdown Editing for Windows">
<img src="https://weblog.west-wind.com/images/sponsors/banner-example.png?v=1.2" class="da-content-image" />
</a></p>
<h2 id="encryption-keys">Encryption Keys</h2>
<p>The app uses Cookie Authentication for the administration backend using a custom identity implementation on top of the base ASP.NET Identity APIs. The base Identity implementation in ASP.NET handles the cookie creation and management using internal logistics to encrypt and decrypt the cookie data, which serves both to hide the data as well as ensuring the content is not tempered with.</p>
<p>In the scenario I mention above the problem is that Cookies are re-generating when the machine application or the Application Pool is restarting (which on IIS usually coincides). For the TLDR; crowd the short version is that the Encryption Keys for the application weren't persisting across Application Pool restarts.</p>
<p>But before I get into the why of that lets look at how the ASP.NET Cookie encryption works by default on Windows and IIS and locally in your development environment.</p>
<h3 id="cookie-authentication-101-in-aspnet-core">Cookie Authentication 101 in ASP.NET Core</h3>
<p>Here's a quick review of explicit (non-Identity-Provider) Cookie Authentication in ASP.NET Core, which thankfully has gotten a lot simpler over the many convulsions that were plaguing early Authentication schemes in ASP.Core. These days doing your own Cookie implementation on top of the Identity base layer is pretty easy.</p>
<p>It's a two step process:</p>
<ul>
<li>Configure the Cookie/Identity middleware in the Startup</li>
<li>Sign in and Sign out in your endpoints with a single method call</li>
</ul>
<p>In your app startup set up the auth middleware:</p>
<pre><code class="language-csharp">services
    .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddCookie(o =&gt;
    {
        o.LoginPath = &quot;/account/login&quot;;
        o.LogoutPath = &quot;/account/logout&quot;;
        o.SlidingExpiration = true;
        o.ExpireTimeSpan = new TimeSpan(7, 0, 0, 0); // overridden by login 
        o.Cookie.Name = &quot;ww_wl&quot;;
    });
</code></pre>
<p>and to enable the middleware:</p>
<pre><code class="language-csharp">// in this order!
app.UseRouting();

app.UseAuthentication();
app.UseAuthorization();
</code></pre>
<p>Then in your authentication endpoint logic - a controller or minimal api endpoint or Page logic - you can sign in a user after you've validated their credentials (in my case <strong>not using the Identity provider</strong>) by adding the auth cookie:</p>
<pre><code class="language-csharp">// `user` comes from Db
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
identity.AddClaim(new Claim(&quot;Fullname&quot;, user.Fullname));
identity.AddClaim(new Claim(&quot;Username&quot;, user.Username));
identity.AddClaim(new Claim(&quot;UserId&quot;, user.Id.ToString()));

if (user.IsAdmin)                
    identity.AddClaim(new Claim(ClaimTypes.Role,&quot;Admin&quot;));

// Set cookie and attach claims
await HttpContext.SignInAsync(
    CookieAuthenticationDefaults.AuthenticationScheme,
    new ClaimsPrincipal(identity), 
    new AuthenticationProperties
    {
        IsPersistent = true,
        ExpiresUtc = DateTimeOffset.UtcNow.AddDays(7),
        AllowRefresh = true
    });
</code></pre>
<p>To sign out is also a one-liner:</p>
<pre><code class="language-cs">await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
</code></pre>
<p>With the sign in set you can now get a <code>Context.User.Identity</code> object when a cookie has been set, and you can examine <code>Identity.IsAuthenticated</code> and the individual <code>Claims</code> you added.</p>
<p>Here's the part that's relevant to this post and the lost cookies:</p>
<p>ASP.NET encodes all that information into an Identity cookie and encrypts that whole internally stored package with using a known encryption key when it it is created, and then uses that same key to decrypt the cookie value to restore the Identity associated data. More on this in a second as this is part of the problem I ran into...</p>
<p>Once signed in in my app, once the cookie is set, I can now access the admin panel. The cookie persists and should persist across browser sessions and  - in theory - across application shutdowns.</p>
<p>When I ran this on my local development setup with Kestrel and a regular logged in user everything is hunky dory. It works for all scenarios - including application restarts.</p>
<h2 id="on-server-on-iis-not-so-much">On Server on IIS: Not so much</h2>
<p>I then deployed the app to the server running IIS, and now the browser persistence was working fine even with browser restarts, but an application restart now forced a new login every time. Annoying!</p>
<p>So what gives?</p>
<h3 id="its-not-me---its-you-iis-you-old-bastard">It's not me - it's You! (IIS you old bastard!)</h3>
<p>Turns out I was looking in all the wrong places for the problem. I was looking at the ASP.NET Cookie configuration, which as a I showed above is pretty straight forward - not to many thing you can screw up there. I have several applications that use the <strong>exact same cookie auth set up</strong>, and they work just fine with cookies persisting across restarts. 🤔</p>
<p>After checking and checking and re-checking everything, and even pointing CoPilot at two projects and it confirmed that it couldn't spot a difference that would account for the different behavior either.</p>
<p>CoPilot turned out to be helpful after all, because in a small reasoning side note it mentioned the DataProtection API and key storage location. Although it didn't point at the exact cause - it made me review how encryption keys are generated and used and sure enough that's where the problem turned out to be!</p>
<h3 id="dataprotection-apis-for-cookie-encryption">DataProtection APIs for Cookie Encryption</h3>
<p>The cookies that ASP.NET writes are two-way encrypted and so the keys to read and write have to be available when the cookie is created and then also when it is read.</p>
<blockquote>
<p>More simply put: The underlying key can't change or be 'renewed' in any way between encryption and decryption.</p>
</blockquote>
<p>It turns out that the location where keys are stored is crucial. The location is configurable, but by default this location is stored in the active user's <strong>Windows User Profile</strong>. Aha! 💡</p>
<p><strong>Turns out when you create a new Application Pool in IIS, the User Profile activation is turned off by default!</strong>.</p>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Lost-ASP-NET-Cookies-on-IIS-Restarts/InvalidLoadUserProfileSetting.png" alt="Invalid Load User Profile Setting"></p>
<p>Oddly the default of <code>False</code> shows as a non-default value (ie. it's bolded) in the Application Pool Admin panel.</p>
<blockquote>
<h5 id="--what-does-load-user-profile-do"><i class="fas fa-lightbulb" style="font-size: 1.1em"></i>  What does Load User Profile do?</h5>
<p><em>Load User Profile</em> effectively causes the Application Pool to map environment variables like <code>USERPROFILE</code> and registry keys like <code>HKEY_CURRENT_USER</code>, so that they work as expected against the specific Identity User Profile. For 'dynamic' accounts like ApplicationPoolIdentity a Profile folder is created the first time the AppDomain starts and that profile is persisted after that and behaves the same as a standard user account.</p>
</blockquote>
<p>Here's why this matters: By default, <strong>ASP.NET stores the DataProtection API encryption keys used for Cookie Encryption in the active User Profile</strong>. No user profile, no persistent encryption key storage.</p>
<p>Instead when no User Profile is mapped, a temporary, non-persistent user profile is created when the Application Pool instance is created (so that profile update operations can work without blowing up) which results in new encryption keys getting generated every time the Application Pool starts.</p>
<p>Now, when a previously created cookie comes in it and tries to validate against the new cookie encryption keys, the keys no longer match and the integrity check against the cookie fails, and a new sign in is required. And that's precisely what I saw happening in my Admin Panel access.</p>
<p>There are couple of ways to fix this:</p>
<ul>
<li>Re-enable the User Profile Mapping so your get a persistent User Profile</li>
<li>Explicitly store the encryption keys in a known location</li>
</ul>
<h4 id="enable-the-load-user-profile">Enable the Load User Profile</h4>
<p>The simplest fix then is to set the <strong>Load User Profile</strong> setting in the Application Pool  to <code>True</code> to force using a persistent user profile for the Application Pool Identity account. This works both with existing User and System accounts as well as with dynamic accounts like <code>ApplicationPoolIdentity</code>.</p>
<p>And voila - keys now work across application and IIS restarts.</p>
<p>When you enable the user profile and don't set an explicit DataProtection API location, keys are stored in:</p>
<pre><code class="language-ps">%LOCALAPPDATA%\ASP.NET\DataProtection-Keys
</code></pre>
<blockquote>
<p>On non-Windows platforms this works in a similar fashion and are stored under:
<code>~/.aspnet/DataProtection-Keys/key-*.xml</code></p>
</blockquote>
<p>For Windows 'Service' accounts like Network Service this ends up being in a special location that is not in <code>c:\Users</code> as you might expect but in <code>c:\windows\ServiceProfiles\</code>:</p>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Lost-ASP-NET-Cookies-on-IIS-Restarts/ServiceProfileLocalAppDataFolder.png" alt="Service Profile Local App Data Folder"></p>
<p>For each account, each application gets its own set of keys based on some generated application id. You can see above several different applications that are all running under Network Service with their own dedicated encryption keys.</p>
<p>The Windows key files look like this in case you're interested:</p>
<pre><code class="language-xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;key id=&quot;65d6b51f-5282-4065-a0e4-1681d6fc0096&quot; version=&quot;1&quot;&gt;
  &lt;creationDate&gt;2024-03-08T00:52:28.2113827Z&lt;/creationDate&gt;
  &lt;activationDate&gt;2024-03-08T00:52:28.2059047Z&lt;/activationDate&gt;
  &lt;expirationDate&gt;2024-06-06T00:52:28.2059047Z&lt;/expirationDate&gt;
  &lt;descriptor deserializerType=&quot;Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60&quot;&gt;
    &lt;descriptor&gt;
      &lt;encryption algorithm=&quot;AES_256_CBC&quot; /&gt;
      &lt;validation algorithm=&quot;HMACSHA256&quot; /&gt;
      &lt;encryptedSecret decryptorType=&quot;Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor, Microsoft.AspNetCore.DataProtection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60&quot; xmlns=&quot;http://schemas.asp.net/2015/03/dataProtection&quot;&gt;
        &lt;encryptedKey xmlns=&quot;&quot;&gt;
          &lt;!-- This key is encrypted with Windows DPAPI. --&gt;
          &lt;value&gt;AQBAANCMnd8BFdERjHoAwE/Cl+sBAAAA/13cneK0bkmbEII3g6oEDgAAAAACAAAAAAAQZgAAAAEAACAAAADxJcn0BIJYkGlTN...==&lt;/value&gt;
        &lt;/encryptedKey&gt;
      &lt;/encryptedSecret&gt;
    &lt;/descriptor&gt;
  &lt;/descriptor&gt;
&lt;/key&gt;
</code></pre>
<p>Using the profile option is easiest because it's automatic, but if you need to share keys between multiple machines or multiple applications, you need to use another approach using one of the other supported key storage mechanisms.</p>
<p>And remember that if you turn Load User Profile to <code>False</code> you don't get a peristant profile and keys won't survive an Application Pool shutdown.</p>
<h4 id="explicitly-provide-dataprotection-folder-location">Explicitly provide DataProtection Folder Location</h4>
<p>If you don't want to be tied to a Windows User Profile there's a more deterministic approach in ASP.NET that lets you specify where the DataProtection keys are stored explicitly in an explicitly specified known location or another storage API solution.</p>
<p>This is configured through ASP.NET's configuration and there's a middleware service that you can register for this via  <code>services.AddDataProtection()</code>:</p>
<pre><code class="language-csharp">// Key storage for cookies - so cookies can persist
if (env.IsProduction())
{
    services.AddDataProtection()
        .PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(env.ContentRootPath, &quot;DataProtectionKeys&quot;)))
        .SetApplicationName(&quot;Weblog&quot;);
}
</code></pre>
<p>This example uses the File System provider to store the keys to a specified folder on disk, that contains the required key chain used for encryption using the DataProtection APIs. The layout for this folder is the same as shown in the Profile location, with the difference that you get to chose the location explicitly. Note that your Application Pool Identity account has to have read and write access in this location in order to create the keys written there.</p>
<p>You can store key - as I do here - in a folder below the app's content root (which is <strong>not</strong> Web accessible), or if you're overly paranoid, stuff it into a known, completely away-from-the-app location.</p>
<p>There are additional providers including persistence to the registry, AzureBlobStorage and you can also implement your own provider to store the key files.</p>
<p><a href="https://www.amazon.com/dp/BT00LN946S?externalReferenceId=fdeaac92-deca-4ea5-92c1-442cdc15a646"  target="_blank"
		  title="Sign up for an Amazon Visa - 5% cash back for Amazon and Whole Food Purchases">
<img src="https://weblog.west-wind.com/images/sponsors/AmazonPrimeVisa-Display.jpg" class="da-content-image" />
</a></p>
<h2 id="summary">Summary</h2>
<p>In the end for my application, I opted for the simplest solution of just enabling the user profile to automatically let it do its thing to store the keys. When running on Windows I tend to have the User Profile enabled even though I don't explicitly access it, because there always can be odd APIs that require a profile user that you might not expect anyway - this has bitten me more than once so I tend to enable it on all app pools. There's no real overhead here as all that really does is map environment variables to point at file and registry keys that already exist. I've had apps break in the past with off the wall failures because profile access was not available. There's no real downside to leaving it on especially with an otherwise non-interactive account.</p>
<p>The alternative of using an explicit store makes sense if you need to share keys between multiple machines in a load balancing or other multi-server environment, or if you simply want more control over where the keys go. Just make sure your app can actually write out the new keys in the location you choose.</p>
<p>Writing this down mainly to remind myself in the future, because due to the default setting in the Application Pool to not load a User Profile I've run into this more than once. Hopefully spending a little time writing it down will have jogged my memory enough not to repeat that mistake in the future... 😀</p>
<div style="margin-top: 30px;font-size: 0.8em;
            border-top: 1px solid #eee;padding-top: 8px;">
    <img src="https://markdownmonster.west-wind.com/favicon.png" style="height: 20px;float: left; margin-right: 10px;">
    this post created and published with the 
    <a href="https://markdownmonster.west-wind.com" target="top">Markdown Monster Editor</a> 
</div>
]]></description>
      <link>https://weblog.west-wind.com/posts/2026/May/31/Lost-ASPNET-Cookies-on-IIS-Restarts</link>
      <guid isPermaLink="false">yd1j66azcyja</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/May/31/Lost-ASPNET-Cookies-on-IIS-Restarts#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/May/31/Lost-ASPNET-Cookies-on-IIS-Restarts</guid>
      <pubDate>Sun, 31 May 2026 08:49:58 GMT</pubDate>
      <abstract><![CDATA[If you find that your ASP.NET authentication cookies expire every time your IIS application pool restarts or recycles, the culprit is likely the DataProtection API not finding the previously stored keys.  This post describes one gotcha I ran into with the default storage location on IIS in the user profile due to a default Application Pool setting.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/imageContent/2026/Lost-ASP-NET-Cookies-on-IIS-Restarts/CookieMonsterAttackOnIis.jpg</featuredImage>
    </item>
    <item>
      <title>Running ASP.NET Core Applications as a Subfolder Application</title>
      <description><![CDATA[<p><img src="https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/PostBanner.jpg" alt="Post Banner"></p>
<p>ASP.NET Core applications by default want to run in a root folder - and to be fair that's the 99% use case. But there are those occasional situations where you want to run a Web site in a sub folder rather than on the root of the Web site.</p>
<p>In this post I review what's required to run ASP.NET with a <code>PathBase</code> - which works with any Web server - and then specifically discuss how to set this up on IIS, which is a little more complicated than it should be.</p>
<blockquote>
<p>Although I discuss IIS specifically here for the physical deployment part since that's what I'm running on, the majority of this this content concerning the ASP.NET set up and modifications, applies to any Web server hosting when using sub folder mapping.</p>
</blockquote>
<p><a href="https://markdownmonster.west-wind.com?ut=weblog"  target="_blank"
	  title="Markdown Monster - Easy to use, yet powerfully productive Markdown Editing for Windows">
<img src="https://weblog.west-wind.com/images/sponsors/banner-example.png?v=1.2" class="da-content-image" />
</a></p>
<h2 id="why-would-i-need-to-run-out-of-a-subfolder">Why would I need to run out of a SubFolder?</h2>
<p>The specific scenario that I ran into was that recently I updated my old custom Blog engine, and decided to pull all my secondary blogs onto my own server from various blog publishing sites. I've always run my blog on my own hosted server and the main blog runs of its own sub-domain. But the other two blogs are small barely used product related blogs that ran on different hosting sites which I never used because they were terrible and it would be a better fit to just run them off the same site in <code>/blog/</code> folder.</p>
<p>With my recent site blog update - I finally moved the old WebForms app to .NET Core - and the much simplified deployment set up that comes with it, I decided to just run everything in house for these relatively low volume sites and get better, more consistent theming and a much easier publishing pipeline using Markdown Monster (using a new custom protocol - more on that in another post).</p>
<p>In any case the scenario here is that I have a root product site:</p>
<ul>
<li><a href="https://markdownmonster.west-wind.com">https://markdownmonster.west-wind.com</a></li>
</ul>
<p>and I now want to run the blog site out of a <code>/blog/</code> sub-folder, rather than as a root site. So:</p>
<ul>
<li><a href="https://markdownmonster.west-wind.com/blog">https://markdownmonster.west-wind.com/blog</a></li>
</ul>
<p>rather than a separate new root Web site like:</p>
<ul>
<li><a href="https://markdownmonsterblog.west-wind.com">https://markdownmonsterblog.west-wind.com</a></li>
</ul>
<p>(which is what I started with then aborted)</p>
<p>For SEO it's often beneficial to run everything on the same site which matters more for the low volume sites, but it's also cleaner and more consistent with other sub folders like <code>/docs</code> and <code>/support</code>. Running a sub folder site also requires less setup - you don't need yet another certificate and custom bindings to manage and so on. So using a subfolder is effectively more lightweight from a config perspective. On the other hand, using a subfolder site requires that more care is given how urls are created in the application as we'll see in a minute.</p>
<h2 id="creating-an-application-in-a-subfolder">Creating an Application in a Subfolder</h2>
<p>There are three parts to the process of running an application in a subfolder:</p>
<ul>
<li>Configuring ASP.NET for running from a subfolder</li>
<li>Fixing up links so no hardcoded <code>/</code> references are used</li>
<li>Configuring the Web Server for a subfolder application</li>
</ul>
<h3 id="setting-up-aspnet-for-running-with-a-subfolder">Setting up ASP.NET For running with a Subfolder</h3>
<p>Turns out setting up ASP.NET to run from a subfolder is pretty easy to do as there's a dedicated middleware to set up a custom <code>PathBase</code> as ASP.NET likes to call it.</p>
<p>In <code>program.cs</code> add this:</p>
<pre><code class="language-cs">var app = builder.build();
...
app.UsePathBase(&quot;/blog/&quot;);
</code></pre>
<p>This code goes into <code>program.cs</code> after the builder has created an <code>app</code> instance using the provided services. You'll want to do this near the top of the app middleware declarations to ensure the folder is respected all the way through the middleware pipeline - you'll want this before authentication,  static files and certainly before any routing middleware. I have it at the very top of the pipeline immediately after the builder has created the <code>app</code> instance.</p>
<p>I tend to parameterize the PathBase parameter with a configuration value, because I'm  duplicating the same application in multiple folders. So, in my Weblog application it looks like this:</p>
<pre><code class="language-csharp">// config from DI initialization or wlApp.Configuration static
if (!string.IsNullOrEmpty(config.VirtualPath) &amp;&amp; config.VirtualPath != &quot;/&quot;)
{
	app.UsePathBase($&quot;/{config.VirtualPath}/&quot;);
}
</code></pre>
<p>I have 3 blog sites - one of which runs as root and two of which run in <code>/blog/</code> subfolders. By parameterizing I can customize whether they run out of a subfolder or not without recompilation.</p>
<p>So what does <code>.AddPathBase()</code> actually do?</p>
<p>It's used to resolve Urls internally, using the path specified in <code>AddPathBase()</code>. Anytime ASP.NET creates a path dynamically for routes, uses <code>~/</code> in Views or Pages, or via <code>Url.Content()</code> or other <code>IUrlHelper</code> the path is automatically fixed up with the provided path base.</p>
<p>So instead of returning <code>/images/someimage.png</code> which you'd get for a root site, you get <code>/blog/images/someimage.png</code> for example.</p>
<p>If you use implicit routing, Url helper methods,  or you stick to using <code>~/</code> paths in your Views/Pages, ASP.NET does most of the heavy lifting for you,  without having to do anything else.</p>
<h4 id="fixing-up-root-paths-with--and-an-applicationbasepath">Fixing up Root Paths with <code>~/</code> and an ApplicationBasePath</h4>
<p>All this means is that you need to be more vigilant about how you <strong>root</strong> any explicitly referenced Urls both in View markup and in your application code. Code fixups should be minimized as much as possible.</p>
<p>For Views:  Rather than  using <code>&lt;img src=&quot;/images/someimage.png&quot; /&gt;</code> you should use <code>&lt;img src=&quot;~/images/someimage.png&quot; /&gt;</code> to ensure the appropriate path is used.</p>
<p>If you didn't do this - and let's be honest most of us don't - you can quickly find and replace all instances of hard coded root paths by doing a <strong>Find in Files Search</strong> (Ctrl-Shift-F) in your IDE and doing a search and replace for <code>=&quot;/</code> and replacing with <code>=&quot;~/</code> in all your View files. This should capture most scenarios in any physical files.</p>
<p>In code you can access the <code>IUrlHelper</code> interface in Razor views or injected into controllers or methods.</p>
<p><strong>In a Razor Page or View</strong></p>
<pre><code class="language-cs">var rootPath = Url.Content(&quot;~/images/someimage.png&quot;);
</code></pre>
<p><strong>In Application Code (.cs files)</strong></p>
<p>You can also inject <code>IUrlHelperFactory</code> (WTF Microsoft?) and then retrieve the <code>IUrlHelper</code> in a somewhat convoluted way that only an ivory tower architect could love:</p>
<pre><code class="language-csharp">public class MyService
{
    private readonly IUrlHelper _url;

	public MyService(
    			IUrlHelperFactory factory,
    			IActionContextAccessor actionContextAccessor)
	{
	    _url = factory.GetUrlHelper(
	        actionContextAccessor.ActionContext);
	}
	
	public string Resolve()
	{
	    return _url.Content(&quot;~/images/logo.png&quot;);
	}

}
</code></pre>
<p>If you don't want to deal with this and just have a couple of generic methods that work anywhere, the <a href="https://github.com/RickStrahl/Westwind.AspNetCore">Westwind.AspNetCore</a> package has a couple of generic helpers:</p>
<ul>
<li><a href="https://github.com/RickStrahl/Westwind.AspNetCore/blob/f244102fcc3b9fbed5f0d736bd0bb9cd2cd57799/Westwind.AspNetCore/Extensions/HttpContextExtensions.cs#L88">HttpContext.ResolveUrl()</a> extension method</li>
<li><a href="https://github.com/RickStrahl/Westwind.AspNetCore/blob/f244102fcc3b9fbed5f0d736bd0bb9cd2cd57799/Westwind.AspNetCore/Utilities/WebUtils.cs#L209">WebUtils.ResolveUrl()</a> - you provide a base path as a string and it resolves with that (works without any Context)</li>
</ul>
<h3 id="running-locally-with-a-subfolder">Running locally with a SubFolder</h3>
<p>If you create your app this way, and fix up Urls you run it locally using the Kestrel Web server with <code>dotnet run</code> or from your IDE you will see the site come up in a subfolder:</p>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/SubfolderInBrowser.jpg" alt="Subfolder In Browser"></p>
<p>The url includes the <code>/docs/</code> subfolder:</p>
<pre><code class="language-text">https://localhost:5001/docs/
</code></pre>
<p>If you stuck to using <code>~/</code> root paths everything is bound to just work the same as if you were running from the root folder.</p>
<p>Note that you should also change your dev <code>launchSettings.json</code> to reflect the new <code>launchUrl</code> that includes the subfolder:</p>
<pre><code class="language-json">&quot;Westwind.Weblog.MarkdownMonster&quot;: {
  &quot;commandName&quot;: &quot;Project&quot;,
  &quot;launchBrowser&quot;: true,
  &quot;environmentVariables&quot;: {
    &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
  },
  &quot;applicationUrl&quot;: &quot;https://localhost:5001&quot;,
  
  // THIS!
  &quot;launchUrl&quot;: &quot;https://localhost:5001/blog/&quot;
},
</code></pre>
<h3 id="configuring-iis-for-a-subfolder-application">Configuring IIS for a Subfolder Application</h3>
<p>While the <code>UsePathBase()</code> middleware handles the ASP.NET Core side seamlessly, IIS requires some extra work to create an <strong>Application</strong> under your root website.</p>
<p>IIS has Web Sites and Applications, which are very similar. Web Sites have extra configuration related to Host mappings and bindings, but otherwise Web Sites and Applications behave very similarly.</p>
<blockquote>
<h5 id="--one-aspnet-application-per-application-pool"><i class="fas fa-lightbulb" style="font-size: 1.1em"></i>  One ASP.NET Application per Application Pool</h5>
<p>IIS requires that each ASP.NET application uses <strong>its own dedicated ASP.NET Application Pool</strong>. Only a single ASP.NET Application can run inside of any given Application Pool, so unlike classic .NET sites, you can't share a single application pool for multiple Core apps.</p>
<p>It's possible to mix an ASP.NET Core app with a classic ASP.NET app or a static app in the same Application Pool, but you cannot have two or more ASP.NET Core Applications in an Application Pool. If you do only the first starts - the second one fails with a startup error.</p>
</blockquote>
<p>Here's what a folder based Application looks like in the IIS Manager:</p>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/DedicatedApplicationPoolInIIS.png" alt="Dedicated Application Pool In IIS"></p>
<blockquote>
<h5 id="--application-vs-virtual-folder"><i class="fas fa-lightbulb" style="font-size: 1.1em"></i>  Application vs. Virtual Folder</h5>
<p>There are two options in IIS for a folder: Application or Virtual. In this post I'm only talking about Applications which are self contained apps that run in their own Application Pool.</p>
<p>You can also create a virtual which does not create or use a new Application Pool but simply provides a virtual folder mapping with the app running in the parents application scope. This might work in some scenarios where the parent site is not an ASP.NET Core app. A static site or an ASP.NET Classic site but I've not tried this out. What I describe here is the scenario of creating a new Application that is mapped to an Application Pool explicitly.</p>
</blockquote>
<p>Note that the physical folder doesn't have to live in the matching parent site folder  - it can point to any location on disk. However, in most cases I put the actual site content into the relative folder location in the parent Web site for consistency in finding it later 😄</p>
<p>For an Application you need to have a <strong>dedicated Application Pool</strong> for this application - or at least an AppPool that doesn't have another ASP.NET application in it. That AppPool should be configured for <strong>No Managed Code</strong>.</p>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/IISApplicationPool.png" alt="IIS Application Pool"></p>
<p>Make sure you use an identity (user) that matches the rights that you need for your application. My apps tend to have a few configuration related settings that get written out so I have to use an account that has some additional rights.</p>
<p>Once this is set up and you've published your app, IIS will handle the initial request routing and pass the correct path information to the ASP.NET Core module to give you the same behavior that you see on your local install.</p>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/RunningInIIs.png" alt="Running In IIS"></p>
<h2 id="recommendations">Recommendations</h2>
<p>If you're like me and you built this site with a Root Site in mind initially,  doing this switch to running a sub-folder - I'd highly recommend you take a breather 😄 and spend a bit of time testing locally with the subfolder.</p>
<p>There are bound to be lots of little edge cases that are hard to test and easy to miss when doing smoke testing.</p>
<p>I initially built the site for my main Weblog which runs on root, never giving any thought for running out of a sub-folder. Then when I created the other two sites I initially set them both up as root sites before realizing that I'd rather run them in sub folders.</p>
<p>I went through the initial steps of making the site work with subfolders, and at first glance everything worked. However I ran into lots of little edge cases with a couple of oddball links that used different quotes around links, and any links in Javascript code (see below). I managed to find most issue before uploading the site to production, but over the next day a whole bunch error log reports came in from things I had missed - mostly links.</p>
<p>So take the time to test your functionality, if not automated then manually excercising all the nooks and crannies of your site.</p>
<h3 id="summary-of-path-fixups">Summary of Path Fixups</h3>
<p>To summarize these are some of the things that you have to probably fix or at least check when going from Site to Folder based:</p>
<h3 id="all-cshtml-razor--pages">All .cshtml, .razor  Pages</h3>
<p>All view pages can automatically fix up pages that reference via &quot;~/&quot; paths. Maybe you were diligent and started doing this right way. I rarely ever do this right - I do some with <code>~/</code> and some not which is no better than not doing it all 😄.</p>
<p>Luckily fixing up View pages is pretty straight forward: You can do a simple search and replace:</p>
<ul>
<li>Select *.cshtml, *.razor etc.</li>
<li>Search for <code>=&quot;/</code></li>
<li>Replace with <code>=&quot;~/</code></li>
</ul>
<p><img src="https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/SearchInFiles.png" alt="Search In Files"></p>
<h3 id="code-fix-ups">Code Fix ups</h3>
<p>You can do something similar for your .NET code, but you have to be a lot more selective and you can't do a search and replace.</p>
<ul>
<li>Select *.cs, *.cshtml     (cshtml for code blocks that build Urls)</li>
<li>Search for <code>&quot;/</code></li>
</ul>
<p>You want to search code both in your CS files and any code snippets in your Views/Pages.</p>
<p>Hopefully there shouldn't be a lot of those in your code because generally hard coding Urls is a bad idea. Typically this only happens if Urls need to be built up based on a host of input parameters.</p>
<pre><code class="language-cs">var redirectUrl = &quot;/somedeeplink/in/the/site&quot;;
</code></pre>
<p>changed to:</p>
<pre><code class="language-cs">var redirectUrl = wlApp.Configuration.ApplicationBasePath + &quot;somedeeplink/in/the/site&quot;;
</code></pre>
<p>Again, this should be pretty rare but worth checking for. This search is likely to produce a lot of false positives that don't require any changes.</p>
<h3 id="javascript-code">Javascript Code</h3>
<p>Javascript code is little more tricky. If you have script code that's making server calls, you may have to fix up paths in your scripts. Scripts aren't executable code and the ASP.NET parser doesn't touch them as the files are served as static resources. It's also common that you provide Urls as strings.</p>
<p>It's a lesson I've learned a long time ago - almost every application that calls to the server requires a configurable value to for a base path to call the server. There are lots of ways to do this and in SPA applications I always have a config object to do this.</p>
<p>However, for traditional server based Web apps that have only a few isolated JavaScript callbacks to the server, there is no common entry point for scripts - they are just loaded randomly.</p>
<p>In this application I do this the brute force way by providing a base path in a global script variable that gets embedded into the <code>_Layout.cshtml</code> page. Since <code>_Layout.cshtml</code> touches every page this is as close as I get to a global client side entry point. You can also put this in a script file but you have to make sure it gets loaded early enough that all other scripts can see it.</p>
<p>The idea is that I create a global variable - or rather a global object with an embedded variable - that is accessible from any script.  The script is defined at the top of the page in the header so it's visible to any code that follows.</p>
<p>I use another helper class from <code>Westwind.AspNetCore</code> helper for this:</p>
<pre><code class="language-cs">@
{
	// at the top of _Layout.cshtml

	// creates an object with props for the value(s) below
	var scriptVars = new ScriptVariables(&quot;window.page&quot;);  
	scriptVars.Add(&quot;basePath&quot;, wlApp.Configuration.ApplicationBasePath);
}
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;@(ViewBag.Title ??  wlApp.Configuration.ApplicationName)&lt;/title&gt;
    &lt;script&gt;
        // expands into an object with props
        @scriptVars.ToHtmlString();
    &lt;/script&gt;
</code></pre>
<p><a href="https://github.com/RickStrahl/Westwind.AspNetCore/blob/f244102fcc3b9fbed5f0d736bd0bb9cd2cd57799/Westwind.AspNetCore/Utilities/ScriptVariables.cs#L100">ScriptVariables</a> is a helper class that makes it easy to create a Json safe object of values you want to embed into the page from your .NET code. You basically add variables which are then serialized - Javascript and Html safe into the document when you use <code>@scriptVars.ToHtmlString()</code>.</p>
<p>In this case it produces an object with a single variable, but typically I end up with a handful of 'global' page level properties that need to be passed through:</p>
<pre><code class="language-js">window.page = {
	basePath: &quot;https://markdownmonster.west-wind.com/blog/&quot;
};
</code></pre>
<p>You can decide whether you want to use just <code>/blog/</code> or the fully qualified path as I'm doing here.</p>
<p>I'm using:</p>
<pre><code class="language-cs">scriptVars.Add(&quot;basePath&quot;, wlApp.Configuration.ApplicationBasePath);
</code></pre>
<p>which is configured value that I store in the app to have quick and easy access to the full site url. In the case of this <code>_Layout.cshtml</code> page you could also use:</p>
<pre><code class="language-cs">scriptVars.Add(&quot;basePath&quot;, Url.Content(&quot;~/&quot;);
</code></pre>
<p>which produces the site relative <code>/blog/</code> base path.</p>
<p>Now any scripts on the page - both in the page itself or in any script files can look at <code>page.basePath</code> and use that to fix up any Urls as necessary:</p>
<pre><code class="language-js">deletePost = ()=&gt; {
	if (confirm('Are you sure you want to delete this post?')) {
		// THIS
		var url = page.basePath + &quot;posts/@post.Id&quot;;
		
		ajaxJson(url, null,
			(res) =&gt; { 
			    // AND THIS
			    location.href = page.basePath + &quot;posts&quot;;
			},
			(err) =&gt; {
			    alert(&quot;Error deleting post: &quot; + err.responseText);
			},
			{ HttpVerb: &quot;DELETE&quot; });                                                    
	}
}
</code></pre>
<p><a href="https://amzn.to/3XmyPE0"  target="_blank"
	  title="Needs More Bass Bear T-Shirt">
<img src="https://weblog.west-wind.com/images/Sponsors/NeedsMoreBassTShirt-Display.png" class="da-content-image" />
</a></p>
<h2 id="summary">Summary</h2>
<p>Conversions like this are always more time consuming than you think - getting to 80% is easy. And just as you're padding yourself on the shoulder for an easy job you find all the edge cases that you didn't test for.</p>
<p>The basics mentioned above should get you through most of the conversion pretty quickly. It takes a little bit of time to set up, and I always kick myself for not doing things like using <code>~/</code> paths and explicit base path fixups for any coded paths right from the start.</p>
<p>Running Web sites out of a virtual folder is not all that common, but for many low impact sites I'm actually finding myself using them more often than I would have thought. When you need to do it, it's good to know that it's possible and not as complicated as I thought it might be.</p>
<p>Now that I've gone through it I suspect I will be more diligent in the future with new and old sites to use proper pathing from the get go even when it seems overkill and you think you'd never run any other way than out of a root site... we shall see.</p>
<div style="margin-top: 30px;font-size: 0.8em;
            border-top: 1px solid #eee;padding-top: 8px;">
    <img src="https://markdownmonster.west-wind.com/favicon.png" style="height: 20px;float: left; margin-right: 10px;">
    this post created and published with the 
    <a href="https://markdownmonster.west-wind.com" target="top">Markdown Monster Editor</a> 
</div>
]]></description>
      <link>https://weblog.west-wind.com/posts/2026/May/26/Running-ASPNET-Core-Applications-in-an-IIS-Subfolder-Application</link>
      <guid isPermaLink="false">qzzxfojpce9j</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/May/26/Running-ASPNET-Core-Applications-in-an-IIS-Subfolder-Application#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/May/26/Running-ASPNET-Core-Applications-in-an-IIS-Subfolder-Application</guid>
      <pubDate>Tue, 26 May 2026 14:16:20 GMT</pubDate>
      <abstract><![CDATA[While ASP.NET Core applications typically run from the root folder, some scenarios—such as hosting multiple blogs under a single domain—require running from a subfolder. This post explains how to configure ASP.NET Core with app.UsePathBase() for proper routing and ~/ path resolution, along with the IIS setup required for a dedicated Application Pool using "No Managed Code." It also covers key migration tips, including bulk updates for root-relative links and JavaScript adjustments to keep client-side functionality working in a subfolder environment.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/imageContent/2026/Running-ASP-NET-Core-Applications-in-an-IIS-Subfolder-Application/PostBanner.jpg</featuredImage>
    </item>
    <item>
      <title>Getting the Client IP Address in ASP.NET Core</title>
      <description><![CDATA[<p><img src="https://weblog.west-wind.com/imageContent/2026/Getting-the-Client-IP-Address-in-ASP-NET-Core/ClientIpBanner.jpg" alt="Client Ip Banner"></p>
<p><a href="https://markdownmonster.west-wind.com?ut=weblog"  target="_blank"
	  title="Markdown Monster - Easy to use, yet powerfully productive Markdown Editing for Windows">
<img src="https://weblog.west-wind.com/images/sponsors/banner-example.png?v=1.2" class="da-content-image" />
</a></p>
<p>When I need to pick up the client IP Address in ASP.NET Core I always forget where to find the connection information.</p>
<p>It's simple enough:</p>
<pre><code class="language-cs">HttpContext?.Connection?.RemoteIpAddress
</code></pre>
<p>but I never remember to look on the context object as I expect it to be on the Request 😄.</p>
<p>It's also useful to remember that if requests are proxied, we need to return the <strong>forwarded IP address</strong>, rather than the proxy's IP Address. Finally, in most cases you'd likely want the ipv4 address rather than an IPv6 address.</p>
<p>Here's ready to use helper extension method for the <code>HttpRequest</code> class that makes this more easily accessible:</p>
<pre><code class="language-csharp">/// &lt;summary&gt;
/// Returns the client IPv4 Address for a request.
///
/// Checks proxy forwarding first, the actual ip
/// and returns null.
/// &lt;/summary&gt;
/// &lt;param name=&quot;request&quot;&gt;The HttpRequest instance.&lt;/param&gt;
/// &lt;param name=&quot;checkForProxy&quot;&gt;
/// Indicates whether to check for proxy headers.
/// 
/// Default returns the un-translated connection's IP Address
/// returned by the Web server.
///
/// When true, checks the Proxy forwarding headers 
/// `X-Forwarded-For`, `Forwarded` and `X-Real-IP`
/// in that order and returns the 1st valid IP address found.
/// &lt;/param&gt;
/// &lt;returns&gt;IP Address or null&lt;/returns&gt;
public static string GetClientIpAddress(this HttpRequest request, bool checkForProxy = false)
{
    if (request == null) return null;

    string ip = NormalizeIpAddress(request.HttpContext?.Connection?.RemoteIpAddress);
    if (!checkForProxy)
        return ip;

    string proxy = GetForwardedIpAddress(request.Headers[&quot;X-Forwarded-For&quot;].FirstOrDefault());
    if (!string.IsNullOrEmpty(proxy))
        return proxy;

    proxy = GetForwardedIpAddress(request.Headers[&quot;Forwarded&quot;].FirstOrDefault(), true);
    if (!string.IsNullOrEmpty(proxy))
        return proxy;

    proxy = GetForwardedIpAddress(request.Headers[&quot;X-Real-IP&quot;].FirstOrDefault());
    return proxy ?? ip;
}


/// &lt;summary&gt;
/// Handle various forwarding headers and their custom parsing
/// of multiple proxy chain values
/// &lt;/summary&gt;
/// &lt;param name=&quot;headerValue&quot;&gt;The value of the forwarding header.&lt;/param&gt;
/// &lt;param name=&quot;isForwardedHeader&quot;&gt;Indicates if the header is the `Forwarded` header.&lt;/param&gt;
/// &lt;returns&gt;The extracted IP address or null if none found.&lt;/returns&gt;
private static string GetForwardedIpAddress(string headerValue, bool isForwardedHeader = false)
{
    if (string.IsNullOrWhiteSpace(headerValue))
        return null;

    foreach (var value in headerValue.Split(','))
    {
        string candidate = value?.Trim();
        if (string.IsNullOrWhiteSpace(candidate))
            continue;

        if (isForwardedHeader)
        {
            candidate = candidate.Split(';')
                .Select(segment =&gt; segment?.Trim())
                .FirstOrDefault(segment =&gt; segment != null &amp;&amp; segment.StartsWith(&quot;for=&quot;, StringComparison.OrdinalIgnoreCase));

            if (string.IsNullOrWhiteSpace(candidate))
                continue;

            candidate = candidate.Substring(4).Trim();
        }

        candidate = candidate.Trim('&quot;');

        if (candidate.StartsWith(&quot;[&quot;, StringComparison.Ordinal) &amp;&amp; candidate.Contains(&quot;]&quot;, StringComparison.Ordinal))
            candidate = candidate.Substring(1, candidate.IndexOf(']') - 1);
        else if (candidate.Count(ch =&gt; ch == ':') == 1)
        {
            var parts = candidate.Split(':');
            if (parts.Length == 2 &amp;&amp; IPAddress.TryParse(parts[0], out _))
                candidate = parts[0];
        }


        if (string.Equals(candidate, &quot;unknown&quot;, StringComparison.OrdinalIgnoreCase))
            continue;

        if (IPAddress.TryParse(candidate, out var address))
            return NormalizeIpAddress(address);
    }

    return null;
}

/// &lt;summary&gt;
/// Return as IPv4 address if the address is an IPv4-mapped IPv6 address,
/// otherwise return the original address as a string.
/// &lt;/summary&gt;
/// &lt;param name=&quot;address&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
private static string NormalizeIpAddress(IPAddress address)
{
    if (address == null)
        return null;

    if (address.IsIPv4MappedToIPv6)
        address = address.MapToIPv4();

    return address.ToString();
}
</code></pre>
<p>The bulk of this code is related to the Proxy forwarding handling which is optional. If you know you're directly connected to the Internet, you can skip the proxy forwarding stuff - in fact it's a good idea to do this to avoid any spoofing from a client. The various forwarding headers provide multiple IP Addresses in the proxy chain and you essentially need to pick out the first IP address to get the original address.</p>
<p>You can also find this as part of the <code>HttpRequestExtensions</code> class in the <a href="https://github.com/RickStrahl/Westwind.AspNetCore/blob/f244102fcc3b9fbed5f0d736bd0bb9cd2cd57799/Westwind.AspNetCore/Extensions/HttpRequestExtensions.cs#L204"><code>Westwind.AspNetCore</code> package here</a> which provides a host of other small, but frequently used extensions.</p>
<h2 id="alternative-use-the-ip-forwarded-headers-middleware">Alternative: Use the IP Forwarded Headers Middleware</h2>
<p><small><em>thanks to @RichardD in the comments</em></small></p>
<p>If you know you are always running behind a proxy server, and you need the IP Address in all or most requests, you can run the Forwarded Headers Middleware which handles the above logic and simply populates the <code>HttpContext.Connection.RemoteIpAddress</code> making the process complete transparent. That certainly works, but depending on how you use IP Address might be overkill.</p>
<p>The middleware is configured like this in the service configuration during startup:</p>
<pre><code class="language-cs">builder.Services.Configure&lt;ForwardedHeadersOptions&gt;(options =&gt;
{
    options.ForwardLimit = 2;
    options.KnownProxies.Add(IPAddress.Parse(&quot;127.0.10.1&quot;));
    options.ForwardedForHeaderName = &quot;X-Forwarded-For-My-Custom-Header-Name&quot;;
});

...

// near the very top of the middleware pipeline
// to ensure subsequent middleware pieces get the updated addresses
app.UseForwardedHeaders();
</code></pre>
<p>There's more info on the Microsoft site on <a href="https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-10.0">how the middleware works  here</a>.</p>
<p><a href="https://amzn.to/3EaiBqi"  target="_blank"
		  title="Broken Money - A Comprehensive Overview of the Past, Present, and Future of Money">
<img src="https://weblog.west-wind.com/images/sponsors/BrokenMoney-Display.jpg" class="da-content-image" />
</a></p>
<h3 id="summary">Summary</h3>
<p>Nothing new here, but given how often I fumble around with this value, creating a wrapper and putting a reminder here for quick lookup seems worth the effort 😄</p>
<h2 id="resources">Resources</h2>
<ul>
<li><a href="https://github.com/RickStrahl/Westwind.AspNetCore">Westwind.AspNetCore on Github</a></li>
<li><a href="https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-10.0">Configure ASP.NET Core to work with proxy servers and load balancers</a></li>
</ul>
<div style="margin-top: 30px;font-size: 0.8em;
            border-top: 1px solid #eee;padding-top: 8px;">
    <img src="https://markdownmonster.west-wind.com/favicon.png" style="height: 20px;float: left; margin-right: 10px;">
    this post created and published with the 
    <a href="https://markdownmonster.west-wind.com" target="top">Markdown Monster Editor</a> 
</div>
]]></description>
      <link>https://weblog.west-wind.com/posts/2026/May/13/Getting-the-Client-IP-Address-in-ASPNET-Core</link>
      <guid isPermaLink="false">dkvnwxdbh42n</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/May/13/Getting-the-Client-IP-Address-in-ASPNET-Core#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/May/13/Getting-the-Client-IP-Address-in-ASPNET-Core</guid>
      <pubDate>Wed, 13 May 2026 10:35:26 GMT</pubDate>
      <abstract><![CDATA[When I need to pick up the client IP Address in ASP.NET Core I always forget where to find the connection information and/or forget about picking proxy forwarding instead of the actual IP address. To make things easy and reusable, here's a small HttpRequest extension method.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Getting-the-Client-IP-Address-in-ASP-NET-Core/ClientIpBanner.jpg</featuredImage>
    </item>
    <item>
      <title>Putting the Westwind.Scripting C# Templating Library to work, Part 2</title>
      <description><![CDATA[In part 2 of this post series I look at some of the issues you may have to deal with when using the Westwind.Scripting library as an offline document or Web site creation engine. While running simple templates is easy enough, when generating static output for Web site publishing or local preview requires some special considerations.]]></description>
      <link>https://weblog.west-wind.com/posts/2026/Apr/23/Putting-the-WestwindScripting-Templating-Library-to-work-Part-2</link>
      <guid isPermaLink="false">5314605</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/Apr/23/Putting-the-WestwindScripting-Templating-Library-to-work-Part-2#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/Apr/23/Putting-the-WestwindScripting-Templating-Library-to-work-Part-2</guid>
      <pubDate>Thu, 23 Apr 2026 16:04:43 GMT</pubDate>
      <abstract><![CDATA[In part 2 of this post series I look at some of the issues you may have to deal with when using the Westwind.Scripting library as an offline document or Web site creation engine. While running simple templates is easy enough, when generating static output for Web site publishing or local preview requires some special considerations.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Revisiting-C-Scripting-with-the-Westwind-Scripting-Templating-Library,-Part-1/Part2-Banner.jpg</featuredImage>
    </item>
    <item>
      <title>Revisiting C# Scripting with the Westwind.Scripting Templating Library, Part 1</title>
      <description><![CDATA[The `Westwind.Scripting` library provides runtime C# code compilation and execution as well as a C# based Script Template engine using Handlebars style syntax with pure C# code. In this post I discuss use cases for script templating and some examples of how I use in real-world applications, followed by a discussion of the engine's features and the new Layout, Section and Partials feature that was added recently.]]></description>
      <link>https://weblog.west-wind.com/posts/2026/Apr/01/Revisiting-C-Scripting-with-the-WestwindScripting-Templating-Library-Part-1</link>
      <guid isPermaLink="false">5311031</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/Apr/01/Revisiting-C-Scripting-with-the-WestwindScripting-Templating-Library-Part-1#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/Apr/01/Revisiting-C-Scripting-with-the-WestwindScripting-Templating-Library-Part-1</guid>
      <pubDate>Wed, 01 Apr 2026 10:35:37 GMT</pubDate>
      <abstract><![CDATA[The `Westwind.Scripting` library provides runtime C# code compilation and execution as well as a C# based Script Template engine using Handlebars style syntax with pure C# code. In this post I discuss use cases for script templating and some examples of how I use in real-world applications, followed by a discussion of the engine's features and the new Layout, Section and Partials feature that was added recently.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Revisiting-C-Scripting-with-the-Westwind-Scripting-Templating-Library,-Part-1/Scripting-Banner.jpg</featuredImage>
    </item>
    <item>
      <title>Using .NET Native AOT to build Windows WinAPI Dlls</title>
      <description><![CDATA[Did you know that you can use .NET AOT compilation to create native Windows DLLs to potentially replace traditional C/C++ compiled DLLs? It's now possible to build completely native DLLs that can be called from external applications and legacy applications in particular using .NET AOT  compilation. In this post I show how this works and discuss the hits and misses of this tech.]]></description>
      <link>https://weblog.west-wind.com/posts/2026/Mar/21/Using-NET-Native-AOT-to-build-Windows-WinAPI-Dlls</link>
      <guid isPermaLink="false">5321191</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/Mar/21/Using-NET-Native-AOT-to-build-Windows-WinAPI-Dlls#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/Mar/21/Using-NET-Native-AOT-to-build-Windows-WinAPI-Dlls</guid>
      <pubDate>Sat, 21 Mar 2026 11:47:13 GMT</pubDate>
      <abstract><![CDATA[Did you know that you can use .NET AOT compilation to create native Windows DLLs to potentially replace traditional C/C++ compiled DLLs? It's now possible to build completely native DLLs that can be called from external applications and legacy applications in particular using .NET AOT  compilation. In this post I show how this works and discuss the hits and misses of this tech.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Using-NET-Native-AOT-to-build-Windows-WinAPI-Dlls/PostBanner.jpg</featuredImage>
    </item>
    <item>
      <title>Azure Trusted Signing Revisited with Dotnet Sign</title>
      <description><![CDATA[In this follow-up post to my previous guide on Azure Trusted Signing, I  explore how the new `dotnet sign` tool significantly simplifies the code signing process compared to the traditional `SignTool` workflow. The post identifies `dotnet sign` using `artifact-signing` as a faster, more efficient alternative.]]></description>
      <link>https://weblog.west-wind.com/posts/2026/Mar/02/Azure-Trusted-Signing-Revisited-with-Dotnet-Sign</link>
      <guid isPermaLink="false">5249291</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/Mar/02/Azure-Trusted-Signing-Revisited-with-Dotnet-Sign#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/Mar/02/Azure-Trusted-Signing-Revisited-with-Dotnet-Sign</guid>
      <pubDate>Mon, 02 Mar 2026 10:10:23 GMT</pubDate>
      <abstract><![CDATA[In this follow-up post to my previous guide on Azure Trusted Signing, I  explore how the new `dotnet sign` tool significantly simplifies the code signing process compared to the traditional `SignTool` workflow. The post identifies `dotnet sign` using `artifact-signing` as a faster, more efficient alternative.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Azure-Trusted-Signing-Revisited-with-Dotnet-Sign/TrustedSigningBanner.jpg</featuredImage>
    </item>
    <item>
      <title>Don't use the Microsoft Timestamp Server for Signing</title>
      <description><![CDATA[The default Microsoft timestamp server frequently causes intermittent failures during the code-signing process, particularly when processing many files or large binaries as part of a application distribution. These reliability issues can be resolved by replacing the Microsoft timestamp server with a more stable, compatible third-party alternative.]]></description>
      <link>https://weblog.west-wind.com/posts/2026/Feb/26/Dont-use-the-Microsoft-Timestamp-Server-for-Signing</link>
      <guid isPermaLink="false">5239628</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/Feb/26/Dont-use-the-Microsoft-Timestamp-Server-for-Signing#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/Feb/26/Dont-use-the-Microsoft-Timestamp-Server-for-Signing</guid>
      <pubDate>Thu, 26 Feb 2026 12:41:03 GMT</pubDate>
      <abstract><![CDATA[The default Microsoft timestamp server frequently causes intermittent failures during the code-signing process, particularly when processing many files or large binaries as part of a application distribution. These reliability issues can be resolved by replacing the Microsoft timestamp server with a more stable, compatible third-party alternative.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Dont-use-the-Microsoft-Timestamp-Server-for-Signing/SigningFailedBanner.png</featuredImage>
    </item>
    <item>
      <title>Reliably Refreshing the WebView2 Control</title>
      <description><![CDATA[The WebView2 control lacks a direct `Reload(noCache)` overload that forces a browser hard reload of the current page. Instead content is loaded with a soft refresh that - hopefully - reloads the current page and its dependencies dependent on WebView environment and server cache policies. In this post we'll look at how to work around this limitation and force a hard refresh in several different ways.]]></description>
      <link>https://weblog.west-wind.com/posts/2026/Feb/04/Reliably-Refreshing-the-WebView2-Control</link>
      <guid isPermaLink="false">5204283</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2026/Feb/04/Reliably-Refreshing-the-WebView2-Control#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2026/Feb/04/Reliably-Refreshing-the-WebView2-Control</guid>
      <pubDate>Wed, 04 Feb 2026 21:53:22 GMT</pubDate>
      <abstract><![CDATA[The WebView2 control lacks a direct `Reload(noCache)` overload that forces a browser hard reload of the current page. Instead content is loaded with a soft refresh that - hopefully - reloads the current page and its dependencies dependent on WebView environment and server cache policies. In this post we'll look at how to work around this limitation and force a hard refresh in several different ways.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2026/Reliably-Refreshing-the-WebView2-Control/WebViewRefreshBanner.jpg</featuredImage>
    </item>
    <item>
      <title>What the heck is a `\\.\nul` path and why is it breaking my Directory Files Lookup?</title>
      <description><![CDATA[I've been trying to track down an odd bug in my logs related to Null device failures in directory lookups which have been causing application level exceptions. In some odd scenarios these null mappings are showing up for files. In this post I take a look at what they are and how to work around them for this very edge case scenario.]]></description>
      <link>https://weblog.west-wind.com/posts/2025/Dec/08/What-the-heck-is-a-nul-path-and-why-is-it-breaking-my-Directory-Files-Lookup</link>
      <guid isPermaLink="false">5133488</guid>
      <author> (Rick Strahl)</author>
      <comments>https://weblog.west-wind.com/posts/2025/Dec/08/What-the-heck-is-a-nul-path-and-why-is-it-breaking-my-Directory-Files-Lookup#Comments</comments>
      <guid>https://weblog.west-wind.com/posts/2025/Dec/08/What-the-heck-is-a-nul-path-and-why-is-it-breaking-my-Directory-Files-Lookup</guid>
      <pubDate>Mon, 08 Dec 2025 13:15:18 GMT</pubDate>
      <abstract><![CDATA[I've been trying to track down an odd bug in my logs related to Null device failures in directory lookups which have been causing application level exceptions. In some odd scenarios these null mappings are showing up for files. In this post I take a look at what they are and how to work around them for this very edge case scenario.]]></abstract>
      <featuredImage>https://weblog.west-wind.com/images/2025/What-the-heck-is-a-nul-path-and-why-is-it-breaking-my-Directory-Files-Lookup/NullDeviceBanner.jpg</featuredImage>
    </item>
  </channel>
</rss>