Azure部署.NET MVC及前后端分离应用实现新旧版本分流方案咨询
Awesome questions—Azure has exactly the tools you need to handle both scenarios smoothly. Let’s dive in:
1. .NET MVC应用:让新用户用新版,现有用户保留旧版
Yes, you absolutely can do this using Azure Deployment Slots combined with session affinity (sticky sessions). Here’s how:
- First, keep your existing old version running in the default Production slot, and deploy your new .NET MVC app to a separate Staging slot (you can create this directly in the Azure Portal for your App Service).
- Enable session affinity for your App Service: Head to the Configuration > General settings blade, set "Session affinity" to On. This ensures that returning users are routed back to the same slot they first accessed via the
ARRAffinitycookie Azure automatically manages. - Control traffic routing: Initially, keep 100% of traffic directed to the Production slot (old version). Once your staging slot’s new version is tested and ready, adjust the Traffic routing settings for your deployment slots to send 100% of new sessions to the Staging slot.
- Existing users with active sessions will stay tied to the Production slot (old version) until their session expires or they clear their cookies.
- New users (or users with no existing session cookie) will automatically land on the Staging slot (new version).
- Once all old sessions have concluded, you can either swap the Staging slot to become the new Production slot, or simply decommission the old Production slot to finalize the migration.
2. 客户端懒加载模块文件名冲突问题(部署期间)
This is another perfect use case for Deployment Slots—they completely isolate your old and new app assets, eliminating filename mismatch issues. Here’s the workflow:
- Deploy your updated app (with hashed lazy-loaded module filenames) to a Staging slot first. Since each slot has its own independent file system, the new hashed files won’t interfere with the old ones running in Production.
- Enable session affinity just like in the MVC scenario. This ensures users who started using the old version will keep requesting assets from the Production slot, while new sessions get routed to the Staging slot’s new assets.
- Deploy anytime without downtime: You can push updates to the Staging slot whenever you want, test them thoroughly, and only route traffic to them when you’re ready. Even if you need to deploy multiple times, the Staging slot acts as a safe buffer—your Production users never see broken module references.
- If you eventually want to make the Staging slot the primary Production environment, use Azure’s slot swap feature. Swap preserves session affinity mappings, so existing users on the old slot will still be routed to their original assets until their sessions end—no sudden breaks for active users.
A quick note: Deployment Slots are available for Azure App Service plans at the Standard tier and above, so make sure your plan supports them.
内容的提问来源于stack exchange,提问作者Buns of Aluminum
相关产品推荐
相关产品推荐

