C# - Get Role Of User In A String Variable?
Jan 21, 2010
is there a way i can get the role in a string variable using the below commands....
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal wp = new System.Security.Principal.WindowsPrincipal(wi);
i need this for
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version
UserName.Text, // user name
DateTime.Now, // creation
DateTime.Now.AddMinutes(60),// Expiration
false, // Persistent
role); // User data
as string role= wp.IsInRole();
but this is not right
View 5 Replies
Similar Messages:
Mar 7, 2011
I am having one doubt regarding the use of static variable in Asp.net pages.I am having one page say UserDetails.aspx.In this page, I have one static variable to store some data specific to a user. So, will this ?
public partial class UserDetails
{
static int numberOfReviews=0;
[code]...
View 5 Replies
Feb 24, 2011
I'm trying to allow logged user who are in department XYZ to perform some task for my third party App. I have two SQL tables named Users & UserList. The third party app (GoldMine) graps the USERNAME from the Users table and store it as UserID which I then referecnce SessionID. The UserList table has two columns (GM_UserName & Department) which I'm interested in. When a user login into the 3rd party app (GoldMine), i then compare the USERNAME (from Users table) to GM_UserName (from UserList table) and see whether GM_UserName is in = 'Dept XYZ'. Take a look at the SQL query below.
sqlDept = "SELECT USERNAME FROM Users LEFT JOIN UserList ON UserList.GM_UserName=Users.UserName WHERE UserList.Department ='Dept XYZ'"
I'm able to do this.
If Session("Userid") = "TestUser1" Or Session("UserID") = "TestUser2" Then Do this Else Do that End If
BUT unable to do this...
If user's Department = 'Department XYZ' Then
Do This
Else
Do that
End IF
View 2 Replies
May 9, 2010
I want to display a menu (which will be strongly typed with it's own unique model) across all pages only if a user is logged in.What menu items are available depend on the user's role and also I'll need to hit the repository to get numbers like "x Messages", etc
Been scratching my head for a simple solution here. Don't want to create something that need changes all over the place.All my controllers derive from a BaseController, all my Models from BaseViewModel....probably where I'll be implementing functionality for this.
View 3 Replies
May 7, 2015
I have LOGIN PANEL for student, and I want to disable it in different page. And only the admin can enable and disable it. I dont know the logic behind here.
View 1 Replies
Mar 11, 2011
I want to implement access control for usercontrols depending on user role(s), I want to do it on the control base class, in such way that on every user control I only need to set a string with allowed roles to see the user control
This is how an user control class may look like:
public partial class SimpleMenu : MyUsrControlBase
{
protected void Page_Load(object sender, EventArgs e)[code]...
How to set up user control visibility from the base class depending on the validation result?Also which event in the user control is the best to set the roles?
AlloweRoles = "RoleA, RoleB"
View 1 Replies
Jul 17, 2015
i don't know how to use a Encrypted ConnectionString with RoleManager in ASP.NET This is code in Web.config.
<connectionStrings>
<add name="strConnectionString" connectionString="eF8w9r2UJOsk0Ps3pxmV7/Fy/xPR2hN2S7BrC1iOYNnAUaI8AqkSm5bw7r+ta4sePWSV9t/3Spnpz6wsFpvMmcppNpqM5Zk7iiDqWVgIV4k="/>
</connectionStrings>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
[Code] ....
And in project I create a library to read web config
private const string ConnectionStringKey = "strConnectionString";
private readonly string SQLConnectionString =
Security.DecryptString(ConfigurationManager.ConnectionStrings[ConnectionStringKey].ConnectionString);
if I change my ConnectionString like this, it's working:
<add name="strConnectionString" connectionString="server=My-PCMSSQL2008; database=MyDB; uid=sa; pwd=passw0rd;"/>
But I want my ConnectionString Encrypted so i use
<add name="strConnectionString" connectionString="eF8w9r2UJOsk0Ps3pxmV7/Fy/xPR2hN2S7BrC1iOYNnAUaI8AqkSm5bw7r+ta4sePWSV9t/3Spnpz6wsFpvMmcppNpqM5Zk7iiDqWVgIV4k="/>
So when i running website it throw error:
System.ArgumentException:Keyword not supported: 'eF8w9r2UJOsk0Ps3pxmV7/Fy/xPR2hN2S7BrC1iOYNnAUaI8AqkSm5bw7r+ta4sePWSV9t/3Spnpz6wsFpvMmcppNpqM5Zk7iiDqWVgIV4k='.
Line 46: string[] roleNames;
Line 47: roleNames = Roles.GetAllRoles();
View 1 Replies
Jun 11, 2010
I am developing an application in which I can connect to the ASPNETDB.MDF if it is on my machine, however, when I want to put it on another machine and try to remote connect it, I get the error:
An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.
Parameter name: connectionString and my connection string is as follows:
<add name ="NewRemoteSqlServer" connectionString="Data Source=P1M1_2-HPSQLEXPRESS; AttachDBFilename=C:ASPNETDB.MDF; Integrated Security=SSPI; Username=P1M1_2-HP; Password=plus1minus1; " providerName="System.Data.SqlClient"/>
View 5 Replies
Oct 18, 2010
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 :
[code]...
View 2 Replies
Jan 13, 2010
I am in the process of creating a user control that enables content areas of our web application to be editable. The control utilizes the asp.net membership/role providers and incorporates a LoginView that only displays the edit link if a user has logged in and is a member of the desired role. What I would like to be able to do is pass the "role" as a property of the control so it can be set dynamically and does not have to be hard coded into the control if I use elsewhere in another application.
View 3 Replies
Jun 18, 2010
I have a value in string i want to use that value on next page.
How can i access it with previous page property?
Or is there any other way to fetch value store in string variable on next page?
View 6 Replies
Jul 16, 2010
How to display the string data stored in a string[] variable into gridview?
View 9 Replies
Jan 22, 2011
Is there any way that I can find the exact name of the role a User is in? There is a property for UserName ( User.Identity.Name) but what about the role?
View 1 Replies
Jul 18, 2012
trying to get a login script working, its working fine, but now i have a new problem, i have a field im my DB thats called "urole" in that i have 3 roles, Admin, Co-Admin, User.
How can i use something like this on a page.
Code:
If Roles.IsUserInRole("Admin") Then
Label1.Text = User.Identity.Name + " is an Admin"
Else
Label1.Text = User.Identity.Name + " is NOT in an Admin"
End If
I have this script on my login page
Code:
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.Configuration
Partial Class DbLogin
Inherits System.Web.UI.Page
[code]....
and then i have this on my default page, thats shows the info from an user, now i just want to show the role (urole) and then use an "If Roles.IsUserInRole" event so i can show some diffrent thing if admin, co-admin or User
Code:
Imports System.IO
Imports System.Web.Security
Partial Class _Default
Inherits System.Web.UI.Page
[code]....
(The aboved is working fine, but its not showing the urole/Role of an user)
View 12 Replies
Feb 18, 2010
In code, how can I change the user's role from one to another?
Let's say the user1 is in Role1. I would like to change his role to Role2.
View 6 Replies
Dec 10, 2010
I have a page setup to manage and create users.. in order to help the process of creation, i woudl like to add the new users to our default "users" role when they click the create button. Below is what is in place for the creation page and the button event tied to the button. I used this from a tutorial i found else where, but dont have the link at the moment if anyone needed it.. but the code below works great when creating a new user
[Code]....
View 5 Replies
Mar 2, 2010
I wish to know the way to add ASP.NET ("Machine_Name"IIS_IUSRS) to user role in COM+ component programmatically using C#. So whenever my COM+ component is being installed, ASP.NET user is created under Role.
View 1 Replies
Feb 12, 2011
The roles of users are not saved. Here is what i am doing:
[Code]....
And i added this to the create user wizard:
<asp:WizardStep ID="SpecifyRolesStep" runat="server" StepType="Step"
Title="Specify Roles" AllowReturn="False">
<asp:CheckBoxList ID="RoleList" runat="server">
</asp:CheckBoxList>
</asp:WizardStep>
View 1 Replies
Dec 31, 2010
I need to get the role of the user using memebership.
View 2 Replies
May 22, 2010
I roll my own SiteMapProvider inheriting System.Web.XmlSiteMapProvider.I want to override logic of checking user to be in a role specified in siteMapNode's property roles:
<siteMapNode url="Add.aspx?type=user" title="Add user" roles="admin" />
How can I do that? Which class's member does XmlSiteMapProvider call to check that if securityTrimmingEnabled="true"?
View 2 Replies
Mar 31, 2011
Setting role when creating new user with ASP.net MVC
I am looking at the default ASP.net MVC 2 controller.
How do I set the role for the new user that is created in the Register method?
Is this possible with just a simple property set or do I have to do something special?
View 1 Replies
Nov 11, 2010
There used to a lot of tutorials on the asp.net site and I can't find any of them anymore. Anyway, I'm looking for a tutorial on how to send out an email to the newly registered user for verficiation. After the user checks his/her email and click the link in the email, it automatically unlock the user's account and allow him/her to login to the site. Below is what I have so far:
[Code]....
[Code]....
And verification page_load:
[Code]....
The user does receive the verification email and when he/she click on the link it does come over to the verification.aspx page; however, the user still can't login. When I looked at the status of the user, it's still locked.
View 2 Replies
Jan 28, 2011
im using forms authentication and created roles.
while the user enters the credentials im authenticating the user with username and password
now i also want to check the particular user whether he is that role.
eg:
if username,password are true and role is Admin i redirect him to Adminhome.aspx
else to empHome.aspx.
im able to chek username and password but im unable to detect the role.
[Code]....
View 6 Replies
Feb 26, 2010
How can i give access to IIS_WPG user role in IIS.
I am trying to run .net 2.0 application on windows xp laptop
View 3 Replies
Feb 4, 2010
I have a login form from the membership and I am trying to make it so that it would redirect depending on role. I have tried to put this code under login1_loggedin but it didn't seem to work. how can I do this?
View 1 Replies