C# - GetRolesForUser Tries To Get Roles On Old Username?

Mar 24, 2010

I have a section on a page where a user can change their username. This is basically the code for that:

user.UserName = txtNewUserName.Text;
user.Save();

user is a class in my dbml and Save calls SubmitChanges on the data context.The name is changed in the database, so when it calls the following method, it fails because it is trying to get the user with the old username instead of the one that is in the database now.

public override string[] GetRolesForUser(string username)
{
return dc.Users.Where(u => u.UserName== username)
.SingleOrDefault().Roles
.Select(r => r.RoleName).ToArray<string>();
}

View 1 Replies


Similar Messages:

Security :: Roles.GetRolesForUser(UserName) Not Working?

Oct 26, 2010

Roles.GetRolesForUser(UserName) .I have follwing codes in my Web.config,

<authentication mode="Forms">
<forms slidingExpiration="true" defaultUrl="admin/Welcome.aspx" timeout="60"/> </authentication>
<roleManager enabled="true" defaultProvider="SecurityTutorialsSqlRoleProvider">
<providers>
<add name="SecurityTutorialsSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" applicationName="SecurityTutorials" connectionStringName="SecurityTutorialsConnectionString"/>
</providers>
</roleManager>

View 2 Replies

C# - Roles.GetRolesForUser(); Returns Blank?

Dec 18, 2010

using asp.net membership api when I call Roles.GetRolesForUser(); it returns nothing. When I make a call Roles.GetAllRoles() all the roles are returned. What is the problem? Also what is the correct way to authenticate users using the membership api?

View 2 Replies

Security :: Accessing Username / Password / Roles In Xml File

Aug 26, 2010

Currently I am storing my username and password (passwordFormat="SHA1") credientails in my web.config. I would like to figure out how to access them in an xml file that I have stored in my App_Data directory rather than the web.config file because I do not want my application restarting everytime I manually add a user (small list of 5 authorized users for the CMS section).

Here is what my web.config section looks like:

<authentication mode="Forms">
<forms name=".Administration"
loginUrl="~/SiteAdmin/Default.aspx"
defaultUrl="~/SiteAdmin/Administration/Default.aspx"
protection="All"
timeout="30"
path="/"
requireSSL="false"
slidingExpiration="true"
enableCrossAppRedirects="false"
cookieless="UseDeviceProfile"
domain="">
<credentials passwordFormat="SHA1">
<user name="username" password="474BA67XXXXXX3B36DFD8A7BED6C85B04943" />
</credentials>
</forms>
</authentication>

View 1 Replies

Security :: Roles.AddUserToRole((sender As CreateUserWizard).UserName "Customers"); Not Active

Feb 8, 2010

Do you know where could come from my issue. In deed every time i create an user "customers" I always have to active it in asp.net configuration.

View 2 Replies

Extending RoleProvider GetRolesForUser ()

Jun 3, 2010

The GetRolesForUser() method in the RoleProvider takes the user login name and returns the list of roles for that user. But in my application this is not enough, I need a few more pieces of information to be able to get the user's roles. How can I get this extra information into the method? I have it in the Session, but I found out that Session is not available in the RoleProvider.

What I had in mind was putting this extra info in some class that extends MembershipUser, assuming I can get to it inside the RoleProvider. But I don't know how to create the CustomMembershipUser and make it part of the MembershipProvider. Is this even possible? The easy way out would be using cookies, but I'm trying to keep away from it.

View 1 Replies

Security :: GetRolesForUser By User Id?

Aug 23, 2010

Why there is no method to get user roles by their ID. I do not want to use name. So I'm just wondering do I have to write my own or somebody else already did it ?

View 11 Replies

Web Forms :: Login View - Avoid Unnecessary Queries To Db To GetRolesForUser?

Sep 10, 2010

I have built an asp.net web site with .net framework 3.5 and I am trying to avoid sending unncessary queries to my database in order not to have high server load. I have a login view in my master pages and it contains templates for anonymous users and members. To lighten my server load, I am using Sql Data Profiler and Database Tuning Advisor. I noticed that every page load triggers a stored procedure to get user role using
dbo.aspnet_UsersInRoles_GetRolesForUser stored procedure.

My question is that if it is necessary to check for every page load or I can store it somewhere and check later. is it Login View or Login Control sending queries? is it about access rules to member's pages? or is it because I used the login controls in my master page?

View 2 Replies

How To Make All Of The Roles Defined In RoleGroup> Required? (i.e. User Must Meet All Roles)

Feb 24, 2011

Let's say I have a rolegroup as follows:

<asp:LoginView ID="lvDoSomeStuff" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="RoleOne,RoleTwo">
<ContentTemplate>
...
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>

Is there a way I can make it so that a user must meet RoleOne and RoleTwo to satisfy the RoleGroup? By default, if a user is in either of the two roles, they will be granted access. I know I can do this via the code-behind, but I'd prefer to be able to wrap some content template with this markup instead of having to wrap it in a panel and hide the panel programmatically.

View 1 Replies

Sample C# Code To Manage Roles With Roles Provider?

Sep 21, 2010

i want to implement asp.net role provider to assign users over my LAN to roles and have my asp.net intranet app implement security based on roles.

i dont want to use VS to manage this with the built in tools but rather hand this off to users to manage themselves. i want an admin folder with a page(s) for admin roles to be able to create/edit roles and manage users in roles... this way an admin can add a domain user (MyDomainUsername) to a role such as ProojectManager or Tester or Developer... and users wont need to contact me for these tasks...

can anyone provide me a link (or some sample code) to some sample i can use to admin roles and users over a LAN in asp.net with c#?

View 1 Replies

Security :: How To Hide Multiple Roles With Roles.getallroles()

Mar 7, 2011

I have a multi level application that I am developing and need to block multiple rows from being joined. I know how to hide one role but I cannot figure out how to hide multiple.

Here is my current code

[Code]....

View 2 Replies

Security :: Update Username Of Current Logged Username?

Mar 12, 2010

How to update username of current logged username?

View 10 Replies

Security :: Automatically Assigning Roles / Standard Practice For Assigning Roles To Newly Signed-on members?

May 17, 2010

Newb question: what is the standard practice for assigning roles to newly signed-on members. Is it usually manual or is there a way of automatically assigning roles. Being completely new to this, I am confronted by the issue of my site having three different roles that new members could fall into, but am unsure about how to assign each a role. I can't imagine having to go through the process manually if I have thousands of members.

View 6 Replies

Get All Roles, But A Select Few / Get All The Roles Except Administrator?

Aug 13, 2010

I have run into a problem where I need to remove certain items from collections that seem to only have get all functions.

My Idea is to get the full collection and then remove the unneeded items. Then take that new collection and bind it to whatever I need.

For example How do I get all the roles except administrator?

Roles strRoles = Roles.GetAllRoles()
RoleList.DataSource = (Roles) roles; //Roles.GetAllRoles();
RoleList.DataBind();

or How do I get all users but say user123

MembershipUserCollection users = Membership.GetAllUsers();
UserList.DataSource = users;
UserList.DataBind();

View 1 Replies

MVC :: Menu For Different Roles?

Feb 7, 2011

I am writing my first MVC 3 aplication (in ASP.NET) and I don't know how I can(should) display the menu for different users.

My app is created as MVC3 Web Application and the menu look like this:

[Code]....

Now, I want to show another links for user(Projects, Profile) and for admin(Manage Projects, Manage Accounts, Manage news). How I should do that?

View 5 Replies

How To Use Roles In A CMS System For C#

Jan 31, 2011

I am building a content management system and so far I am trying to get a member's area to work. I figured out the CreateUserWizard and the Login controls. I also used Roles.AddUserToRole(RegisterUser.UserName, "Member"); upon account creation to assign the user the role of a "Member". I have been googling but I havent been able to find a solid way on how to restrict either a directory or a page to make it so that only "Member" users can access it, otherwise redirect to login page. Can anyone give me an idea for this? Also I had a related question, when I go on to the site and I am NOT logged in, what is my default role? is it guest or just null?

View 2 Replies

How Does IPrincipal Get Its Roles

May 23, 2010

I need to get know how SiteMapProvider.IsAccessibleToUser() works. Built-in XmlSiteMapProvider calls HttpContext.User.IsInRole() which uses System.Security.Principal.GenericPrincipal in case of forms authentication.

Where does the current user gets its roles? Which provider loads this kind of information? I want to overload it and use custom logic.

View 2 Replies

MVC :: Specify Roles In Web.config

Nov 30, 2010

I want to be able to specify which roles having access to certain controllers in web.config and use it something like this:

[Code]....

..but the compiler says "Error 1 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type...". How to accomplish this behavior?

View 3 Replies

Can User Have More Than One Roles

Apr 3, 2010

I'm developing a web application I want to use the role authentication to control different parts of the website accessibility. But my problem is say I implemented a upload and download functionality on one of the page and I want to have the ability to control a user whether they can either upload or download; or both. So, I'm not exactly sure if the role base authentication can support a user with more than one role to work the way I want it.

View 1 Replies

PDF With Search And Roles?

Sep 24, 2010

I have a pdf file that will be stored in a website and based from roles it will call the certain pdf files. (done with this save pdf inside a folder then call it using sitemap per pdf files according to roles) but I need a search page that will search a given pdf file name based on their roles, they can only see the pdf that is intended for them then via link it will then see all the pdf that was search.

View 1 Replies

Getting The Roles From The HttpContextBase?

Feb 25, 2011

There is a way to get the array of role from the HttpContextBase ?

I'm looking to do a class like that:

public static IList<string> GetUserRoles(this HttpContextBase context)
{
if (context != null)
{
}
// return roles array;
}

View 2 Replies

Losing User Roles?

Aug 11, 2010

I am baffled, I am using a treeview to set the source of an iframe. The web page is being displayed correctly, but User.IsInRole("roleName"), in the code behind, always returns false. The strange thing is User.Identity.Name returns the correct user name. I have tried setting the target of the tree view nodes to "_blank" and to "_self" and still no luck. So, it doesn't appear that the problem is related to the iframe.Before the treeview was added, javascript was used to set the source for the iframe and User.IsInRole returned the correct values.

View 4 Replies

MVC :: Using Checkbox And MultiSelect For Roles

Aug 23, 2010

I am new to MVC and am using MVCContrib and trying to use the Checkboxlist .My requirement is to display list of all available roles on create user page . I have dine as below .


<%=this.CheckBoxList("Roles").Label("Roles:").Options(new MultiSelectList(Roles.GetAllRoles(),"DataTextField","DataValueField"))%>

In this case GetAllRoles method retuns string[] . How can I assign the "DataTextField","DataValueField" to make it work ?

View 7 Replies

Security :: How To Get Roles After Login

Jan 7, 2010

I have used .net login control to authenticate user,i have three types of role ,role1,role2 and role3 and i have users and user have different roles.

now my requirement is like as per loggedin user i want to redirect user on particular page as per role.

for example if loggedin user role is role1 than he will redirect default1.aspx
for example if loggedin user role is role2 than he will redirect default2.aspx
for example if loggedin user role is role3 than he will redirect default3.aspx

and one question if same user may be have more than one role than what should happen???

I got a solution for same than if we are used "loggingin" event than it would be possible but i had placed login control in login view anonymous template because as per my requirement i want that after successfull login user can't see login control on page.thats why i didn't get the login control event on code.

View 6 Replies

C# - Login To Two Different Pages According To Roles?

Jan 18, 2010

My project has a Guest folder and an admin folder.

Guest has a guest1.aspx page and admin has admin1.aspx page.

Now I am trying to figure out a login control which will check the role of the user and send them to the respective pages accordingly.

The names are not in the database or the active directory...

These names are on the windows 2003 server...

So I need to check from the server if the user exists and what is its role in it.. Suppose there is company which has 10 employees and one administrator.. the company has a server and these employees are on the same domain. So the admin can add that machine to the server or delete it.. now every machine has its username password and domain.. i want my gui to use the same credentials to log into the gui and send them to the respective pages according to the role..

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved