.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Check membership roles

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
Hello All, I have the following, for an webapplication I user membership roles. Users are added or removed from a role. I have two things i am wondering how to accomplish.   The first: New or exisiting users have assigned roles for their accounts. This roles can be selected or deselected from a checkbox (when the users is created or edited) . I want to build some routine or function to see if a users is part of a role or if he is assigned a new role. When, in edit mode, a users is part of a role the particular checkbox has to be checked, or if he isn't unchecked. Of course I want to call a function to do that so I don;t have to write the if then statement for all roles, but just one time. I think this should be a public function to call from all pages within the appication, but whatever i try, it doesnt work.  I have written a function in a apart classfile called functions.vb. But the roles syntax isn't recognized. Herby the function{Public Function CheckMembership(ByVal GroupName As Boolean, ByVal User As String, ByVal Group As String) As Integer If GroupName = True Then If Not Roles.IsUserInRole(User, Group) Then Roles.AddUserToRole(User, Group) ElseIf GroupName = False Then If Roles.IsUserInRole(User, Group) Then Roles.RemoveUserFromRole(User, Group)

View Complete Post

More Related Resource Links

FileUpload Control with membership and roles


Hi Everyone!

I'm pretty new to development using Microsoft technologies.

I'm trying to build a portal kind of an application in asp.net, in which one of the functionality is letting people log in and upload their documents. The upload page is only accessible to registered users of the portal.


I would like to track the user uploaded files according to their userIds.

Is it possible to use the FileUpload Control and C# to fetch the current user id, create a directory with the same name(as that of userID) in the file system and upload the files( multiple file upload, if necessary) into it?

Also another admin page would have to be able to see the list of files uploaded by the specific user and download it if necessary.

Could anyone help me with this?

I'm also expecting alternate solutions to the problem.

Awaiting a response.

Thanks in advance 


Multiple groups of roles in membership

Hi,I am developing this website which requires multiple groups of roles inside membership.Here is an example:I want to create a group of states (would be the first group of roles):* Oregon* California* Kansas* Texas* OhioAnd then a second group of profiles:* Admin* Section 1* Section 2* Section 3Then I want to comine these groups, so for example:* Patrick has Oregon and Section 1 role, so he can only access the state of Oregon and Section 1 module on the website.* Laura has Kansas and Section 2 role, so she can only access the state of Kansas and Section 2 module on the website.* John has Ohio, Texas and Admin and Section 1 roles, so he can only....Do you understand what I mean? How can I achieve this with .net memberhip?

how to customize asp.net membership roles to create separate member area ?


I am using asp.net membership for all the users and roles, right now i have a website on which i have created 2 roles "admin" and "member"

in this website i create accounts, so all the accounts are separated/distinguished by account name

now i was to add one more role "accountholders" and i want to add this role in such a way that an account holder will be able to see his / her account's stuff ...

i as admin will be creating username and password for accountholders and i will provide them their login credentials so that they can login and see what's in their account.

My idea of creating account is that, the accounts that i have in my database will be the key, so when i will create username for particular account , in the create user wizard i should have a drop downmenu will all the accounts name. so the user that i am creating will be linked on that account only ..

how to accoplish this ? please guide me in a right direction...

profiles, membership and roles


Dear All,

Can someone help me with creating a custom profile, membership and role page something like this:


I'm trying to edit this as my requirment but I can't make it work. I will just need to add detailview to view the entire profile since it's to long for the gridview to handle.

I need to display the gridview custom data then by selecting the select, it will be displayed on the detailview to edit and delete. In create user, need to add my data requirement by making a createwizard page on the left table same as the link. 

Check User Roles (more than 50)


I have more than 100 roles defined for my app. Now I have a page which is allowed for around 50 roles,
so when user comes to page instead of writing too many if else conditions, what is the best & efficient way
to check the if user in any of those 50 roles?


I have more than 100 roles defi

IIdentity, IPrincipal, membership and roles provider



How I must use this? I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize. 

I can implement custom MembershipUser, custom Roles and Membership provider. 

IIdentity, IPrincipal, membership and roles provider



How I must use this? I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize. 

I can implement custom MembershipUser, custom Roles and Membership provider. 

How to do it? What best practices are?

Best regards,

Peshkov Evgeniy.

Do Membership Roles work with custom connection string?


Hi all, plz help with one issue.
I have Membership configured with IIS7, tables for it located in my own database, created with aspnet_regsql utility, and I am using custom connection string to access it.

This is part of web.config related to Membership :

        <add connectionString="Server=CORESERVER\SQLExpress;Database=Shop;User ID=Tema;Password=Matrix" name="CustomSqlConnection" />
    <profile enabled="true">
            <add name="CustomSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="CustomSqlConnection" />
    <roleManager defaultProvider="AspNetSqlRoleProvider" enabled="true">
            <add name="CustomSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="CustomSqlConnection" />
    <membership defaultProvider="CustomSqlMemberPr

How to use ASP.NET's Membership, Roles etc. in asp.net 4.0?


Good morning everybody.

I want to practise ASP.NET Authentication, and Authorization features in Visual Studio 2010.

I wanted to store user account information NOT IN THE aspnet db, but in a SEPARATE database. Hence, I have tried to use aspnet_regiis tool at visual studio command prompt. I am not presenting with wizard type window. Without wizard, I don't know how to store user information in a separate database otherthan aspnet db.

Can anybody please suggest any solution for this.

Also, one more thing:

It looks like lot of features have been changed in Visual Studio 2010 to work with Forms Authentication. If it is really changed, can anybody please suggest me the better resources to learn on the web?

Thansk in advance,
Ashok kumar.

Roles.GetAllRoles() And Membership.GetAllUsers() Not Working.


Hello Forum,


I have been attempting to load my users and roles into a couple of listboxes but for some reason the listboxes are showing up empty.  What am I doing wrong?


<%@ Page Language="VB" MasterPageFile="~/PEPMasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script runat="server">

Dim rolesArray() As String
Dim users As MembershipUserCollection

    Public Sub Page_Load()

        Msg.Text = ""

        If Not IsPostBack Then
            ' Bind roles to ListBox.

            rolesArray = Roles.GetAllRoles()
            RolesListBox.DataSource = rolesArray

            ' Bind users to ListBox.

            users = Membership.GetAllUsers()
            UsersListBox.DataSource = users
        End If
    End Sub

Public Sub AddUser_OnClick(sender As Object, args As EventArgs)


Membership and roles in ASP.net 3.5



I would like to know about roles in asp.net.Actually I am using VS2008 and SQL Server 2008.

Here I have to implement admin,L1,L2,Employee roles and their access assign by admin.

Here all machines are in network.I have also limited access.

I want to implement roles only for stand alone PC. Please advice the better way.


Help in Membership schema and roles


hi all,

i am making a website when i m almost 25% my manager told me to add roles and stuff...my problem is how to make roles in nested manner.

my website has Admin and users(admin, area manager, site manager, user) and then on the default page i need to disable enable buttons according to companies e.g starbucks should not access accident modules etc etc

so i am really confused how to make roles in nested manner. any assistance is welcome

thanks in advance

WCF and ASP.Net Membership, Roles and Profile



I have a client asp.net website that uses  ASP.Net Membership, Roles and Profile providers and Login controls.

I need to expand the application so was going to use WCF Workflows, the ASP.Net website will be hosted on a different server than the WCF Services so what I want to do is get the ASP.Net Website to auth via the WCF Service.

So process will go:

ASP.Net Website ------------------> WCF Service ------------------> SQL Database (Membership, Roles, Profile, Workflow Persistence Data and Business Data)

I tried creating a custom Membership and Role providers but I have had problems managing the users (Membershipuser class) saying null when a vaild user has been return by the WCF Service as can access the properies but not the methods.

Am I doing this the right way or is there other built in classes that I have missed?


Check the if SSAS Roles property is used in excel connection string before returning the values



We are using Excel 2007 to connect to SSAS cubes. We have many roles for a user and all having different permission including different VISUAL TOTAL setting. We want to restrict the user so that he cannot see anything if he is not using the ROLES property in the excel connection string.

At the run time I want to know if the user who is using excel has used ROLES property or not.

Any help will be appreciated

Mr myName

New to MemberShip and Roles


Hello all professionals !  My Problem is different. I want to implement the roles and membership feature in my website. The problem is that i want to use it in my own way. I dont want any kind of security question and answer and the password and user ID is also generated automatically in my website registration form according to client need. but the problem i am facing is i dont know how to implement membership and roles feature on remote sql server database. i have a connectionstring written in web config. I dont want to use the default databse automatically generated by visual studio. I want to use the Database designed by me. it has its own columns and properties. I want to customize create user vizard also. I am using roles and membership only because i provide more efficient way to handle bulk coding. 

 What i want to do is just store registration information in remote databse using create user wizard and through membership. and also create user wizard will be customized.


Any Help would be apppreciable. PLZZZZ

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend