G
Guest
hi folks,
I've got XP pro service pack 2 VS 2005 TSE with ASP.net 2.0 and C#
I'm doing an example from Stephen Walther's so far excellent book and he
has a whole load of stuff to add the current user to a role like so:
<script runat="server">
void Page_Load()
{
if (!Page.IsPostBack)
{
foreach (ListItem item in cblSelectRoles.Items)
if (!Roles.RoleExists(item.Text))
{
Roles.CreateRole(item.Text);
Roles.AddUserToRole(User.Identity.Name, item.Text);
}
}
}
protected void btnSelect_Click(object sender, EventArgs e)
{
foreach (ListItem item in cblSelectRoles.Items)
{
if (item.Selected)
{
if (!User.IsInRole(item.Text))
Roles.AddUserToRole(User.Identity.Name, item.Text);
}
else
{
if (User.IsInRole(item.Text))
Roles.RemoveUserFromRole(User.Identity.Name, item.Text);
}
}
Response.Redirect(Request.Path);
}
void Page_PreRender()
{
foreach (ListItem item in cblSelectRoles.Items)
item.Selected = User.IsInRole(item.Text);
}
</script>
but two things happens
firstly it tells me that there is no overload for
Roles.AddUserToRole(User.Identity.Name, item.Text);
that takes only a string as first argument, so it has to be an array.
I create an array and populate it with User.identity.Name but then it turns
out that in the locals window that User.Identity.Name is empty (i.e "") how
can this be?
regards and many thanks in advance
CharlesA
I've got XP pro service pack 2 VS 2005 TSE with ASP.net 2.0 and C#
I'm doing an example from Stephen Walther's so far excellent book and he
has a whole load of stuff to add the current user to a role like so:
<script runat="server">
void Page_Load()
{
if (!Page.IsPostBack)
{
foreach (ListItem item in cblSelectRoles.Items)
if (!Roles.RoleExists(item.Text))
{
Roles.CreateRole(item.Text);
Roles.AddUserToRole(User.Identity.Name, item.Text);
}
}
}
protected void btnSelect_Click(object sender, EventArgs e)
{
foreach (ListItem item in cblSelectRoles.Items)
{
if (item.Selected)
{
if (!User.IsInRole(item.Text))
Roles.AddUserToRole(User.Identity.Name, item.Text);
}
else
{
if (User.IsInRole(item.Text))
Roles.RemoveUserFromRole(User.Identity.Name, item.Text);
}
}
Response.Redirect(Request.Path);
}
void Page_PreRender()
{
foreach (ListItem item in cblSelectRoles.Items)
item.Selected = User.IsInRole(item.Text);
}
</script>
but two things happens
firstly it tells me that there is no overload for
Roles.AddUserToRole(User.Identity.Name, item.Text);
that takes only a string as first argument, so it has to be an array.
I create an array and populate it with User.identity.Name but then it turns
out that in the locals window that User.Identity.Name is empty (i.e "") how
can this be?
regards and many thanks in advance
CharlesA