Help needed for App_Code\MembershipUser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sacha4
    New Member
    • Sep 2007
    • 11

    Help needed for App_Code\MembershipUser

    I have created an administrator page which further creates an office administrators and users. The office aministrator can create users too, but they cannot see all the offices.What code should I write so that when an office administrator creates an user, that user is automatically from his office?The code is in vb.net
    need help urgently....Tha nks in advance

    Sacha4
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by sacha4
    I have created an administrator page which further creates an office administrators and users. The office aministrator can create users too, but they cannot see all the offices.What code should I write so that when an office administrator creates an user, that user is automatically from his office?The code is in vb.net
    need help urgently....Tha nks in advance

    Sacha4

    What have you tried so far?

    -Frinny

    Comment

    • sacha4
      New Member
      • Sep 2007
      • 11

      #3
      [code=vbnet]
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
      ClientScript.Re gisterClientScr iptInclude("lay outjs", "_js/layout.js")

      If User.Identity.I sAuthenticated = False Then
      Response.Redire ct("loginName.a spx?ReturnURL=" + HttpContext.Cur rent.Request.Ur l.ToString())
      End If

      If (Not User.IsInRole(" 100")) AndAlso (Not User.IsInRole(" 1")) Then
      Response.Redire ct("loginName.a spx?ReturnURL=" + HttpContext.Cur rent.Request.Ur l.ToString())
      End If
      'If (Not Profile.UserNam e.Equals("temp" )) AndAlso (Not Profile.UserNam e.Equals("sacha 4")) AndAlso (Not Profile.UserNam e.Equals("coor" )) Then
      ' ' Response.Redire ct("loginName.a spx?ReturnURL=" + HttpContext.Cur rent.Request.Ur l.ToString())
      'End If
      ' Grab first username and load roles below
      If Not IsPostBack Then
      FindFirstUserNa me()
      End If

      If (Not User.IsInRole(" 1")) Then
      office.Visible = False
      End If
      If (User.IsInRole( "100")) Then
      Session("LoginV alid") = Profile.Office. ToString()
      End If

      End Sub

      [/code]
      This is wat i have tried till. IsInRole(1 ) stands for administrator and 100 for office administrator..
      Last edited by Frinavale; Oct 31 '07, 06:11 PM. Reason: Added [code] tags to make more legible

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by sacha4
        [code=vbnet]
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        ClientScript.Re gisterClientScr iptInclude("lay outjs", "_js/layout.js")

        If User.Identity.I sAuthenticated = False Then
        Response.Redire ct("loginName.a spx?ReturnURL=" + HttpContext.Cur rent.Request.Ur l.ToString())
        End If

        If (Not User.IsInRole(" 100")) AndAlso (Not User.IsInRole(" 1")) Then
        Response.Redire ct("loginName.a spx?ReturnURL=" + HttpContext.Cur rent.Request.Ur l.ToString())
        End If
        'If (Not Profile.UserNam e.Equals("temp" )) AndAlso (Not Profile.UserNam e.Equals("sacha 4")) AndAlso (Not Profile.UserNam e.Equals("coor" )) Then
        ' ' Response.Redire ct("loginName.a spx?ReturnURL=" + HttpContext.Cur rent.Request.Ur l.ToString())
        'End If
        ' Grab first username and load roles below
        If Not IsPostBack Then
        FindFirstUserNa me()
        End If

        If (Not User.IsInRole(" 1")) Then
        office.Visible = False
        End If
        If (User.IsInRole( "100")) Then
        Session("LoginV alid") = Profile.Office. ToString()
        End If

        End Sub

        [/code]
        This is wat i have tried till. IsInRole(1 ) stands for administrator and 100 for office administrator..
        On Line 8 of the above code...you're IF statement is incorrect.
        It should be an OR not and AND.
        I think this'll fix your problem :)

        Cheers!
        -Frinny

        Comment

        Working...