Published ASP.NET MVC 5 app with Organizational Account authentication Redirects back to localhost

南楼画角 提交于 2019-12-06 05:01:14

To answer my question. Below is one possible workable workflow:

  1. From Visual Studio 2013, Project->New->Web->ASP.NET Web Application
  2. Name: WebApplication2
  3. New ASP.NET Project – WebApplication2

    a. Select a template: MVC

    b. Change Authentication

    i.  Organizational Accounts
    ii. Cloud – Single Organization
    iii.    Domain: <organization_name>.onmicrosoft.com
    iv. Access Level: Single Sign On
    

    c. OK

  4. Configure Microsoft Azure Website

    a. Site name: WebApplicationXXXXX

    b. Region: North Europe

    c. Database server: existing database server

    d. Database username: admin

    e. Database password: admin_password

    f. OK

  5. Publish with the default profile without changing any parameters

    a. The result will be Server error in application. In the address bar, it will be http://webapplicationXXXXX.azurewebsites.net/

  6. Browse to https instead of http: https://webapplicationXXXXX.azurewebsites.net/

    a. It will be redirected to organizational account correctly. After successful authentication, it will be redirected back to https://localhost:44310/ which is not accessible from Azure website, so it will fail.

  7. Launch publishing again with some corrections this time, Publish Web

    a. Connection->DestinationUrl: https://webapplicationXXXXX.azurewebsites.net/

    b. Settings->Enable Organizational Authentication (check)

    i.  Domain: <organization_name>.onmicrosoft.com
    
    ii. Access Level: Single Sign On
    

    c. Publish

It might fail to authenticate first time (no idea why), but when manually browsed to https://webapplicationXXXXX.azurewebsites.net/, it will work as it is supposed to. By skipping steps 5 and 6 above, the workflow becomes workable. It’s another question if it’s optimal and according to the best practices.

You can setup return url for organizational account auth inside active directory in management panel (azure)

Here a good article

Select your App inside Active Directory, click on app name -> config -> single sign on -> config return url

I was having the same problem but found that enable organisational authentication option has been removed in Visual Studio 2015 and 2017.

You have to edit the relying party trust on your ADFS server. Right click > Properties > Endpoints > Add a WS-Federation Endpoint pointing to your https root site URL > Tick set as default.

My site now works and authenticates with ADFS.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!