According to MSDN the class Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase, Microsoft.SharePoint should be used to give anonymous users access to page. However despite in inheriting from the class you might still get a 401 Unauthorised error. Not only do you need to inherit from this class but you also need to override the AllowAnnoymouseAccess property and set it to return true:
public class Login: Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase{
protected override bool AllowAnnonymouseAccess{
get{
return true;
}
}
}
I am not sure why this class needs this additional property but once added it worked fine.