How to redirect the user to the default ACS login page

I am using azure Access Control System (ACS)

in my web application to authenticate users from different identity providers. I have successfully registered my application to use ACS. Now I removed full website protection with ACS by removing the following content from the web.config file:

<authorization>
  <deny users="?" />
</authorization>

      

After deleting this user, my users can access my site home page without logging in. Now on my home page I have set a link SignIn

. I want to know how can I redirect my users to the default ACS login page when the user clicks on the SignIn link? (similarly when the asp.net app redirects the user to the ACS login page if the user is not authenticated and tries to access the controller which is decorated with the Authorize attribute)

+3


source to share


4 answers


You can manually create the url using the SignInRequestMessage class or call



FederatedAuthentication.WSFederationAuthenticationModule.RedirectToIdentityProvider () (IIRC).

+1


source


Also, I believe WIF includes a control that will display this login link



0


source


This is how I did it in my MVC application.

Allow users to access all unsecured pages with this declaration in web.cofig:

<location path="FederationMetadata">
<system.web>
  <authorization>
    <allow users="*" />
  </authorization>
</system.web>

      

Use the RequireHttps attribute for my login method:

[HttpGet]
[RequireHttps]
public ActionResult LogOn(string returnUrl)
{
     if (string.IsNullOrWhiteSpace(returnUrl))
       returnUrl = "/reports";

     return LogOnCommon(returnUrl);
}

      

and use the web.config authentication section where my login page is:

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="~/account/logon" timeout="2880" />
  </authentication>
</system.web>

      

0


source


The following code will redirect you to the federated account login page:

public class AccountController : Controller
{
    public ActionResult SignIn(string returnUrl)
    {
        if (String.IsNullOrEmpty(returnUrl))
        {
            returnUrl = Url.Content("~/");
        }

        var signInRequest = FederatedAuthentication.WSFederationAuthenticationModule.CreateSignInRequest(
            "passive",
            returnUrl,
            FederatedAuthentication.WSFederationAuthenticationModule.PersistentCookiesOnPassiveRedirects);

        return Redirect(signInRequest.RequestUrl);            
    }

    // SignOut, SignOutCallback below from typical MVC template
}

      

0


source







All Articles