ASP.Net redirecting to local host after authentication

后端 未结 5 686
萌比男神i
萌比男神i 2020-12-18 12:45

I just created a webform that is hosted in my Azure subscription. I set it up with authenication via my works Azure directory for authenticating users. In debug this works f

相关标签:
5条回答
  • 2020-12-18 13:05

    I have solved this issue. Since it was such a pain I will keep this up as I couldn't find any answers on this. It was actually quite simple.

    You have two options. The one I did and which worked was changing the publish profile as below:

    Add the domain where the authentication is occurring. So if you have your web app hosted by a different azure account that which is authenticating the users, use the one that is authenticating.

    This will create two versions of your app on the site one for local host and one for the actual site.

    The second option(I have not tried this but it should work) is to go to the Azure account where you are authenticating the users and go to applications and then configure. Change the APP URL from local host to the url you are trying to get to.

    Here is an excellent link that explains how to do this clearly.

    Click this link for detailed explanation

    0 讨论(0)
  • 2020-12-18 13:11

    I had this issue when I switched an app from our company Azure over to a customer's Azure. In my case I'd forgotten to update the ida:ClientId, ida:AADInstance and ida:TenantId, which then meant that the value I'd set for ida:PostLogoutRedirectUri was ignored (I think) and instead my app redirected to localhost.

    Once I changed those ida values to the values from the app settings and subscriptions settings on our customer's Azure it all worked as expected.

    It took a while to track down all the values in Azure portal as they are all called something different, or aren't named at all:

    • ClientId can be found at Azure Active Directory > App Registrations > YourAppName. It's called 'Application ID' in Azure
    • Domain can be found on Azure Active Directory > Overview. It's currently in the top left in the format somename.onmicrosoft.com
    • TenantId this is the Azure AD instance ID, get that from Azure Active Directory > Properties and then it's called 'Directory ID'

    I spent a lot of time trying to work out where the localhost port that was being redirected to was in the code, but it simply isn't there as far as I can see, so I have no idea how Azure was choosing what localhost address to redirect to!

    0 讨论(0)
  • 2020-12-18 13:13

    You need to set another parameter in configuration that is replyUrl and assign to your web app, other wise it takes the url from which it was originated.

    0 讨论(0)
  • 2020-12-18 13:21

    I also had this issue and took these steps to resolve

    1. navigate to the app registration in AAD
    2. Open the manifest
    3. Change the ReplyUrl to the url of the app (e.g. http://appname.azurewebsites.net)

    Then I got the error

    Bad Request - Request Too Long HTTP Error 400. The size of the request headers is too long.

    Next I cleared all cookies from the browser, and this changed the error to just

    Bad Request

    So I went back to that ReplyUrl and changed it to https://appname.azurewebsites.net/.auth/login/aad/callback and now it appears to work.

    Note I also had to make sure I didn't have the site open in any other tabs before it started working

    0 讨论(0)
  • 2020-12-18 13:28

    I was able to fix this by changing my Startup.Auth.cs file redirectUri from "https://localhost:44316/" to https://myapp.com/

    0 讨论(0)
提交回复
热议问题