0
votes

I'm currently working on a website with the ASP.net MVC framework for my own amusement and I decided to stop working with a local database and to publish my web application on azure with it's associated database. Now I have a strange issue with authentication. Identity.IsAuthenticated is always true. At first I got the following error :

A claim of type 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' or 'http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider' was not present on the provided ClaimsIdentity. To enable anti-forgery token support with claims-based authentication, please verify that the configured claims provider is providing both of these claims on the ClaimsIdentity instances it generates. If the configured claims provider instead uses a different claim type as a unique identifier, it can be configured by setting the static property AntiForgeryConfig.UniqueClaimTypeIdentifier.

Without understanding too much I found a solution which was to configure the AntiForgery token in the global.cs file

AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;

At the point the error stopped showing but the user identified don't exist in the AspNetUsers table. Of course when I try to get info from the user in a section where authentification is needed the application crashes since no entry exists.

On my layout, I have a section of code to display some data if the user is authenticated

@if (User.Identity.IsAuthenticated)
{
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
    {
        @Html.AntiForgeryToken()

        <ul class="nav navbar-nav navbar-right">
            <li>
                @Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })
            </li>
            <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
        </ul>
    }
}

The User.Identity.GetUserName() always returns live.com#[MyAzureAccount]@outlook.com and it's impossible for me to logoff.

This seems like an identity issue but as I didn't touch the code generated when I started the project and as it works in local I would've expected it to work.

1
Did you: 1) remove all your Cookies? 2) try incognito mode?TGlatzer
Incognito mode showed something interesting, I had to log on my azure account to acces the application. I now need to find why this is happening. Thanks for the idea.user3044142
That's possibly because of stray Cookies ;)TGlatzer
I don't know what they are but I'm definitely going to investigate. If I found the solution I'll post it if no one has answered in the meanwhileuser3044142

1 Answers

0
votes

The solution was simply to download the publishing files from azure instead of filling by hand the fields for publishing. I don't really know why it worked but it solved the problem.