This project has moved and is read-only. For the latest updates, please go here.

understanding the code (redirection)

Jan 9, 2011 at 12:52 PM


I was today going through the code and trying to understand it.

/// <summary>        /// This is a hook where you can assign        /// a lambda to perform the technology        /// specific redirection action.        ///         /// The string passed as the lambda paramter        /// is the Twitter authorization URL.        /// </summary>      

 public Action<string> PerformRedirect { get; set; }

 /// <summary>        /// First part of the authorization sequence that:        /// 1. Obtains a request token and then        /// 2. Redirects to the Twitter authorization page        /// </summary>        /// <param name="callback">This is where you want Twitter to redirect to after authorization</param>    

   public void BeginAuthorization(Uri callback)      

  {            if (IsAuthorized) return;
             string callbackStr = OAuthTwitter.FilterRequestParameters(callback);          

 string link = OAuthTwitter.AuthorizationLinkGet(OAuthRequestTokenUrl, OAuthAuthorizeUrl, callbackStr, readOnly: false, forceLogin: false);


And Finally:

 public class MvcOAuthActionResult : ActionResult 


     private WebAuthorizer m_webAuth;
        public MvcOAuthActionResult(WebAuthorizer webAuth) 


       m_webAuth = webAuth;    

        public override void ExecuteResult(ControllerContext context)    


     m_webAuth.PerformRedirect = authUrl =>    

       {                HttpContext.Current.Response.Redirect(authUrl);    





I believe this is where you are redirecting to twitter.

Could you please explain the performredirect code.

Thanks and best regards


Jan 9, 2011 at 6:42 PM

Hi Arnab,

You're right, PerformRedirect is where the redirect to Twitter for authorization occurs.  The design allows a user to specify their own redirection logic.  In most cases, the Response.Redirect is appropriate, but I didn't want to make the assumption for the user.  Also, for the benefit of reuse, MvcOauthAuthorizer derives from WebAuthorizer.  The consequence is that the redirection occurs in different places in the code.  The WebForms page would do the redirect as a lambda in the code behind, but the MVC app would do the redirect, as you've shown, in a custom ActionResult.