使用Visual Studio发布Azure App Service(.NET后端)后页面跳转异常
Hey there, let's figure out why your .NET backend on Azure App Service is redirecting to the Microsoft login page instead of showing the expected "This mobile app is up and running" message. Here are the most likely causes and fixes to try:
Check App Service Authentication Settings
Head to the Azure portal, find your App Service, and go to the Authentication tab. Chances are you've enabled App Service Authentication and set the action to "Require authentication"—this forces all unauthenticated requests to redirect to the login page. If your backend doesn't need mandatory auth, switch the action to "Allow anonymous requests (no action)", save the changes, and republish to test.Review Project Authentication Configurations
Look into your .NET project'sappsettings.json,Program.cs, orStartup.csfor auth-related code. Did you add middleware likeAddMicrosoftIdentityWebApp? Or set up a global[Authorize]filter? If global auth is the issue, either remove the global filter or add the[AllowAnonymous]attribute to your default home/health check route.Verify Publish Configuration Auth Settings
In Visual Studio's publish profile settings, check if you've checked the "Enable App Service Authentication" option. Sometimes publish syncs local auth configs to Azure automatically—if you don't need auth in production, uncheck this option before republishing.Inspect Route Configurations
Make sure your project has a default route (like/) that returns the expected page, and this route isn't decorated with[Authorize]. If the default route requires authorization, accessing it will naturally trigger a login redirect. You can temporarily add[AllowAnonymous]to the default controller/action to test this.Check App Service Logs
Turn on Log Stream in your App Service or download log files. The logs might show exactly which component is triggering the auth redirect, helping you pinpoint the root cause quickly.
内容的提问来源于stack exchange,提问作者Creepin

