asp.net mvc - Redirecting Users from Unauthorized Page -


i have mvc application converted authentication/authorization method forms federated. works fine, on home page have create cookie authorization of rest of site work properly. when users navigate home page first works great, if navigate different page first authorization required 401 unauthorized error page.

when had forms authentication implemented redirect users unauthorized login page, federation no longer have login page redirect home page. forms authentication redirection automatic, how setup similar federated application?

here federated portions of web.config relevant. again, federated authentication/authorization works, unauthorized redirect isn't.

  <system.web>     <customerrors mode="off"/>     <authentication mode="none"/>     <authorization>       <deny users="?"/>     </authorization>      <membership defaultprovider="admembershipprovider">       <providers>         <add name="admembershipprovider" type="system.web.security.activedirectorymembershipprovider" connectionprotection="secure" attributemapusername="samaccountname" connectionstringname="adconn" connectionusername="uname" connectionpassword="pass" />       </providers>     </membership>     <rolemanager enabled="true" defaultprovider="activedirectoryroleprovider" cacherolesincookie="true" cookiename=".adlibraryroles" cookiepath="/" cookietimeout="1440" cookierequiressl="false" cookieslidingexpiration="true" createpersistentcookie="true" cookieprotection="all">       <providers>         <clear />         <add name="activedirectoryroleprovider" connectionstringname="adconn" connectionusername="uname" connectionpassword="pass" attributemapusername="samaccountname" type="myapp.activedirectoryroleprovider" />       </providers>     </rolemanager>   </system.web>   <system.webserver>       <modules>         <add name="wsfederationauthenticationmodule" type="system.identitymodel.services.wsfederationauthenticationmodule, system.identitymodel.services, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" precondition="managedhandler"/>         <add name="sessionauthenticationmodule" type="system.identitymodel.services.sessionauthenticationmodule, system.identitymodel.services, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" precondition="managedhandler"/>       </modules>   </system.webserver>   <system.identitymodel>     <identityconfiguration>       <audienceuris>         <add value="https://fed.example.com/"/>       </audienceuris>       <securitytokenhandlers>         <add type="system.identitymodel.services.tokens.machinekeysessionsecuritytokenhandler, system.identitymodel.services, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/>         <remove type="system.identitymodel.tokens.sessionsecuritytokenhandler, system.identitymodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089"/>       </securitytokenhandlers>       <certificatevalidation certificatevalidationmode="none"/>       <issuernameregistry type="system.identitymodel.tokens.validatingissuernameregistry, system.identitymodel.tokens.validatingissuernameregistry">         <authority name="http://myfedservice.example.com/adfs/services/trust">           <keys>             <add thumbprint="mythumb"/>           </keys>           <validissuers>             <add name="http://fed.example.com/adfs/services/trust"/>           </validissuers>         </authority>       </issuernameregistry>     </identityconfiguration>   </system.identitymodel>   <system.identitymodel.services>     <federationconfiguration>       <cookiehandler requiressl="true"/>       <wsfederation passiveredirectenabled="true" issuer="https://fed.example.com/adfs/ls/" realm="https://fed.example.com/" reply="https://fed.example.com/" requirehttps="true" persistentcookiesonpassiveredirects="true"/>     </federationconfiguration>   </system.identitymodel.services> 

you can configure in wsfederation section, see msdn further details. setting “passiveredirectenabled” true, wsfederationauthenticationmodule @ outgoing responses, trying find http 401s. if finds 401, modify response , turn redirect sts. please note in production want change requirehttps true.

<system.identitymodel.services> <federationconfiguration>   <wsfederation passiveredirectenabled="true"      issuer="http://localhost:15839/wsfederationsts/issue"      realm="http://localhost:50969/" reply="http://localhost:50969/"      requirehttps="false"      signoutreply="http://localhost:50969/signedoutpage.html"      signoutquerystring="param1=value2&amp;param2=value2"      persistentcookiesonpassiveredirects="true" />   <cookiehandler requiressl="false" /> </federationconfiguration> 

please note need add these modules:

<modules>   <add name="wsfederationauthenticationmodule" type="system.identitymodel.services.wsfederationauthenticationmodule, system.identitymodel.services, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" precondition="managedhandler" />   <add name="sessionauthenticationmodule" type="system.identitymodel.services.sessionauthenticationmodule, system.identitymodel.services, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" precondition="managedhandler" /> </modules> 

and following config sections:

<configsections> <!-- more information on entity framework configuration, visit http://go.microsoft.com/fwlink/?linkid=237468 --> <section name="system.identitymodel" type="system.identitymodel.configuration.systemidentitymodelsection, system.identitymodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" /> <section name="system.identitymodel.services" type="system.identitymodel.services.configuration.systemidentitymodelservicessection, system.identitymodel.services, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" /> 


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -