how can i force the visitor to login (page)

Topics: Administration, General
Sep 23, 2012 at 3:27 PM

as skywalker 's artical:


var currentUser = _authenticationService.GetAuthenticatedUser();
if (currentUser == null) throw new OrchardSecurityException(T("Login required"));

The first thing we do is get the currently signedin user via the IAuthenticationService. If it returns null, it means there is currently no user signed in. If that's the case, we'll throw an OrchardSecurityException, which will be handled by Orchard by redirecting the user to the login page.


but it seems it does not work.

it gave me "OrchardSecurityException was unhandled by user code",  after i pressed F5 , it then went to login page.

Sep 23, 2012 at 5:17 PM


use this

if (currentUser == null)
                return new HttpUnauthorizedResult();
Sep 25, 2012 at 12:33 AM

You can also remove the ViewPErmission from Anonymous role.