+1-888-365-2779
Try Now
More in this section

Forums / Security / Set Current User to Logged In

Set Current User to Logged In

6 posts, 0 answered
  1. James Salisbury
    James Salisbury avatar
    1 posts
    Registered:
    08 Jul 2009
    29 Oct 2009
    Link to this post
    Hi All,

    How do i programaticly set the current user to logged in?

    I have my own login functionality controlling access to the site.

    I am using the deny=true on a page property to control access.

    Cheers,
    James


  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    29 Oct 2009
    Link to this post
    Hi James Salisbury,

    Thank you for contacting Telerik Support.

    Consider the following logic for setting an authentication cookie to authenticate the user, give that we know the username and password:
    Telerik.Security.UserManager userManager = new Telerik.Security.UserManager(System.Web.Security.Membership.Provider.Name);
    if(userManager.ValidateUser(username,passowrd)
    {
            FormsAuthentication.SetAuthCookie(username, true);
            var aCookie = FormsAuthentication.GetAuthCookie(userusername, true);
            userManager.SetAuthenticationCookie(aCookie);
    }

    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Anshu Nigam
    Anshu Nigam avatar
    5 posts
    Registered:
    13 Mar 2010
    14 Mar 2010
    Link to this post
    Hi All,

    I want to restrict all anonymous users so I've made following changes at Web.Config
      <authentication mode="Forms">
        <forms loginUrl="MyLogon.aspx" protection="All" timeout="60" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
      </authentication>
        <authorization>
        <deny users="?" />
      </authorization>

    I've created physical file MyLogon.aspx which set FormsAuthentication.SetAuthCookie(user,false) when certain condition met.
    it look like it is working fine, do you see any issue with this approach?

    Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Mar 2010
    Link to this post
    Hi Anshu Nigam,

    Generally  this will work for physical files, but Sitefinity pages are stored in the database. Also the setting you have made restrict the access to all resources as well. So you should consider whether this will not cause some further problems.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Anshu Nigam
    Anshu Nigam avatar
    5 posts
    Registered:
    13 Mar 2010
    15 Mar 2010
    Link to this post
    Thanks!  I need to restrict all anonymous users from my site only authenticated user should get access. There won't be any login page page on my site for authentication; Mylogin.aspx accept QueryString parameters from other site via http redirect then based on parameter value access allow/deny will be decided.  What is the best recommended method to set authentication ticket. Pls advise.

    Thanks
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Mar 2010
    Link to this post
    Hello Anshu Nigam,

    Thanks!  I need to restrict all anonymous users from my site only authenticated user should get access.

    You can set Anonymous Access to "Deny" from page Properties tab. This will allow you to control the access from the UI instead using the web.config file. Then you can read the QueryStirng and authenticate the user. Note that you should pass the username and password.

    sample code

    if (Request.QueryString.Count > 0)
     {
         string qs = Request.QueryString[0];
         string ps = Request.QueryString[1];
         if (!String.IsNullOrEmpty(qs) && !String.IsNullOrEmpty(ps) && ps == "someuser" && qs == "somepassword")
        {
             MembershipUser user = Membership.GetUser(qs);
             if (user != null)
             {
                 FormsAuthentication.SetAuthCookie(user.UserName, true);
                 HttpCookie c = FormsAuthentication.GetAuthCookie(user.UserName, true);
                 UserManager.Default.SetAuthenticationCookie(c);
                 Response.Redirect("~/Sitefinity/Admin/Default.aspx");
             }
         }
     }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
6 posts, 0 answered