Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ${aspnet-user-isAuthenticated} #135

Closed
1 task done
304NotModified opened this issue May 7, 2017 · 3 comments · Fixed by #143
Closed
1 task done

add ${aspnet-user-isAuthenticated} #135

304NotModified opened this issue May 7, 2017 · 3 comments · Fixed by #143
Labels
ASP.NET Core ASP.NET Core - all versions feature

Comments

@304NotModified
Copy link
Member

304NotModified commented May 7, 2017

[LayoutRenderer("aspnet-user-isAuthenticated")]
 public class IsAuthenticatedLayoutRenderer : AspNetLayoutRendererBase
 {
    protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
    {
         var httpContext = HttpContextAccessor.HttpContext;
         if (httpContext == null)
         {
               return;
          }

        if (httpContext.User?.Identity?.IsAuthenticated)
        {
            builder.Append(1);
        }
        else
        {
            builder.Append(0);
        }
    }
}

todo

  • non-core support
@snakefoot
Copy link
Contributor

Not missing null-check of HttpContext like in #136? Also what if HttpContextAccessor returns null?

@304NotModified
Copy link
Member Author

sharp @snakefoot ! Updated it.

@304NotModified
Copy link
Member Author

304NotModified commented May 14, 2017

@snakefoot snakefoot added ASP.NET Core ASP.NET Core - all versions and removed ASP.NET Core 1 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASP.NET Core ASP.NET Core - all versions feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants