Not able to set up Azure AD B2C on .NET Web Forms

Allex Rocha 101 Reputation points
2020-05-27T09:42:37.33+00:00

I'm currently not able to set up Azure AD B2C on .NET Web Forms

I could set up in MVC or .NET Core in no more than 5 minutes but we have a legacy and I can't do this in another tech.

I have followed this reference and just changed to my current config and got 500 error, once I click sign up or sign in buttons.

    <add key="ida:Tenant" value="aicdb2c.onmicrosoft.com" />
    <add key="ida:ClientId" value="{applicationId}" />
    <add key="ida:AadInstance" value="https://login.microsoftonline.com/{0}/v2.0/.well-known/openid-configuration?p={1}" />
    <add key="ida:RedirectUri" value="http://localhost:58851/" />
    <add key="ida:SignUpPolicyId" value="B2C_1_sign_up" />
    <add key="ida:SignInPolicyId" value="B2C_1_sign_in" />
    <add key="ida:UserProfilePolicyId" value="B2C_1_edit_profile" />

The message error is not helpful. It's just a generic message: "The page cannot be displayed because an internal server error has occurred".

After getting this message, if I hit enter in the address bar (http://localhost:58851/), I can access the page normally. Otherwise, I just get a blank page with this message.

I have Googled a lot and no luck.

I appreciate any help.

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
3,195 questions
{count} vote

Accepted answer
  1. Allex Rocha 101 Reputation points
    2020-06-05T00:50:42.527+00:00

    Hi @saurabh sharma ,

    Thanks for the help.

    I found what was causing the issue.

    The reference from GitHub is 3 years old and the ida:AadInstance was no longer valid.

    It should be like the following:

    <add key="ida:AadInstance" value="https://aicdb2c.b2clogin.com/{0}/{1}/v2.0/.well-known/openid-configuration" />  
    

    Please note that you should change aicdb2c to your name / domain.


2 additional answers

Sort by: Most helpful
  1. Allex Rocha 101 Reputation points
    2020-06-03T00:20:20.313+00:00

    Hi @Saurabh Sharma

    Console:
    8820-console.png

    Network:
    8977-network.png

    HAR file:
    {
    "log": {
    "version": "1.2",
    "creator": {
    "name": "WebInspector",
    "version": "537.36"
    },
    "pages": [
    {
    "startedDateTime": "2020-06-03T00:15:55.821Z",
    "id": "page_1",
    "title": "http://localhost:58851/",
    "pageTimings": {
    "onContentLoad": 1242.8700000746176,
    "onLoad": 1438.4870000649244
    }
    }
    ],
    "entries": [
    {
    "startedDateTime": "2020-06-03T00:15:55.819Z",
    "time": 1054.2170000262558,
    "request": {
    "method": "POST",
    "url": "http://localhost:58851/",
    "httpVersion": "HTTP/1.1",
    "headers": [
    {
    "name": "Host",
    "value": "localhost:58851"
    },
    {
    "name": "Connection",
    "value": "keep-alive"
    },
    {
    "name": "Content-Length",
    "value": "414"
    },
    {
    "name": "Cache-Control",
    "value": "max-age=0"
    },
    {
    "name": "Upgrade-Insecure-Requests",
    "value": "1"
    },
    {
    "name": "Origin",
    "value": "http://localhost:58851"
    },
    {
    "name": "Content-Type",
    "value": "application/x-www-form-urlencoded"
    },
    {
    "name": "User-Agent",
    "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
    },
    {
    "name": "Accept",
    "value": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9"
    },
    {
    "name": "Sec-Fetch-Site",
    "value": "same-origin"
    },
    {
    "name": "Sec-Fetch-Mode",
    "value": "navigate"
    },
    {
    "name": "Sec-Fetch-User",
    "value": "?1"
    },
    {
    "name": "Sec-Fetch-Dest",
    "value": "document"
    },
    {
    "name": "Referer",
    "value": "http://localhost:58851/"
    },
    {
    "name": "Accept-Encoding",
    "value": "gzip, deflate, br"
    },
    {
    "name": "Accept-Language",
    "value": "en-AU,en;q=0.9,pt-BR;q=0.8,pt;q=0.7"
    },
    {
    "name": "Cookie",
    "value": ".AspNetCore.Antiforgery.-qL_f1LO0ZA=CfDJ8DEVO1hfMPxDkNcXD1hM-gJKXXWstDFy809mzhZBQ3MBJqhlwkRZDKuhXP1K9zmoYZN5I3cyG5tArgbEm5bhVmG8ZVYVKktKVDMPbEsq6VgddCKgPfTGCxxGwE52IunkhsmqzfNGvAYP2V5J9DCqQ2g; ASP.NET_SessionId=xrdmgd3t2c2dgpgytxef2k0s"
    }
    ],
    "queryString": [],
    "cookies": [
    {
    "name": ".AspNetCore.Antiforgery.-qL_f1LO0ZA",
    "value": "CfDJ8DEVO1hfMPxDkNcXD1hM-gJKXXWstDFy809mzhZBQ3MBJqhlwkRZDKuhXP1K9zmoYZN5I3cyG5tArgbEm5bhVmG8ZVYVKktKVDMPbEsq6VgddCKgPfTGCxxGwE52IunkhsmqzfNGvAYP2V5J9DCqQ2g",
    "expires": null,
    "httpOnly": false,
    "secure": false
    },
    {
    "name": "ASP.NET_SessionId",
    "value": "xrdmgd3t2c2dgpgytxef2k0s",
    "expires": null,
    "httpOnly": false,
    "secure": false
    }
    ],
    "headersSize": 954,
    "bodySize": 414,
    "postData": {
    "mimeType": "application/x-www-form-urlencoded",
    "text": "__EVENTTARGET=ctl00%24Account1%24linkSignUp&__EVENTARGUMENT=&__VIEWSTATE=Xl4ldmCTo%2BNZIU9AxOt2%2BQYGnK6cBZ0t7CnRRvrMJkjWxe1%2Fqb5vIUhju%2Bp901Rmu%2FpM%2B9FwZDfvu0%2FvvM7IbC%2FWS6QhQOwPevwxPi1G2Yw%3D&__VIEWSTATEGENERATOR=CA0B0334&__EVENTVALIDATION=NNoQu4SN39n8vQzgQTJZovzr9zjPem4XpZwUphM5culOHn%2B3jvonvbGFW1ez3607cey7O%2BKWDGU%2BSBfEhwPbeTWb0r8LUpyp5obfMCPZaN%2F5hRwhwNiqEwL1yFU2%2B4jcc2SJUxJcTXTgOrx6oqohGA%3D%3D",
    "params": [
    {
    "name": "__EVENTTARGET",
    "value": "ctl00%24Account1%24linkSignUp"
    },
    {
    "name": "__EVENTARGUMENT",
    "value": ""
    },
    {
    "name": "__VIEWSTATE",
    "value": "Xl4ldmCTo%2BNZIU9AxOt2%2BQYGnK6cBZ0t7CnRRvrMJkjWxe1%2Fqb5vIUhju%2Bp901Rmu%2FpM%2B9FwZDfvu0%2FvvM7IbC%2FWS6QhQOwPevwxPi1G2Yw%3D"
    },
    {
    "name": "__VIEWSTATEGENERATOR",
    "value": "CA0B0334"
    },
    {
    "name": "__EVENTVALIDATION",
    "value": "NNoQu4SN39n8vQzgQTJZovzr9zjPem4XpZwUphM5culOHn%2B3jvonvbGFW1ez3607cey7O%2BKWDGU%2BSBfEhwPbeTWb0r8LUpyp5obfMCPZaN%2F5hRwhwNiqEwL1yFU2%2B4jcc2SJUxJcTXTgOrx6oqohGA%3D%3D"
    }
    ]
    }
    },
    "response": {
    "status": 500,
    "statusText": "Internal Server Error",
    "httpVersion": "HTTP/1.1",
    "headers": [
    {
    "name": "Cache-Control",
    "value": "private"
    },
    {
    "name": "Content-Type",
    "value": "text/html"
    },
    {
    "name": "Server",
    "value": "Microsoft-IIS/10.0"
    },
    {
    "name": "X-AspNet-Version",
    "value": "4.0.30319"
    },
    {
    "name": "X-SourceFiles",
    "value": "=?UTF-8?B?QzpcVXNlcnNcYWxsZXhcRG93bmxvYWRzXEIyQy1XZWJGb3Jtcy1Eb3ROZXRcQjJDLVdlYkZvcm1zXGRlZmF1bHQuYXNweA==?="
    },
    {
    "name": "X-Powered-By",
    "value": "ASP.NET"
    },
    {
    "name": "Date",
    "value": "Wed, 03 Jun 2020 00:15:56 GMT"
    },
    {
    "name": "Content-Length",
    "value": "75"
    }
    ],
    "cookies": [],
    "content": {
    "size": 75,
    "mimeType": "text/html",
    "compression": 0,
    "text": "The page cannot be displayed because an internal server error has occurred."
    },
    "redirectURL": "",
    "headersSize": 349,
    "bodySize": 75,
    "_transferSize": 424
    },
    "cache": {},
    "timings": {
    "blocked": 2.518000010214746,
    "dns": -1,
    "ssl": -1,
    "connect": -1,
    "send": 0.139,
    "wait": 1049.419000011556,
    "receive": 2.1410000044852495,
    "_blocked_queueing": 1.943000010214746
    },
    "serverIPAddress": "[::1]",
    "_initiator": {
    "type": "other"
    },
    "_priority": "VeryHigh",
    "_resourceType": "document",
    "connection": "29084",
    "pageref": "page_1"
    }
    ]
    }
    }

    Thanks for your help.


  2. saurabh sharma 76 Reputation points
    2020-06-05T00:45:11.94+00:00

    @Allex Rocha - I have able to run your provided sample. There are few changes you need to make -

    1. Instead of using http you need to use "https" for application redirect URI in web.config file -
      <add key="ida:RedirectUri" value="https://localhost:58854/" /> Please make sure to provide a different port number than used by http. Here I have changed it to 58854
    2. You need to update the same in the registered application on Azure portal -
      9201-webapp1-redirect-uri.png
    3. You also need to update "Project Url" in Visual Studio project to use the new https url as shown below -

    9135-b2c-webforms-visual-studio.png

    Here is the result which I can see with the changes -
    9162-b2c-webforms.png

    Please let me know if any other questions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.