question

jxt-allex avatar image
1 Vote"
jxt-allex asked MariosKimonos-8108 published

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

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.




azure-ad-b2c
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@jxt-allex Sorry, I am not able to access your code reference. Can you please provide code snippet over here which you are using to authenticate to azure ad b2c. Are you getting any errors in network or console in the "Developer Tools" of the browser you are using ?

8957-console-network-logs.png


0 Votes 0 ·
jxt-allex avatar image
0 Votes"
jxt-allex answered MariosKimonos-8108 published

Hi @saurabhsh-msft,

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@jxt-allex great to hear that. yes, that is correct. But, the solution also worked for me without changing aadInstance with the new url.

0 Votes 0 ·

Thanks your solution worked for me.

0 Votes 0 ·
jxt-allex avatar image
0 Votes"
jxt-allex answered jxt-allex commented

Hi @SaurabhSharma-msft

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.



console.png (31.2 KiB)
network.png (26.5 KiB)
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@jxt-allex Can you please provide the actual code snippet which you are using to authenticate to azure ad b2c ? Also, I am not able to access the reference link you have shared in your question. can you please check if the link is correct and help providing me the correct link.

0 Votes 0 ·

Hi @SaurabhSharma-msft,

I have fixed the link this morning.

And I'm using the following credentials to authenticate to Azure AD B2C:

   <appSettings>
     <add key="ida:Tenant" value="aicdb2c.onmicrosoft.com" />
     <add key="ida:ClientId" value="ef354479-458f-48e3-bd4f-a4ad313ebac7" />
     <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" />
   </appSettings>

0 Votes 0 ·

@jxt-allex thanks for sharing. I will take a look and update you with my findings.

0 Votes 0 ·
Show more comments
saurabhsh-msft avatar image
0 Votes"
saurabhsh-msft answered

@jxt-allex - 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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.