Friday, May 9, 2014

How to Authenticate MVC5 Web Users with Azure Active Directory Access Control ACS

Friday, May 09, 2014 Posted by Andre Broers , , , , 87 comments
In this example I will show how to do authentication with Azure ACS from an MVC 5 web application. For this example I will use Visual Studio 2013. But we will start with some work in the Azure Management Portal.
The first thing we do is create a new Access Control Namespace. Click new in the bottom of the portal and select Access Control - Quick Create and type a unique namespace name (in my case my1stacs) and select your region.



Click create to create the new ACS namespace. Now select the tab ACCESS CONTROL NAMESPACES to find your new namespace. Select it and click on MANAGE in the bottom.



Now it is time to fire up Visual Studio and create our MVC 5 Website.
Open Visual Studio 2013 and click New Project. Select an ASP.NET Web Application, give it a location and a name and click OK.



Select MVC as the template and click on Change Authentication. Choose Organizational Accounts and select On-Premises as option. (On-Premises? Yes :-) )


Now go back to our ACS management portal and click on Development Application integration on the left and select the WS-Federation Metadata url.


Copy this url and paste it in the On-Premises Authority field in Visual Studio.


You can leave the App ID URI empty. You can change this value later when you deploy to another location in the web.config.
Click OK. And again on OK. Our web application is being generated.

Check the web.config for our Realm.

Now go back to our ACS management portal and create a new Relying Partner (our web application).
Click Trust relationships - Relying party application and click Add.


Type the Name and the Realm and the Return URL. The Realm and the Return URL are the same and are as seen in the web.config.


Leave the rest default and press Save on the bottom of the form.

We have now created a Relying party for the default Windows Live provider.


And it has created a default rule group.

Open this Rule Group and click on the Default rule group:



Now click on generate to add the default rule where it copies a claim from the Windows Live Provider to our ACS Relying Party.


Click on generate and Save.

How to implement ACS Single Sign-off functionality


Now go back to Visual Studio. The first thing we want to create is a logoff button so we can logoff and retry our demo without removing cookies etc.etc.

Edit the file _LoginPartial.cshtml


So that it looks like this:



In this you have to change the hostname to the one of your acs and the wtrealm to your realm and the last link is the one of the page to return to after the logoff. In our case the home page where you get redirected again to the Windows Live login page.

Try running the WebApplication. You immediately get redirected to the login page. When you login to the Identity Provider it wil redirect you to the home page of you application. Use the logoff link to disconnect again.

Only protect a certain area of the site

In the next example we only gonna protect the About page. So all pages of our Web Application are open but when you link to the About page you have to authorise. It's as simple as we always did with ASP.NET web applications by editing the web.config file:


Lets comment out both authorisation sections from the web.config so that we have no authentication on our web application anymore.
Next open up the HomeContoller.cs and add an Authorize attribute to our About method.


When we run our WebApplication1 we can browse our app freely as long as we stay away from the About page. (If you are still connected hit the logoff link to sign out and see that you can still access the web application). When you click the About page you will get redirected to Windows Live to logon and after this you will get redirected to the About page.

How to access the claims we got from ACS?

Use the following code to access the claims from the connected user:





Happy .netting

