Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将下拉列表中的选定参数发送到C代码隐藏文件以代替User.Identity.Name使用?_C#_Asp.net_Authentication_Webforms - Fatal编程技术网

C# 如何将下拉列表中的选定参数发送到C代码隐藏文件以代替User.Identity.Name使用?

C# 如何将下拉列表中的选定参数发送到C代码隐藏文件以代替User.Identity.Name使用?,c#,asp.net,authentication,webforms,C#,Asp.net,Authentication,Webforms,我能够为一个遗留应用程序创建一个快速而肮脏的asp用户网站管理工具,我能够实现注册、激活、分配角色、创建角色的工具,但我正在努力创建一个允许您选择现有用户并从底层aspnet安全数据库用户、UserinRoles、成员资格等中删除其所有相关信息的数据库 到目前为止,我所做的是开发一个工具,查询我的sql数据库,返回所有现有用户,并将其绑定到下拉列表。我有一个删除按钮,它调用代码隐藏文件中的一个函数,该函数将删除当前登录用户的所有相关用户信息 我只想删除下拉列表中所选用户的用户信息 请原谅我的无知

我能够为一个遗留应用程序创建一个快速而肮脏的asp用户网站管理工具,我能够实现注册、激活、分配角色、创建角色的工具,但我正在努力创建一个允许您选择现有用户并从底层aspnet安全数据库用户、UserinRoles、成员资格等中删除其所有相关信息的数据库

到目前为止,我所做的是开发一个工具,查询我的sql数据库,返回所有现有用户,并将其绑定到下拉列表。我有一个删除按钮,它调用代码隐藏文件中的一个函数,该函数将删除当前登录用户的所有相关用户信息

我只想删除下拉列表中所选用户的用户信息

请原谅我的无知,我确实花了几个小时试图自己找到最简单的解决办法

以下是ASPX的首页:

<h3>Delete Users</h3>
    <p>
        <b>Select a User:</b>
        <asp:DropDownList ID="UserList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Page_Load"></asp:DropDownList>
    </p>
    <p>
        <asp:SqlDataSource ID="UserInfo" runat="server" ConnectionString="<%$ ConnectionStrings:AspnetdbConnectionString %>" SelectCommand="SELECT [UserName], [UserID] FROM [vw_aspnet_MembershipUsers] WHERE ([UserName] = @UserName)">
            <SelectParameters>
                <asp:ControlParameter Name="Username" ControlID="UserList" PropertyName="SelectedValue" />
            </SelectParameters>                
        </asp:SqlDataSource>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="UserInfo" Height="50px">
            <Fields>
                <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
                <asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" />                                         
            </Fields>               
        </asp:DetailsView>
        <asp:Button id="DeleteButton" Text="Yes" OnClick="DeleteButton_OnClick" runat="server" />
    </p>
</div>
代码隐藏文件如下所示:

 < using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.Web.Security;

public partial class DeleteUsers : System.Web.UI.Page
{    
protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        DisplayUsersInGrid();
    }
}

private void DisplayUsersInGrid()
{
    UserList.DataSource = Membership.GetAllUsers();
    UserList.DataBind();
}

public void DeleteButton_OnClick(object sender, EventArgs args)
{
    Membership.DeleteUser(User.Identity.Name);
    ActionStatus.Visible = true;
}    

您正在尝试删除当前登录的用户。 您必须从下拉列表中获取所选的用户id并传递给DeleteUserFunction

替换Membership.DeleteUserUser.Identity.Name;与下面

Membership.DeleteUser(UserList.SelectedValue);

真不敢相信这么容易,我差一点就成功了!我非常感激,我只是错过了用户列表中的选定值!