locked
Difference between RequireAuthenticatedUser and IsAuthenticated RRS feed

  • Question

  • User-1327394822 posted

    Is there any difference between these two methods...If yes, please explain.

    WebSecurity.RequireAuthenticatedUser();

    and

    WebSecurity.IsAuthenticated

    Sunday, December 6, 2015 3:43 PM

Answers

  • User-821857111 posted

    The first is a method whereas the second is a property. The first one is generally used as a barrier to prevent unauthorised any access to a page or group of pages if placed in a _PageStart or Layout file. If the current user is not authenticated, they will be redirected to the site's login page. The second is more useful as part of a conditional statement for managing inline rendering of content depending on whether the current user is authenticated. For example, your admin area's home page might have a menu and a login form. You only want to show the menu to an authenticated user, but you want to show the form to unauthenticated users:

    if(WebSecurity.IsAuthenticated)
    { 
        @RenderPage("_Menu.cshtml")
    }
    else
    {
        @RenderPage("_LoginForm.cshtml")
    )

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 7, 2015 7:49 AM