87 comments:

  1. Hi

    First of all thanks for writing this blog..it helped really :)

    I am getting problem in accessing the User's Name & EmailId, in User Name is receiving a GUID, is there a way to greet the user and access his Email address.

    ReplyDelete
  2. Thanks for your informative article and the blog. your article is very useful for .net professionals and freshers looking for interview. Best DOT NET Training | Dot Net course Chennai

    ReplyDelete
  3. MVC is a new concept in dot net actually now only i have moved to learn mvc, In your blog i am finding some useful information about mvc, thanks for sharing i am expecting your future blog,... DOT NET Training in Chennai

    ReplyDelete
  4. Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.If anyone wants to get Dot Net Training in Chennai reach FITA, rated as No.1 Dot Net Training Institute in Chennai.

    ReplyDelete
  5. Here i had an opportunity to learn about get authenticate mvc5 using html, it was very clear to understand keep sharing...
    DOT NET Training Institutes in Chennai

    ReplyDelete
  6. Hi Andre,
    I am following your blog from the beginning, it was so distinct & I had a chance to collect conglomeration of information that helps me a lot to improvise myself.
    Thanks,
    Web design training in Chennai

    ReplyDelete
  7. Its a advanced concepts for designing sites.Thanks for sharing the great information.

    dot net training in chennai | Ccna Training in Chennai

    ReplyDelete
  8. Thanks for sharing this and its useful for designing the site...
    Android Training in bangalore

    ReplyDelete
  9. Thanks for the Great post Broersa.. That was very informative and helful.. thanks ASP.NET Training

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    Regards,
    ccna training center in Chennai|ccna training chennai

    ReplyDelete
  12. Need help to logout for live id, google and facebook for ACS
    I am using MVC3

    ReplyDelete
  13. This is exactly what I was searching for. Awesome post. Thanks a bunch. Helped me in taking class for my students. Wish to follow your posts, keep writing! God Bless!
    Shashaa
    Dot Net course in Chennai | Dot Net course in Chennai | Dot Net course in Chennai

    ReplyDelete
  14. There are lots of information about latest technology, like Hadoop cluster is a special type of computational cluster designed specifically for storing and analyzing huge amounts of unstructured data in a distributed computing environment. This information seems to be more unique and interesting. Thanks for sharing.
    Big Data Training Chennai | Best hadoop training institute in chennai | Big Data Training Chennai

    ReplyDelete
  15. What this essentially means is that any user opening up our web ... Windows Azure's Access Control Services helps us to achieve this so easily, ... was configured to authenticate users via Azure Active Directory .... PHP Training in Chennai

    ReplyDelete

  16. Hai if our training additional way as (IT) trained as individual,you will be able to understand other applications more quickly and continue to build your skll set
    which will assist you in getting hi-tech industry jobs as possible in future courese of action..
    visit this blog webMethods-training in chennai



    ReplyDelete
  17. great article!!!!!This is very importent information for us.I like all content and information.I have read it.You know more about this please visit again.
    QTP Training in Chennai

    ReplyDelete
  18. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Informatica Training in Chennai

    ReplyDelete
  19. I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
    informatica training in chennai

    ReplyDelete

  20. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    QTP Training in Chennai

    ReplyDelete
  21. Latest Govt Bank Jobs Recruitment Notification 2016


    Nice content many thanks! We think your posts are excellent as well as hope there will be more in future.....................

    ReplyDelete
  22. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog.
    QTP Training in Chennai

    ReplyDelete
  23. Hai you have to learned to lot of information about selenium Gain the knowledge and hands-on experience you need to successfully design,so you have more details visit this site..
    selenium Training in Chennai

    ReplyDelete
  24. Whatever we gathered information from the blogs, we should implement that in practically then only we can understand that exact thing clearly, but it’s no need to do it, because you have explained the concepts very well. It was crystal clear, keep sharing..
    Best Oracle SQL & PL/SQL Training In Chennai
    Microsoft SQL Server Training In Chennai
    Teradata Training In Chennai
    MySQL Training In Chennai
    Sybase Training In Chennai
    Informix Training In Chennai
    Best Oracle Training In Chennai

    ReplyDelete
  25. Great article!!!!!This is very importent information for us.I like all content and information.I have read it.You know more about this please visit again.
    mainframe developer Training in Chennai

    ReplyDelete
  26. That is a brilliant article on dot net training in Chennai that I was searching for. Helps us a lot in referring at our dot net training institute in Chennai. Thanks a lot. Keep writing more on dot net course in Chennai, would love to follow your posts and refer to others in dot net training institutes in Chennai.

    ReplyDelete
  27. Hello admin, thank you for your informative post on hadoop training in Chennai. It helped a lot in training my students during our hadoop training Chennai sessions. We at Fita, provide big data training in Chennai for students who are interested in choosing a career in big data.

    ReplyDelete
  28. Nice Article! Mostly I have gathered knowledge from the blogger, because its provides more information over the books & here I can get more experienced skills from the professional, thanks for taking your to discussing this topic.
    Regards,
    Angular training institutes in Chennai|Angularjs training in chennai|Angular training institute in Chennai

    ReplyDelete
  29. TechnoSoftwar having several years experience working with global customers, connecting our professionals to their business needs, as their IT Development & Support Partner. TechnoSoftwar having a team of dedicated and experienced softwares developers that works for your all business needs. TechnoSoftwar deals in web design and development, Customized ERPs, CRMs, Web & Mobile Applications, eCommerce platforms etc.

    ReplyDelete
  30. Haryana HSSC Steno Typist Recruitment 2016


    The information provided was extremely useful and informative. Thanks a lot for useful stuff.....................

    ReplyDelete
  31. Thanks for your informative post!!! After completing my graduation, i am confused whether to choose web design as my career. Your article helped me to make a right choice. PHP Training Chennai

    ReplyDelete
  32. Haryana HSSC Steno Typist Recruitment 2016

    Many thanks for you post, this is good post i find for today............

    ReplyDelete
  33. Thanks for sharing informative article on wordpress. Being a most advanced CMS tool, wordpress help you to create sophisticated website with ease. Wordpress Training in Chennai

    ReplyDelete
  34. Nice information. I was searching for the same. It helped me alot and saved my time. Thanks alot. , windows azure training in hyderabad

    ReplyDelete
  35. I really enjoyed while reading your article, the information you have mentioned in this post was damn good. Keep sharing your blog with updated and useful information.
    Regards,
    SAS Training in Chennai|SAS Course in Chennai|SAS Institutes in Chennai

    ReplyDelete
  36. Really interesting content which is unique which provided me the required information.
    Dot Net Training in Chennai | .Net training in Chennai | FITA Training | FITA Velachery .

    ReplyDelete
  37. I really enjoyed while reading your article about authenticating mvc5 web users, the information you have delivered in this post was damn good. Keep sharing your post with efficient news.
    Regards,
    FITA Chennai complaints|Python Training in Chennai|SAS Training in Chennai

    ReplyDelete
  38. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Pega Training In Chennai

    ReplyDelete
  39. "We … are very happy with your editing. Your rewrite reduced the length and
    also improve clarity of the sentence. Most important, you kept the major...
    Dot net in chennai

    ReplyDelete
  40. nice ..
    Best SEO training in hyderabad all modules are clearly solved and practice with guide.seo training in hyderabadAnd clearly getting knowledge of seo.

    ReplyDelete
  41. Great post. I like your blog. Thanks for sharing such a useful post.

    Wordpress development services in chennai

    ReplyDelete
  42. Thanku for sharing about acess and authentuicate..
    Informatica training, in the recent times has acquired a wide scope of popularity amongst the youngsters at the forefront of their career.
    Informatica online training in hyderabad


    ReplyDelete
  43. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    salesforce training in chennai | salesforce training institute in chennai

    ReplyDelete
  44. Hi Dude,
    Awesome Post!!! With unique content, I really get interest to read this post. I hope this article help many of them who looking this pretty information.
    Regards,
    Salesforce Training Chennai|salesforce developer training in chennai

    ReplyDelete
  45. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Hadoop Training in Chennai | Hadoop Training Chennai

    ReplyDelete
  46. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    cloud computing training in chennai | cloud computing courses in chennai

    ReplyDelete
  47. 100% Job Oriented R Programming Training In Chennai for more Information click tothe best php training in chennaiphp training in chennai.

    ReplyDelete
  48. 100% Job Oriented R Programming Training In Chennai for more Information click tothe best cloud-computing training in chennaicloud-computing training in chennai.

    ReplyDelete
  49. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    Angularjs training in chennai | Angularjs course in Chennai

    ReplyDelete
  50. Updating with the latest technology and implementing it is the only way to survive in our niche. Thanks for making me this article. You have done a great job by sharing this content in here. Keep writing article like this.
    SAS Training in Chennai | SAS Training Institute in Chennai

    ReplyDelete
  51. best windows azure online training in hyderabad with work support and job assistance and high quality training facilities and well expert faculty
    to Register you free demo please visit
    windows azure training in hyderabad

    ReplyDelete
  52. This comment has been removed by the author.

    ReplyDelete
  53. A pioneer bridge the gap of 40 lakh job vacancies in the Hospitality sector. The Institute is contributing to the creation of knowledge and offer quality program to equip students with skills to face the global market concerted effort by dedicated faculties, providing best learning environment in fulfilling the ambition to become a Leading Institute in India.

    cha jaipur
    management college in jaipur
    management of hospitality administration jaipur
    cha management jaipur
    Hotel management in jaipur
    Best hotel college in jaipur
    Best management college in jaipur
    College of Hospitality Administration, Jaipur
    Top 10 hotel management in jaipur
    Hotel managementin Rajasthan




    A pioneer bridge the gap of 40 lakh job vacancies in the Hospitality sector. The Institute is contributing to the creation of knowledge and offer quality program to equip students with skills to face the global market concerted effort by dedicated faculties, providing best learning environment in fulfilling the ambition to become a Leading Institute in India.

    cha jaipur
    management college in jaipur
    management of hospitality administration jaipur
    cha management jaipur
    Hotel management in jaipur
    Best hotel college in jaipur
    Best management college in jaipur
    College of Hospitality Administration, Jaipur
    Top 10 hotel management in jaipur
    Hotel managementin Rajasthan




    ReplyDelete
  54. A Pioneer Institute owned by industry professionals to impart vibrant, innovative and global education in the field of Hospitality to bridge the gap of 40 lakh job vacancies in the Hospitality sector. The Institute is contributing to the creation of knowledge and offer quality program to equip students with skills to face the global market concerted effort by dedicated faculties, providing best learning environment in fulfilling the ambition to become a Leading Institute in India.

    cha jaipur
    hotel management college in jaipur
    management of hospitality administration jaipur
    cha management jaipur
    Hotel management in jaipur
    Best hotel management college in jaipur
    College of Hospitality Administration, Jaipur
    Top 10 hotel management in jaipur
    Hotel management collegein Rajasthan

    ReplyDelete
  55. android training in bangaloreAndroid tutorial or android development tutorial covers basic and advanced concepts of android technology. Our android tutorial is developed for beginners and professionals.

    ReplyDelete
  56. * Jual Obat Aborsi,,
    * Obat Aborsi,,
    * Obat Penggugur Kandungan,,
    * what I have read on this page is enough to make me satisfied can menik die this article thanks greetings *
    * Harga Obat Aborsi,,

    ReplyDelete



  57. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Power BI Online Training .

    ReplyDelete
  58. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating. Azure Online Training

    ReplyDelete