Recently when developing a custom sign in page I was encountering an “401 Unauthorized” error.
The cause of this error was that my application page was inherited from LayoutsPageBase.
In order to fix this I changed the application page to inherit from System.Web.UI.Page.
Throws 401 Unauthorized
public partial class Login : LayoutsPageBase
Resolution
public partial class Login : System.Web.UI.Page