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

Forums / Bugs & Issues / Bypass login with valid IP address

Bypass login with valid IP address

4 posts, 0 answered
  1. nick
    nick avatar
    1 posts
    Registered:
    25 Mar 2011
    29 Mar 2011
    Link to this post
    Hi there:

    How can I bypass the login page for some internal users who have certain fixed IP? For other users, they have to sign in? I am totally new to sitefinity. I can't find login.aspx in my project. I have tested the following code. It works. I need to know where I can plug in the code. Please help.

    Protected
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
     
    Dim strClientIP As String
    Dim IPArray() As String
    Dim matching As Boolean
    matching =
    False
    Dim ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If (IsNothing(ip)) Then ip = Request.ServerVariables("REMOTE_ADDR")
    IPArray() = Split(ip,
    ".")
    If IPArray(0) = "???" And IPArray(1) = "???" And IPArray(2) = "???" Then matching = True
    If matching Then
    Response.Write(ip +
    "</BR>")
    Response.Write(
    "Bypass the login")
    Else
    Response.Write(ip +
    "</BR>")
    Response.Write(
    "Need Login")
    End If
    End Sub


    Best regards,

    Nick
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    31 Mar 2011
    Link to this post
    Hello nick,

    This post shows how to authenticate a user

    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/creating-and-publishing-genericcontent-using-api.aspx

    Greetings,
    Ivan Dimitrov
    the Telerik team
  3. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    24 Jun 2011
    Link to this post
    Thanks for the link to the other post. I've got things working to bypass the login screen but I'm getting stuck on what I think is a very trivial thing. In this bit of code you are passing a hard coded username, "admin". I want to pass a variable instead, such as a querystring. I can't seem to figure out how to get that in there without generating an error.

    MembershipUser user = UserManager.Default.MembershipProvider.GetUser("admin", false);
    FormsAuthentication.SetAuthCookie(user.UserName, true);
    var authCookie = FormsAuthentication.GetAuthCookie(user.UserName, true);
    var ticket = FormsAuthentication.Decrypt(authCookie.Value);
    var identity = new FormsIdentity(ticket);
    Context.User = new RolePrincipal(identity);
    UserManager.Default.SetAuthenticationCookie(authCookie);

    I tried things such as:

    string passeduser = Request.QueryString["PassedUserName"];
    MembershipUser user = UserManager.Default.MembershipProvider.GetUser(passeduser, false);

    but that generates System.NullReferenceException: Object reference not set to an instance of an object.

    Any tips? Thanks!
  4. Cameron
    Cameron avatar
    42 posts
    Registered:
    27 Jul 2009
    24 Jun 2011
    Link to this post
    D'oh! I got it. I knew it was something stupid. I got so stuck on the harder parts, I missed the simple one. I was checking for a QueryString instead of a Form variable. Amazing how the simple post vs get tripped me up! Thanks!
Register for webinar
4 posts, 0 answered