title: How to set Azure Authentication custom login return url?
body: <p>I followed this article <a href="https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/" rel="noreferrer">https://azure.microsoft.com/en-us/blog/announcing-app-service-authentication-authorization/</a> to set up Azure authentication for my MVC app. First I turned on Azure AD provider. In the Authentication / Authorization settings, I selected "Allow request(no Action)" for "Action to take when request is not authenticated" because I only need users to login for certain controller actions.</p>
  
  <p>Then I added a custom FilterAttribute to check if one action needs authentication as in <a href="https://stackoverflow.com/a/26652816/1837339">https://stackoverflow.com/a/26652816/1837339</a>. In the OnAuthenticationChallenge function, I had this code to redirect to login page:</p>
  
  <pre><code>public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
  {
      if (filterContext.Result is HttpUnauthorizedResult) {
          filterContext.Result = new RedirectResult("~/.auth/login/aad");
      }
  }
  </code></pre>
  
  <p>All of this works, except after user finished authentication, it is redirected back to mysite/.auth/login/done page saying "You have successfully signed in" and a button to return to my site's base url.</p>
  
  <p>What I want is the redirection goes back to the user's original url, so I think I need somehow set the return url for the login redirect. But I couldn't find any documentation about this. Anyone could give any advice?</p>