Have the security setup, have the authentication working fine, except now need to create a page to add roles to users and hopefully modify the web.config to set folders access rights.
Have the sqldataadapter and all working, and trying to create the SQL stored procedure to get users and show assigned roles if any, and have a button to manage each user. Is this only done by manually writing the scripts and creating procedures, or is there
a simpler way possibly using a user or role manager? all that happens is it errors out. you see the table, but the role manager doesnt. the database path is right, login is right.
Have the grid and all but it seems like there would be some sql already in existence, need this working fast; my sql management studio will not build scripts it says
have procedures to display all tables, display meta data from each table; any code found online to manage user roles seems to be from an obscure obsolete version that cant be found online like:
using System.Web.Security.Maverick
(sorry not found)
Are there any established SQL queries or procedures to read from the standard individual account security for VS2015 asp.net?
Unclear. Could you clarify which security system you are using ? Usually it brings all you need including SP if SPs are used. As you said System.Web.Security.Maverick doesn't return much and what's the benefit it brings compared with what ASP.NET brings
out of the box and if it doesn't have documentation ?
ApplicationDbContext context = new ApplicationDbContext();
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
If theres an example of how this is used to at least show a grid view of the current users, that would be great
PatriceSc
Hi,
Unclear. Could you clarify which security system you are using ? Usually it brings all you need including SP if SPs are used. As you said System.Web.Security.Maverick doesn't return much and what's the benefit it brings compared with what ASP.NET brings
out of the box and if it doesn't have documentation ?
In order to enable identity in webform, you should first:
Install Microsoft.AspNet.Identity.EntityFramework ,Microsoft.AspNet.Identity.OWIN,Microsoft.Owin.Host.SystemWeb using nuget.
Or you could directly create a webform project with identity , just click the change authentication button and choose Individual User Account ,vs will create a webform project with all the packages installed and many ready-made code for identity.
If you start with an empty project, you should create a startup class, use additem and select startup, the class should be like:
[assembly: OwinStartup(typeof(WebFormCases2.Startup))]
namespace WebFormCases2
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
}
}
}
Then you should configure the datasource of identity.
namespace WebFormCases2.Models.Identity
{
public class AppUser:IdentityUser
{
}
}
namespace WebFormCases2.Models.Identity
{
public class AppIdentityDbContext: IdentityDbContext<AppUser>
{
public AppIdentityDbContext():base("Identity")
{
// the identity is the connection string name in web.config // mine is <add name="Identity" connectionString="data source=localhost;initial catalog=Identity;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /> // my database Identity is an empty database
}
public static AppIdentityDbContext Create()
{
return new AppIdentityDbContext();
}
}
}
If owin doesn't create tables of your model automatically in your database, you should migrate the empty database(like entity framework migration).
Please ignore the first 3-10 step of the link below , just enable-migrations,add-migration, Update-Database -Verbose.
Then you should define a UserManager class to manage users.
namespace WebFormCases2.Models.Identity
{
public class AppUserManager : UserManager<AppUser>
{
public AppUserManager(IUserStore<AppUser> store) : base(store)
{
}
public static AppUserManager Create(
IdentityFactoryOptions<AppUserManager>options,
IOwinContext context
)
{
AppIdentityDbContext db = context.Get<AppIdentityDbContext>();
//make the usermanager's user come from your dbcontext
AppUserManager manager = new AppUserManager(new UserStore<AppUser>(db)); //set the user manager's password validator,to be simple, I set it loose
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 3,
RequireNonLetterOrDigit = false,
RequireDigit = false,
RequireLowercase = true,
RequireUppercase = false,
};
return manager;
}
}
}
Then in your startup.cs.You should register the usermanger and dbcontext.
public class Startup
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
app.CreatePerOwinContext<AppIdentityDbContext>(AppIdentityDbContext.Create);
app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create);
app.UseCookieAuthentication(
new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/IdentityExe/login.aspx")
}
);
}
}
To show all the users, you could refer to the code below, it is simplest code. For more information , you should learn more about identity.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ // if user ackerly doesn't exist , create the user.
if(UserManager.Users.Where(user => user.UserName == "ackerly").Count() == 0)
{
AppUser user = new AppUser() { UserName = "ackerly", Email = "ackerly@gmail.com" }; // the second parameter is password
UserManager.CreateAsync(user, "123wre");
} // show the users
GridView1.DataSource = UserManager.Users.ToList();
GridView1.DataBind();
}
}
private AppUserManager UserManager
{
get
{ // get usermanager from owincontext // please add reference to using Microsoft.AspNet.Identity.Owin; and using Microsoft.Owin; // or you couldn't find the method GetUserManager
IOwinContext content = HttpContext.Current.GetOwinContext();
return content.GetUserManager<AppUserManager>();
}
}
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Thanks for that explanation. I have the project and do have both individual and AD authentication working, I created the initial user tables locally then modified the script so that in startup it will create the user roles if they dont exist. I can run
the built in Register page and add and email confirm new users and see them appear in the table, the connection string is now pointing to the external SQL server and works great.
When I tried to show users it would say error: a datareader is already enabled, you must close this first. I created some stored procedures in SQL to fetch tables but it looks like thats not even needed, the userManager instance can read it all out and
bind to a Grid?
So now its a matter of trimming out the unneeded columns, then adding what role is assigned to each user? do you know how that would look, its the one GridView1 where the columns show the username, email, email is confirmed and then the Role theyre assigned
to? How to query the users and then line up which roles belong to the users? so its shown on the Grid?
but for VS2015 for this project. I need to make a utility that can change roles for users and set up all this stuff. How can this tool or anything similar be added to the project so that the website has this feature built in that the users can use as they
want?
When I tried to show users it would say error: a datareader is already enabled, you must close this first
The error indicates the code is not closing/disposing the SqlDataReader properly. This can happen if you have nest loops. Read the SqlDataReader docs for proper constructs. Post your source code if you need the community to review your code.
rogersbr
I created some stored procedures in SQL to fetch tables but it looks like thats not even needed, the userManager instance can read it all out and bind to a Grid?
The UserManager can return a list<T> which is easily bound to data controls. See the data bound control documentation.
rogersbr
So now its a matter of trimming out the unneeded columns, then adding what role is assigned to each user? do you know how that would look, its the one GridView1 where the columns show the username, email, email is confirmed and then the Role theyre assigned
to?
Clearly users can have more than one role so a Grid is probably not the best UI. My knee jerk reaction is first finding the user by ID or email. Perhaps this page also has a grid of users with a detials link. Then show the user's information and a list
of roles the user belongs to. This type of pattern is covered in the Getting Started Tutorials.
rogersbr
How to query the users and then line up which roles belong to the users? so its shown on the Grid?
Again, users to roles is a one to many so a Grid might not be the best UI design choice.
Are you using the Identity tables and need a SQL Query, Linq? Are you having trouble building an object model? Are you having trouble building UI using Web Forms? Maybe you need UI design help? I recommend talking with the folks that will use the application
and ask them how they want the UI to flow.
IF ONLY!! there was some way to see the source and adapt THAT tool? if only!
So Im creating from scratch what that website admin tool does. I would pay money to buy that tool and then put it in. In my project users have only 1 role, thats per design requirement by the customer. There needs to be some "page" where you can see all
the users, add new users and set the password, then set their role.
am trying various instances of each and every rolemanager and usermanager command and throwing them at a grid. then need to find out how to add a button to each row, to modify the settings.
So Im creating from scratch what that website admin tool does. I would pay money to buy that tool and then put it in. In my project users have only 1 role, thats per design requirement by the customer. There needs to be some "page" where you can see all
the users, add new users and set the password, then set their role.
As far as I can tell, you are creating the role management feature which had two pages if I recall correctly. That should only take a day or two depending. However, there are UI available found with a quick Google.
Thanks, Ive been studying the Brock Allen one since yesterday although its from 2014 and they seemed to give up on the project. Am now trying to integrate and test it. the User admin projects I usually find end up not working because of unknown references
that aren't available
didnt see the one from Scott Hanselman will try that now
ok so theyre the SAME package... Now I cant figure this out, what is supposed to happen, just drop this in, as-is? How would I integrate a completely separate webforms project into the existing one? Almost feel like this commenter from 2017:
If you still want to use identity in your project, you could add RoleManager into owin.
MyRole and RoleManager.
public class AppRole:IdentityRole
{
public AppRole():base()
{
}
public AppRole(string name):base(name)
{
}
}
public class AppRoleManager : RoleManager<AppRole>, IDisposable
{
public AppRoleManager(RoleStore<AppRole>store):base(store)
{
}
public static AppRoleManager Create(
IdentityFactoryOptions<AppRoleManager>options,
IOwinContext context
)
{
return new AppRoleManager(new RoleStore<AppRole>(context.Get<AppIdentityDbContext>()));
}
}
After that you may need to migrate your model. User add-migration and update-database to migrate.Or below error may occur.
The model backing the 'AppIdentityDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database
After that , you should register your role manager in your starup.cs.
I also define a userModel to show partial data of user
public class UserModel
{
public string Email { get; set; }
public string PasswordHash { get; set; }
public string Username { get; set; }
public string Id { get; set; }
public string Role { get; set; }
}
My code behind.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// RoleManager.Create(new AppRole("admin"));
// RoleManager.Create(new AppRole("normal"));
BindUsers();
}
}
private AppUserManager UserManager
{
get
{
IOwinContext content = HttpContext.Current.GetOwinContext();
return content.GetUserManager<AppUserManager>();
}
}
private void BindUsers()
{
var query = UserManager.Users.Select(et => new
{
et.UserName,
et.PasswordHash,
et.Email,
et.Id
}).ToList();
List<UserModel> arrayList = new List<UserModel>();
foreach (var item in query)
{
// use UserManager's GerRoles method to get the Role of a user
string role = UserManager.GetRoles(item.Id).Count == 0 ? "have no role" : UserManager.GetRoles(item.Id)[0];
arrayList.Add(new UserModel { Email = item.Email,PasswordHash= item.PasswordHash, Username = item.UserName, Id= item.Id, Role = role });
}
GridView1.DataSource = arrayList;
GridView1.DataBind();
}
private AppRoleManager RoleManager
{
get
{
return HttpContext.Current.GetOwinContext().GetUserManager<AppRoleManager>();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridViewRow row = GridView1.Rows[e.NewEditIndex];
// rebind the gridview
BindUsers();
}
public class UserModel
{
public string Email { get; set; }
public string PasswordHash { get; set; }
public string Username { get; set; }
public string Id { get; set; }
public string Role { get; set; }
}
// in rowdatabound , bind the dropdownlist of role
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (GridView1.EditIndex != -1 && e.Row.RowIndex == GridView1.EditIndex)
{
GridViewRow row = e.Row;
// get the current usermodel
UserModel model = row.DataItem as UserModel;
// get the dropdow
DropDownList dropdown = row.FindControl("DropDownList1") as DropDownList;
// get all the roles through rolemanager
var query = RoleManager.Roles.Select(r => new { r.Id, r.Name }).ToList();
query.Add(new { Id = "no role", Name = "no role" });
// get the roleid of current user 's role
string roleId = RoleManager.Roles.Where(r => r.Name == model.Role).Select(r => r.Id).FirstOrDefault();
// if the user has no role
if (model.Role == "have no role")
{
dropdown.SelectedValue = "no role";
}
else
{
// set current user's role selected
dropdown.SelectedValue = roleId;
}
dropdown.DataValueField = "Id";
dropdown.DataTextField = "Name";
dropdown.DataSource = query;
dropdown.Items.Add(new ListItem("no role", "no role"));
dropdown.DataBind();
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string id = e.Keys[0].ToString();
string userName = (row.Cells[1].Controls[0] as TextBox).Text;
string password = (row.Cells[2].Controls[0] as TextBox).Text;
// use UserManager's PasswordHasher to hash the user's password
string passwordHash = UserManager.PasswordHasher.HashPassword(password);
string email = (row.Cells[3].Controls[0] as TextBox).Text;
DropDownList drop = row.FindControl("DropDownList1") as DropDownList;
// update the user
try { AppUser user = UserManager.FindById(id); user.Email = email; user.UserName = userName; user.PasswordHash = passwordHash; IdentityResult result = UserManager.Update(user); } catch (Exception exe) {
}
// get the current user's roles
IList<string> roles = UserManager.GetRoles(id);
// if has role, remove the role at first
if (roles.Count > 0)
{
UserManager.RemoveFromRole(id, roles[0]);
}
if (drop.SelectedValue != "no role")
{
// add the user into the selected role user UserManager's AddToRole method
UserManager.AddToRole(id, drop.SelectedItem.Text);
}
GridView1.EditIndex = -1;
BindUsers();
}
The result.
For more information about identity, I recommend you to read Adam Freeman‘s Pro ASP.NET MVC5 Ch13-15 additional content.pdf , although it is written using mvc.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
If you still want to use identity in your project, you could add RoleManager into owin.
MyRole and RoleManager.
Thanks so much! So add 2 web pages called appMyRole and appRoleManager and fit these in? Thats so much, will work on integrating this
public class AppRole:IdentityRole
{
public AppRole():base()
{
}
public AppRole(string name):base(name)
{
}
}
public class AppRoleManager : RoleManager<AppRole>, IDisposable
{
public AppRoleManager(RoleStore<AppRole>store):base(store)
{
}
public static AppRoleManager Create(
IdentityFactoryOptions<AppRoleManager>options,
IOwinContext context
)
{
return new AppRoleManager(new RoleStore<AppRole>(context.Get<AppIdentityDbContext>()));
}
}
After that you may need to migrate your model. User add-migration and update-database to migrate.Or below error may occur.
The model backing the 'AppIdentityDbContext' context has changed since the database was created.ConsiderusingCodeFirstMigrations to update the database
After that , you should register your role manager in your starup.cs.
protectedvoidPage_Load(object sender,EventArgs e){if(!IsPostBack){// RoleManager.Create(new AppRole("admin"));// RoleManager.Create(new AppRole("normal"));BindUsers();}}privateAppUserManagerUserManager{get{IOwinContext content =HttpContext.Current.GetOwinContext();return content.GetUserManager<AppUserManager>();}}privatevoidBindUsers(){var query =UserManager.Users.Select(et =>new{
et.UserName,
et.PasswordHash,
et.Email,
et.Id}).ToList();List<UserModel> arrayList =newList<UserModel>();foreach(var item in query){// use UserManager's GerRoles method to get the Role of a userstring role =UserManager.GetRoles(item.Id).Count==0?"have no role":UserManager.GetRoles(item.Id)[0];
arrayList.Add(newUserModel{Email= item.Email,PasswordHash= item.PasswordHash,Username= item.UserName,Id= item.Id,Role= role });}GridView1.DataSource= arrayList;GridView1.DataBind();}privateAppRoleManagerRoleManager{get{returnHttpContext.Current.GetOwinContext().GetUserManager<AppRoleManager>();}}protectedvoidGridView1_RowEditing(object sender,GridViewEditEventArgs e){GridView1.EditIndex= e.NewEditIndex;GridViewRow row =GridView1.Rows[e.NewEditIndex];// rebind the gridviewBindUsers();}publicclassUserModel{publicstringEmail{get;set;}publicstringPasswordHash{get;set;}publicstringUsername{get;set;}publicstringId{get;set;}publicstringRole{get;set;}}// in rowdatabound , bind the dropdownlist of roleprotectedvoidGridView1_RowDataBound(object sender,GridViewRowEventArgs e){if(GridView1.EditIndex!=-1&& e.Row.RowIndex==GridView1.EditIndex){GridViewRow row = e.Row;// get the current usermodelUserModel model = row.DataItemasUserModel;// get the dropdowDropDownList dropdown = row.FindControl("DropDownList1")asDropDownList;// get all the roles through rolemanagervar query =RoleManager.Roles.Select(r =>new{ r.Id, r.Name}).ToList();
query.Add(new{Id="no role",Name="no role"});// get the roleid of current user 's rolestring roleId =RoleManager.Roles.Where(r => r.Name== model.Role).Select(r => r.Id).FirstOrDefault();// if the user has no roleif(model.Role=="have no role"){
dropdown.SelectedValue="no role";}else{// set current user's role selected
dropdown.SelectedValue= roleId;}
dropdown.DataValueField="Id";
dropdown.DataTextField="Name";
dropdown.DataSource= query;
dropdown.Items.Add(newListItem("no role","no role"));
dropdown.DataBind();}}protectedvoidGridView1_RowUpdating(object sender,GridViewUpdateEventArgs e){GridViewRow row =GridView1.Rows[e.RowIndex];string id = e.Keys[0].ToString();string userName =(row.Cells[1].Controls[0]asTextBox).Text;string password =(row.Cells[2].Controls[0]asTextBox).Text;// use UserManager's PasswordHasher to hash the user's passwordstring passwordHash =UserManager.PasswordHasher.HashPassword(password);string email =(row.Cells[3].Controls[0]asTextBox).Text;DropDownList drop = row.FindControl("DropDownList1")asDropDownList;// update the userIdentityResult result =UserManager.Update(newAppUser{Id= id,Email= email,PasswordHash= passwordHash,UserName= userName});// get the current user's rolesIList<string> roles =UserManager.GetRoles(id);// if has role, remove the role at firstif(roles.Count>0){UserManager.RemoveFromRole(id, roles[0]);}if(drop.SelectedValue!="no role"){// add the user into the selected role user UserManager's AddToRole methodUserManager.AddToRole(id, drop.SelectedItem.Text);}GridView1.EditIndex=-1;BindUsers();}
The result.
For more information about identity, I recommend you to read Adam Freeman‘s Pro ASP.NET MVC5 Ch13-15 additional content.pdf , although it is written using mvc.
It needs some enhancement before shipping but it works. it wouldnt run on the existing .net 4.5 that was being used. Created a new project with 4.7.2 the newest VS2015 could use (I think) and did the steps in package manager and set the HTTPS and it runs.
But now the question is how are the roles assigned to classes or methods? in MVC the controller method simply gets [Authorize role=Admin] ? and it works by magic. but webforms has the folders and a web.config, how are the permissions set?
mgebhard
rogersbr
So Im creating from scratch what that website admin tool does. I would pay money to buy that tool and then put it in. In my project users have only 1 role, thats per design requirement by the customer. There needs to be some "page" where you can see all
the users, add new users and set the password, then set their role.
As far as I can tell, you are creating the role management feature which had two pages if I recall correctly. That should only take a day or two depending. However, there are UI available found with a quick Google.
where is the code to change the page? all angularjs? where is it?
So there is the github repo of the "code" but its done in angular? need to be able to modify and compile and upload changes back. the version shown by Brock Allen and Scott Hanselman is done in Angular js. How it fits into the webforms project is a total
mystery.
Have to make alot of changes to how this tool works, but just to change one line, where does the new code get put at? I dont know angular in depth, just some syntax. Will have to bail out and go with something that works and can be upgraded. They dont support
it, probably wont answer questions there.
The link I have provided you only uses bootstrap as ui and because angularjs belongs to web front end and identity to server side, it doesn't matter whether angularjs, react.js or jquery is used in client side, you don't need to use angularjs.
About how to use identity to authenticate user as mvc attribute.
You could use original webform authentication in web.config, identity could work with it.
<authentication mode="Forms">
<forms loginUrl = "login.aspx" />
</authentication>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
<location path="IdentityExe">
<system.web>
<authorization>
<deny users="?" roles="normal"/> // deny users that haven't login and with role normal
</authorization>
</system.web>
</location>
protected void Page_Load(object sender, EventArgs e)
{
}
private IAuthenticationManager AuthManager // AuthManager is used to logout or login
{
get
{
return HttpContext.Current.GetOwinContext().Authentication;
}
}
private AppUserManager UserManager
{
get
{
IOwinContext content = HttpContext.Current.GetOwinContext();
return content.GetUserManager<AppUserManager>();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Task<AppUser> result = UserManager.FindAsync(TextBox1.Text, TextBox2.Text); // find the user
AppUser user = result.Result;
if (user != null) // if it is not null, that's to say the user exists or the user doesn't exist
{ // create ClaimsIdentity
ClaimsIdentity ident = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); // first logout
AuthManager.SignOut();
// then make the user login
AuthManager.SignIn(new AuthenticationProperties { IsPersistent = false }, ident);
}
}
One more thing ,I'm sorry, I have changed my code yesterday for updating, please pay attention.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
string id = e.Keys[0].ToString();
string userName = (row.Cells[1].Controls[0] as TextBox).Text;
string password = (row.Cells[2].Controls[0] as TextBox).Text;
// use UserManager's PasswordHasher to hash the user's password
string passwordHash = UserManager.PasswordHasher.HashPassword(password);
string email = (row.Cells[3].Controls[0] as TextBox).Text;
DropDownList drop = row.FindControl("DropDownList1") as DropDownList;
// update the user
//////////
try
{
AppUser user = UserManager.FindById(id);
user.Email = email;
user.UserName = userName;
user.PasswordHash = passwordHash;
IdentityResult result = UserManager.Update(user);
}
catch (Exception exe)
{
}
Best regards,
Ackerly Xu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
I said angular.js because there were 2 solutions offered, yours which is great, direct; And one I was in the middle of using already which is the identity framework. On the other one thats from Brock Allen and others' work on identity, someone came up with
the user/role admin page, you add about 6/7 lines of code and it just works? So I did, webforms, c# and in a new project that Identity2 example ran as shown, it has the button to add users, show all users, set claims/roles. But where in the project is it?
Its not in any of the pages in the solution. I want to change functions, add things etc. Where was the .cshtml pages for it? NOT FOUND!!!
So apparently in GitHub their solution has to be downloaded then you modify that angular.js project, then install a precompiled dll? into the project that gives you that user interface. I thought it was going to be code in the solution. its not. It will
not run in anything but VS2017, so had to install/set that up, one thing after another, another. I thought it was the solution but where the compiled dll(s) are supposed to go is not known. if the project uses CDN files for the user interface? not known.
Its interesting how projects can have that kind of feature, a user interface in a webforms app thats precompiled. It looks like the user interface is not even in the source, doing searches for text used in the .cshtml or .html pages with 0 results? Their
project is complex, it would take months to come up with what they have there, dozens of controller pages some with huge intricate 1000+ LOC. so now that one wont work and am looking at your solution offered, will try to integrate that and let you know, thanks
so much for all that
I don't know whether I have understood what you have said.
As far as I know ,cshtml belongs to view of asp.net mvc.
If you create a mvc project , you should find the cshtml.
You could see cshtml in views folder of a mvc project.
If their project is a mvc project , it should have cshtml or html.
Maybe it is not complete.
Best regards,
Ackerly Xu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Please take a look at https://www.scottbrady91.com/ASPNET-Identity/Identity-Manager-using-ASPNET-Identity as its a popular solution for .net and authentication.
What Im trying to understand is how he got that user interface working with the link clicks to show all users, modify users, add claims and all of that. Its a page(s) that I assumed was there in .cshtml in the project. ITS NOT.
I guess they wrote some package in AngularJS and compiled it and added it in to the project as a precompiled dll, so when you look at the project and want to change the page text or font or add something? not possible, its not "in" the project, thats what
I meant. Scott talks about the source on Github, ok got it. oh, it wont run in VS2015. have to install VS2017 ok now it loads and runs. you can see the first login page when it starts. but you cannot, or I could not find the .cshtml altho I had to drop
it yesterday; And even if the pages could be changed, where is this project supposed to go? they dont explain which output file to use or where it belongs.
Because I was using this identity project for a week, then found the example I tried it and it ran; but its a failure because it cant be modified, their github project is closed/archived and they dont support it anymore.
What I was saying was that I was 95% there with the above solution. Its just another thing Brock Allen did that didnt work for anyone else. but hey, its fine I'll know better to RUN AWAY if I see that name as one of the authors in the future.
So will go back and start over from scratch again. just lost about a week. and now will begin to implement the excellent complete solution you provided.
So Ive gone over the github source, and still cannot find where they create the various grid components. I do F12 and view page source, the components in the running page cannot be found in the source code provided. Only thing you can modify is the Identity
security itself and tokens and all.
The UI is pre defined and I havent found where its coming from. An asp.net showing pages that are not in the source code. Id like to know how they do this. Some online link hidden in the code to get the UI? Waste of time at this point
So Ive gone over the github source, and still cannot find where they create the various grid components. I do F12 and view page source, the components in the running page cannot be found in the source code provided. Only thing you can modify is the Identity
security itself and tokens and all.
The UI is pre defined and I havent found where its coming from. An asp.net showing pages that are not in the source code. Id like to know how they do this. Some online link hidden in the code to get the UI? Waste of time at this point
This should not take several days. This is very basic ASP.NET Web Forms data binding. The only construct that might be a bit different is using strong types rather than a dataset and linq syntax.
You've been given source code to update user roles. Below is a page to create/delete roles. Keep in mind that you cannot delete a role that is assigned to a user.
Here's an example for managing users. Keep in mind neither example is production code. Also, this code implements user with a single role which is not how the DB schema is designed.
Feel free to modify the code to suite your needs. Don't forget to lookup any Web Form constructs you don't understand. Most of this stuff is openly published.
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebFormsIdentityRoleManager.Models;
namespace WebFormsIdentityRoleManager.Admin
{
public partial class ManageUsers : System.Web.UI.Page
{
public List<IdentityRole> Roles { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Roles = RoleManager.Roles.ToList();
if (!Page.IsPostBack)
{
PopulateUsersGrid();
}
}
protected void PopulateUsersGrid()
{
var users = (from u in UserManager.Users
select new UserGridVm()
{
Username = u.UserName,
RoleId = u.Roles.FirstOrDefault().RoleId
}).ToList();
UserGrid.DataSource = users;
UserGrid.DataBind();
}
private ApplicationUserManager userManager;
public ApplicationUserManager UserManager
{
get
{
return userManager ?? Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set { this.userManager = value; }
}
private ApplicationRoleManager roleManager;
public ApplicationRoleManager RoleManager
{
get
{
return roleManager ?? Context.GetOwinContext().Get<ApplicationRoleManager>();
}
private set { this.roleManager = value; }
}
protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList roleSelect = e.Row.FindControl("RoleSelect") as DropDownList;
HiddenField roleId = e.Row.FindControl("RoleId") as HiddenField;
if (null != roleSelect)
{
roleSelect.DataSource = Roles;
roleSelect.DataValueField = "Id";
roleSelect.DataTextField = "Name";
if(Roles.Any(f => f.Id == roleId.Value))
{
roleSelect.SelectedValue = roleId.Value;
}
roleSelect.DataBind();
roleSelect.Items.Insert(0, new ListItem("--Select--", String.Empty));
}
}
}
protected void UserGrid_RowEditing(object sender, GridViewEditEventArgs e)
{
UserGrid.EditIndex = e.NewEditIndex;
PopulateUsersGrid();
}
protected void UserGrid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
UserGrid.EditIndex = -1;
PopulateUsersGrid();
}
protected void UserGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Get the new role
GridViewRow row = UserGrid.Rows[e.RowIndex];
string username = ((Label)row.FindControl("Username")).Text;
string roleId = ((DropDownList)(row.FindControl("RoleSelect"))).SelectedValue;
if(roleId != "0")
{
var role = RoleManager.FindByIdAsync(roleId).Result;
//Get the user and roles
var user = UserManager.FindByNameAsync(username).Result;
var roles = UserManager.GetRolesAsync(user.Id).Result;
//Remove any old roles as there can be only one role per user
var results = UserManager.RemoveFromRolesAsync(user.Id.ToString(), roles.ToArray()).Result;
//Add the new role
results = UserManager.AddToRoleAsync(user.Id.ToString(), role.Name).Result;
UserGrid.EditIndex = -1;
PopulateUsersGrid();
}
else
{
//User must select a value from the dropdown.
}
}
}
}
What version? Cannot get this, it says red line under Identity. And have fully given up on identity manager, its basically a fraud, doesnt work as advertised. They put a Mercedes hood ornament on a Ford Pinto thats missing the motor and said it works fine!
Now Im implementing THIS identity tool manager manually in a new vs2017 project. Right away get stuck because I cannot import or find the right usings.
Nuget is apparently all messed up. what comes up in package manager console:
If I goto nuget.org and search for aspnet.identity there are DOZENS of items to pick from. The first 1 or 2 probably the right one to pick. But in my project click on BROWSE and type in aspnet.identity its a BLANK screen, doesnt say no items found it just sits there
If so,it is a namespace not a type, you should use Microsoft.AspNet.Identity.UserManager<YourUserType>.
If you don't know what version of Identity package to use , please choose Individual User Accounts , it will automatically adds references then you could know what version to choose.
Best regards,
Ackerly Xu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
The NuGet package manager had a corrupt online path. In the settings I needed to specify the online repository at
https://nuget.org/api/v2/ but that entry was lost, so it only searched in local folders.
Now have the project you posted partly running, next thing is the grids to show the users and set the roles
Member
126 Points
878 Posts
How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 30, 2018 07:54 PM|rogersbr|LINK
Have the security setup, have the authentication working fine, except now need to create a page to add roles to users and hopefully modify the web.config to set folders access rights.
Have the sqldataadapter and all working, and trying to create the SQL stored procedure to get users and show assigned roles if any, and have a button to manage each user. Is this only done by manually writing the scripts and creating procedures, or is there a simpler way possibly using a user or role manager? all that happens is it errors out. you see the table, but the role manager doesnt. the database path is right, login is right.
Have the grid and all but it seems like there would be some sql already in existence, need this working fast; my sql management studio will not build scripts it says
have procedures to display all tables, display meta data from each table; any code found online to manage user roles seems to be from an obscure obsolete version that cant be found online like:
Are there any established SQL queries or procedures to read from the standard individual account security for VS2015 asp.net?
All-Star
48720 Points
18184 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 30, 2018 08:22 PM|PatriceSc|LINK
Hi,
Unclear. Could you clarify which security system you are using ? Usually it brings all you need including SP if SPs are used. As you said System.Web.Security.Maverick doesn't return much and what's the benefit it brings compared with what ASP.NET brings out of the box and if it doesn't have documentation ?
It's seems you start wiht that as fundamental features seems not in place yet so I would suggest maybe to look at https://docs.microsoft.com/en-us/aspnet/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project for using ASP.NET Identity with Web Forms.
Oµr you try to extend an existing app that uses already this "Maverick" system ???
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 30, 2018 08:42 PM|rogersbr|LINK
Hi,
Here is the using section of login, and from web.config (main)
If theres an example of how this is used to at least show a grid view of the current users, that would be great
Contributor
3500 Points
1300 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 06:43 AM|Ackerly Xu|LINK
Hi rogersbr,
In order to enable identity in webform, you should first:
Install Microsoft.AspNet.Identity.EntityFramework ,Microsoft.AspNet.Identity.OWIN,Microsoft.Owin.Host.SystemWeb using nuget.
Or you could directly create a webform project with identity , just click the change authentication button and choose Individual User Account ,vs will create a webform project with all the packages installed and many ready-made code for identity.
If you start with an empty project, you should create a startup class, use additem and select startup, the class should be like:
Then you should configure the datasource of identity.
If owin doesn't create tables of your model automatically in your database, you should migrate the empty database(like entity framework migration).
https://www.tutorialspoint.com/entity_framework/entity_framework_code_first_migration.htm
Please ignore the first 3-10 step of the link below , just enable-migrations,add-migration, Update-Database -Verbose.
Then you should define a UserManager class to manage users.
Then in your startup.cs.You should register the usermanger and dbcontext.
To show all the users, you could refer to the code below, it is simplest code. For more information , you should learn more about identity.
https://docs.microsoft.com/en-us/aspnet/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project
https://www.asp.net/identity/overview/getting-started
A simple gridview.
The result.
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 02:28 PM|rogersbr|LINK
Hi Ackerly
Thanks for that explanation. I have the project and do have both individual and AD authentication working, I created the initial user tables locally then modified the script so that in startup it will create the user roles if they dont exist. I can run the built in Register page and add and email confirm new users and see them appear in the table, the connection string is now pointing to the external SQL server and works great.
When I tried to show users it would say error: a datareader is already enabled, you must close this first. I created some stored procedures in SQL to fetch tables but it looks like thats not even needed, the userManager instance can read it all out and bind to a Grid?
So now its a matter of trimming out the unneeded columns, then adding what role is assigned to each user? do you know how that would look, its the one GridView1 where the columns show the username, email, email is confirmed and then the Role theyre assigned to? How to query the users and then line up which roles belong to the users? so its shown on the Grid?
thanks again!
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 02:55 PM|rogersbr|LINK
Hi Ackerly
What I am trying to create and add into the project? Already exists as the asp.net WebSite Administration tool, http://blog.regencysoftware.com/post/2014/06/22/asp-net-web-site-administration-tool-visual-studio-2013
but for VS2015 for this project. I need to make a utility that can change roles for users and set up all this stuff. How can this tool or anything similar be added to the project so that the website has this feature built in that the users can use as they want?
All-Star
53691 Points
24028 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 02:59 PM|mgebhard|LINK
The error indicates the code is not closing/disposing the SqlDataReader properly. This can happen if you have nest loops. Read the SqlDataReader docs for proper constructs. Post your source code if you need the community to review your code.
The UserManager can return a list<T> which is easily bound to data controls. See the data bound control documentation.
Clearly users can have more than one role so a Grid is probably not the best UI. My knee jerk reaction is first finding the user by ID or email. Perhaps this page also has a grid of users with a detials link. Then show the user's information and a list of roles the user belongs to. This type of pattern is covered in the Getting Started Tutorials.
Again, users to roles is a one to many so a Grid might not be the best UI design choice.
Are you using the Identity tables and need a SQL Query, Linq? Are you having trouble building an object model? Are you having trouble building UI using Web Forms? Maybe you need UI design help? I recommend talking with the folks that will use the application and ask them how they want the UI to flow.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 03:23 PM|rogersbr|LINK
The absolutely perfect solution for what Im trying to accomplish already exists in the form of the asp.net website admin tool, found http://blog.regencysoftware.com/post/2014/06/22/asp-net-web-site-administration-tool-visual-studio-2013 although this is for 2013 and Im using 2015 here.
IF ONLY!! there was some way to see the source and adapt THAT tool? if only!
So Im creating from scratch what that website admin tool does. I would pay money to buy that tool and then put it in. In my project users have only 1 role, thats per design requirement by the customer. There needs to be some "page" where you can see all the users, add new users and set the password, then set their role.
am trying various instances of each and every rolemanager and usermanager command and throwing them at a grid. then need to find out how to add a button to each row, to modify the settings.
All-Star
53691 Points
24028 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 05:18 PM|mgebhard|LINK
As far as I can tell, you are creating the role management feature which had two pages if I recall correctly. That should only take a day or two depending. However, there are UI available found with a quick Google.
https://www.hanselman.com/blog/ThinktectureIdentityManagerAsAReplacementForTheASPNETWebSiteAdministrationTool.aspx
https://brockallen.com/2014/04/09/introducing-thinktecture-identitymanager/
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 11:23 PM|rogersbr|LINK
Thanks, Ive been studying the Brock Allen one since yesterday although its from 2014 and they seemed to give up on the project. Am now trying to integrate and test it. the User admin projects I usually find end up not working because of unknown references that aren't available
didnt see the one from Scott Hanselman will try that now
should be rather easy to insert....
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Dec 31, 2018 11:43 PM|rogersbr|LINK
ok so theyre the SAME package... Now I cant figure this out, what is supposed to happen, just drop this in, as-is? How would I integrate a completely separate webforms project into the existing one? Almost feel like this commenter from 2017:
https://github.com/IdentityManager/IdentityManager/wiki
brockallen,
Thanks for your reply.
I am developing a web application with individual user accounts authentication.
I guess I'm too stupid to figure out how to get this IdentityManager to work with my website.
Thanks,
<div class="timeline-comment-header clearfix">Tony
brockallen commented on Jun 16, 2017
</div> <div class="edit-comment-hide">No, not too stupid -- just that I never had time to write up walk-thrus and complete docs (FOSS is not really free, as it takes lots of time :))
Contributor
3500 Points
1300 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 01, 2019 04:26 AM|Ackerly Xu|LINK
Hi rogersbr,
If you still want to use identity in your project, you could add RoleManager into owin.
MyRole and RoleManager.
After that you may need to migrate your model. User add-migration and update-database to migrate.Or below error may occur.
After that , you should register your role manager in your starup.cs.
Then you could change your gridview to. The TemplateField is used to add role to a user.
Before , I have added two default roles into database using
I also define a userModel to show partial data of user
My code behind.
The result.
For more information about identity, I recommend you to read Adam Freeman‘s Pro ASP.NET MVC5 Ch13-15 additional content.pdf , although it is written using mvc.
https://github.com/Apress/pro-asp.net-mvc-5/blob/master/Additional%20content/Pro%20ASP.NET%20MVC5%20Ch13-15%20additional%20content.pdf
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 01, 2019 03:19 PM|rogersbr|LINK
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 01, 2019 05:02 PM|rogersbr|LINK
So this example is what I did for a new project: https://www.scottbrady91.com/ASPNET-Identity/Identity-Manager-using-ASPNET-Identity
It needs some enhancement before shipping but it works. it wouldnt run on the existing .net 4.5 that was being used. Created a new project with 4.7.2 the newest VS2015 could use (I think) and did the steps in package manager and set the HTTPS and it runs.
But now the question is how are the roles assigned to classes or methods? in MVC the controller method simply gets [Authorize role=Admin] ? and it works by magic. but webforms has the folders and a web.config, how are the permissions set?
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 01, 2019 06:08 PM|rogersbr|LINK
where is the code to change the page? all angularjs? where is it?
So there is the github repo of the "code" but its done in angular? need to be able to modify and compile and upload changes back. the version shown by Brock Allen and Scott Hanselman is done in Angular js. How it fits into the webforms project is a total mystery.
Have to make alot of changes to how this tool works, but just to change one line, where does the new code get put at? I dont know angular in depth, just some syntax. Will have to bail out and go with something that works and can be upgraded. They dont support it, probably wont answer questions there.
Contributor
3500 Points
1300 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 02:33 AM|Ackerly Xu|LINK
Hi rogersbr,
I don't know why you say angularjs.
The link I have provided you only uses bootstrap as ui and because angularjs belongs to web front end and identity to server side, it doesn't matter whether angularjs, react.js or jquery is used in client side, you don't need to use angularjs.
About how to use identity to authenticate user as mvc attribute.
You could use original webform authentication in web.config, identity could work with it.
My code in login.aspx.
Code behind.
One more thing ,I'm sorry, I have changed my code yesterday for updating, please pay attention.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; string id = e.Keys[0].ToString(); string userName = (row.Cells[1].Controls[0] as TextBox).Text; string password = (row.Cells[2].Controls[0] as TextBox).Text; // use UserManager's PasswordHasher to hash the user's password string passwordHash = UserManager.PasswordHasher.HashPassword(password); string email = (row.Cells[3].Controls[0] as TextBox).Text; DropDownList drop = row.FindControl("DropDownList1") as DropDownList; // update the user ////////// try { AppUser user = UserManager.FindById(id); user.Email = email; user.UserName = userName; user.PasswordHash = passwordHash; IdentityResult result = UserManager.Update(user); } catch (Exception exe) { }
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 05:39 AM|rogersbr|LINK
Hi Ackerly,
I said angular.js because there were 2 solutions offered, yours which is great, direct; And one I was in the middle of using already which is the identity framework. On the other one thats from Brock Allen and others' work on identity, someone came up with the user/role admin page, you add about 6/7 lines of code and it just works? So I did, webforms, c# and in a new project that Identity2 example ran as shown, it has the button to add users, show all users, set claims/roles. But where in the project is it? Its not in any of the pages in the solution. I want to change functions, add things etc. Where was the .cshtml pages for it? NOT FOUND!!!
So apparently in GitHub their solution has to be downloaded then you modify that angular.js project, then install a precompiled dll? into the project that gives you that user interface. I thought it was going to be code in the solution. its not. It will not run in anything but VS2017, so had to install/set that up, one thing after another, another. I thought it was the solution but where the compiled dll(s) are supposed to go is not known. if the project uses CDN files for the user interface? not known.
Its interesting how projects can have that kind of feature, a user interface in a webforms app thats precompiled. It looks like the user interface is not even in the source, doing searches for text used in the .cshtml or .html pages with 0 results? Their project is complex, it would take months to come up with what they have there, dozens of controller pages some with huge intricate 1000+ LOC. so now that one wont work and am looking at your solution offered, will try to integrate that and let you know, thanks so much for all that
Contributor
3500 Points
1300 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 05:56 AM|Ackerly Xu|LINK
Hi rogersbr,
I don't know whether I have understood what you have said.
As far as I know ,cshtml belongs to view of asp.net mvc.
If you create a mvc project , you should find the cshtml.
You could see cshtml in views folder of a mvc project.
If their project is a mvc project , it should have cshtml or html.
Maybe it is not complete.
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 03:35 PM|rogersbr|LINK
Hi Ackerly
Please take a look at https://www.scottbrady91.com/ASPNET-Identity/Identity-Manager-using-ASPNET-Identity as its a popular solution for .net and authentication. What Im trying to understand is how he got that user interface working with the link clicks to show all users, modify users, add claims and all of that. Its a page(s) that I assumed was there in .cshtml in the project. ITS NOT.
I guess they wrote some package in AngularJS and compiled it and added it in to the project as a precompiled dll, so when you look at the project and want to change the page text or font or add something? not possible, its not "in" the project, thats what I meant. Scott talks about the source on Github, ok got it. oh, it wont run in VS2015. have to install VS2017 ok now it loads and runs. you can see the first login page when it starts. but you cannot, or I could not find the .cshtml altho I had to drop it yesterday; And even if the pages could be changed, where is this project supposed to go? they dont explain which output file to use or where it belongs.
Because I was using this identity project for a week, then found the example I tried it and it ran; but its a failure because it cant be modified, their github project is closed/archived and they dont support it anymore.
What I was saying was that I was 95% there with the above solution. Its just another thing Brock Allen did that didnt work for anyone else. but hey, its fine I'll know better to RUN AWAY if I see that name as one of the authors in the future.
So will go back and start over from scratch again. just lost about a week. and now will begin to implement the excellent complete solution you provided.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 07:17 PM|rogersbr|LINK
So Ive gone over the github source, and still cannot find where they create the various grid components. I do F12 and view page source, the components in the running page cannot be found in the source code provided. Only thing you can modify is the Identity security itself and tokens and all.
The UI is pre defined and I havent found where its coming from. An asp.net showing pages that are not in the source code. Id like to know how they do this. Some online link hidden in the code to get the UI? Waste of time at this point
All-Star
53691 Points
24028 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 07:58 PM|mgebhard|LINK
This should not take several days. This is very basic ASP.NET Web Forms data binding. The only construct that might be a bit different is using strong types rather than a dataset and linq syntax.
You've been given source code to update user roles. Below is a page to create/delete roles. Keep in mind that you cannot delete a role that is assigned to a user.
All-Star
53691 Points
24028 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 02, 2019 09:33 PM|mgebhard|LINK
Here's an example for managing users. Keep in mind neither example is production code. Also, this code implements user with a single role which is not how the DB schema is designed.
Feel free to modify the code to suite your needs. Don't forget to lookup any Web Form constructs you don't understand. Most of this stuff is openly published.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 24, 2019 08:23 PM|rogersbr|LINK
If I goto nuget.org and search for aspnet.identity there are DOZENS of items to pick from. The first 1 or 2 probably the right
one to pick. But in my project click on BROWSE and type in aspnet.identity its a BLANK screen, doesnt say no items found
it just sits there
Contributor
3500 Points
1300 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 25, 2019 04:33 AM|Ackerly Xu|LINK
Hi rogersbr,
Do you mean Microsoft.AspNet.Identity?
If so,it is a namespace not a type, you should use Microsoft.AspNet.Identity.UserManager<YourUserType>.
If you don't know what version of Identity package to use , please choose Individual User Accounts , it will automatically adds references then you could know what version to choose.
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
126 Points
878 Posts
Re: How to get UserNames, User assigned Roles and modify from c# Webforms .net 4.5
Jan 26, 2019 12:30 AM|rogersbr|LINK
Hi Ackerly,
The NuGet package manager had a corrupt online path. In the settings I needed to specify the online repository at https://nuget.org/api/v2/ but that entry was lost, so it only searched in local folders.
Now have the project you posted partly running, next thing is the grids to show the users and set the roles