0

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;
    }
  • Maybe helps - https://stackoverflow.com/questions/3772486/how-to-fix-root-element-is-missing-when-doing-a-visual-studio-vs-build – James P Dec 05 '19 at 12:00
  • I don't think it's the AccountController. What's the stack trace for the exception? – Ryan Hill Dec 06 '19 at 18:38
  • @RyanHill-MSFT Maby you are right. The stack is to long to paste here. But if you tro to go to the page [link](https://brflillaangar.azurewebsites.net/Account/Login) You will see it. – Fredrik Ling Dec 09 '19 at 08:08
  • @FredrikLing in looking at the stack trace, looks like you're using an anti-forgery tag helper on your Login page (either on the markup or the code-behind itself) that's referencing data protection. How did you configure your data protection in Startup.cs? Also, what AspNetCore version are you using? Your issue looks very similar to https://github.com/aspnet/AspNetCore/issues/4167. – Ryan Hill Dec 10 '19 at 17:53
  • @RyanHill-MSFT Yes you were on the right track as it seems. I fount the cause of the problem and solved it. See answers below. Thank you for your efforts! – Fredrik Ling Dec 11 '19 at 07:47

1 Answers1

2

Ok so I found the problem myself. After digging in to Debug snapshots available in Azure i got a hint that the directory where the app was trying to get the xml causing the exception was "D:\home\ASP.NET\DataProtection-Keys". When I analysed the content of that directory I saw that one xml-file was empty. I Deleted that file. And that solved the problem.