首页 > 解决方案 > Azure, MVC Core Web App suddenly throw "XmlException: Root element is missing" + "CryptographicException"

问题描述

I have a web application hosted by an Azure App service. It has worked fine for years but suddenly I get an Exception when i try to enter the Account/login action: -->"XmlException: Root element is missing" + "CryptographicException: An error occurred while trying to encrypt the provided data.". If i got to Home/About action (which have [AllowAnonymous] attribute) that page works fine. But if i try to enter a page within the Account controller which have the [AllowAnonymous] attribute. That also throw the same Exception. So I am guessing the Exception occur in the constructor for the Account controller. See below.

I have not made any updates to the page in months and it has worked fine until now. If I run the application locally on my PC (connected to the same database on azure) it works fine. As I understand Azure have recently made updates to their portal. My guess is that the cause of the error is related to that.

Does anyone know how to solve this?

public AccountController(
        UserManager<ApplicationUser> userManager,
        SignInManager<ApplicationUser> signInManager,
        IEmailSender emailSender,
        ILogger<AccountController> logger,
        ApplicationDbContext context)
    {
        _userManager = userManager;
        _signInManager = signInManager;
        _emailSender = emailSender;
        _logger = logger;
        _context = context;
    }

标签: azureasp.net-coreasp.net-core-mvcazure-web-app-servicexmlexception

解决方案


好的,所以我自己发现了问题。在深入研究 Azure 中可用的调试快照后,我得到一个提示,即应用程序试图获取导致异常的 xml 的目录是“D:\home\ASP.NET\DataProtection-Keys”。当我分析该目录的内容时,我看到一个 xml 文件是空的。我删除了那个文件。这解决了问题。


推荐阅读