开发者

Handling Authentication for users in Sitecore 5.3.1

In Sitecore 6+ I can use the following code to check wheter a user has been logged in:

   string logonUser = base.Request.ServerVariables["LOGON_USER"];

   // check of de gebuiker geautenticeerd is (bijv. door in een andere browser venster in het beheer in te loggen.)
   if (Sitecore.Context.User.IsAuthenticated)
   {
      Response.Redirect("/", true);
   }

In Sitecore 5.3.1. on which one of our customers is running I want to implement similar functionality. I want to determine wheter a user has entered valid credentials and then l开发者_如何转开发og that user to the system. After that I want to be able to determine if this user is logged in by checking the Session vars on each return to the website. I can't find the method to use to do this. Any bright ideas?


I would encourage you to browse Sitecore.SecurityModel namespace, especially Domain class. It contains the methods you'd probably find useful (IsLoggedIn, Login, Logout). You can download the help file of Sitecore API from here.

Also, Sitecore security model is based on ASP.NET security starting from version 6. In 5.x a user is still an item in the appropriate database. Hope this info can help you.


I think something like this should work:

if (Sitecore.Context.IsLoggedIn) {

} else {
  Response.Redirect("http://" + Request.Url.Host + "/sitecore/login");
}


Hm.. I think as long as a user can be found in the current context, you can assume the user is logged ind.

so

Sitecore.Context.User != null

is probably enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