Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ACS installed but MVC 4.0 app still redirects and fails to find login.aspx

Tags:

First post here on stackoverflow but I love the site!...

I've successfully created a fully functioning Azure hybrid model application using MVC 4. Published and works great. Now I want to add ACS for auth to my site. I've followed all the steps but when I run the app in simulation it fails to re-direct to ACS and offers up the page stating that it couldn't find login.aspx.

I have created a simple website solution just to prove that my ACS is setup correctly and it works just fine. I noticed that the web.config files of the two solutions were wildly different.

Anyone tried to do this yet? Any help would be appreciated.

--------- Solution -----------

I finally got everything to work. The key was to remove the WebMatrix.WebData references since I didn't need to do my own auth. The following came from MVC4 Release notes.

When WebMatrix.WebData.dll is included in in the /bin directory of an ASP.NET MVC 4 apps, it takes over the URL for forms authentication. Adding the WebMatrix.WebData.dll assembly to your application (for example, by selecting "ASP.NET Web Pages with Razor Syntax" when using the Add Deployable Dependencies dialog) will override the authentication login redirect to /account/logon rather than /account/login as expected by the default ASP.NET MVC Account Controller.

like image 947
barnesbuilt Avatar asked Apr 23 '12 17:04

barnesbuilt


1 Answers

Open your web.config file.

Locate the Authentication node.

Change it from:

<authentication mode="Forms" /> 

To:

<authentication mode="None" /> 

Comment here, if it doesn't help, and what is the result after changes to web.config.

As a side question - how did you add reference to the ACS namespace - via "right click -> Add STS Reference", or manually changed the web.config ?

Make sure that the required Modules are registered with the web server:

  <system.webServer>     <modules runAllManagedModulesForAllRequests="true">       <add name="ClaimsPrincipalHttpModule" type="Microsoft.IdentityModel.Web.ClaimsPrincipalHttpModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />       <add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />       <add name="SessionAuthenticationModule" type="Microsoft.IdentityModel.Web.SessionAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />     </modules>    ...  </system.webServer> 

Also make sure that you have microsoft.identityModel section, and you have federatedAuthentcation node within it:

<federatedAuthentication>         <wsFederation passiveRedirectEnabled="true" issuer="https://[your_namespace].accesscontrol.windows.net/v2/wsfederation"                        realm="http://127.0.0.1:81/" requireHttps="false" />         <cookieHandler requireSsl="false" /> </federatedAuthentication> 

Where "realm" shall be valid URL for Realying Party Application. And requireHttps="false" is to simplify development process.

When you debug it locally, make sure you are running the Cloud project (which uses IIS), and not the Web Project (which will use Cassini / webdevserver, which does not understand the system.webServer section!)

like image 51
astaykov Avatar answered Jan 06 '23 16:01

astaykov