- Azure Content Delivery Network – Getting Started
- Azure Content Delivery Network with Storage Account
- Azure Content Deliver Network – Create Profile
- Azure CDN – Adding Restrictions by Region
- Azure CDN – Enhance performance by compression
- Azure CDN – With .NET Core 5 Web Application
In previous post, we have seen how to enable Azure CDN on Azure web app. We will extend further on it in this post. By default, the Azure CDN endpoint would ignore the query string. Meaning, regardless of whether the query string is same or different, same page would be returned by CDN.
In real world, it might not be the case. If the application decides which contents to render on page based on query string, then it might be useful to setup CDN to consider query strings while caching the pages and serving the cached pages.
Modify Application Code
Let’s make simple modifications to the .NET Core web application. In the default page (
/home/index action), let’s expect a query string parameter
version. Set it to ViewData collection. Then on view render this version after application name. Below code snippet shows the changes done:
Now, let’s purge everything from Azure CDN endpoint as mentioned in previous post.
Every Querystring Returns Same Page
Now, if you try to access the web page using two different query string parameters:
Both the query strings, would show the text without the value of query string.
When I tried to both the pages multiple times, randomly showing “first” text after the application name. It means the CDN is not strictly respecting the query string.
Change CDN Settings
Now, let’s navigate to the CDN profile and open the CDN endpoint, which is associated with the Azure web app. Then select the Caching rules under Settings. It would open a new panel.
Under Global caching rules, the field Query string caching behavior has the value
Ignore query strings. Now, let’s open the dropdown and select value
Cache every unique URL value. Then click on Save button to save the changes.
Once again, let’s purge everything from Azure CDN endpoint as mentioned in previous post. Then give some time to get the settings propagate to all POPs. I started verifications in 20 minutes after purging the CDN endpoint data.
Now once again, let’s try to access the application using the CDN endpoint. Now use different query strings. Everytime, correct version should be available on the page.
Also, if the same URL is refreshed many times, the page always show correct version .
I hope you found this information useful. Let me know your thoughts.