我正在尝试创建一个管理员可以编辑用户的页面。我的代码是:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ManageUsers.aspx.cs" Inherits="SiteStiri.Administration.ManageUsers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Repeater ID="FilteringUI" runat="server">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnkFilter" Text='<%# Container.DataItem %>' CommandName='<%# Container.DataItem %>'>
</asp:LinkButton>
</ItemTemplate>
<SeparatorTemplate>|</SeparatorTemplate>
</asp:Repeater>
<asp:GridView ID="UserAccounts" runat="server" AutoGenerateColumns="False">
<Columns> <asp:BoundField DataField="UserName" HeaderText="UserName"/>
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:CheckBoxField DataField="IsApproved" HeaderText="Approved?"/>
<asp:CheckBoxField DataField="IsLockedOut" HeaderText="Locked Out?" />
<asp:CheckBoxField DataField="IsOnline" HeaderText="Online?"/>
<asp:BoundField DataField="Comment" HeaderText="Comment"/>
</Columns>
</asp:GridView>
</asp:Content>
主页面(我在制作东西之前首先按照教程进行操作)
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;
namespace SiteStiri.Administration
{
public partial class ManageUsers : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindUserAccounts();
BindFilteringUI();
}
}
private void BindUserAccounts()
{
UserAccounts.DataSource = Membership.GetAllUsers();
UserAccounts.DataBind();
}
private void BindFilteringUI() {
string[] filterOptions = { "All", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
FilteringUI.DataSource = filterOptions;
FilteringUI.DataBind();
}
}
}
页面背后的代码。
当我运行它时,我收到以下错误
An exception of type 'System.Configuration.Provider.ProviderException' occurred in System.Web.dll but was not handled in user code
Additional information: Default Membership Provider must be specified.
这里必须做些什么,我如何指定默认成员资格提供商以及它是什么?
Extended error eport:
System.Configuration.Provider.ProviderException was unhandled by user code
HResult=-2146233088
Message=Default Membership Provider must be specified.
Source=System.Web
StackTrace:
at System.Web.Security.Membership.InitializeDefaultProvider(Boolean initializeDefaultProvider, MembershipSection settings)
at System.Web.Security.Membership.Initialize()
at System.Web.Security.Membership.get_Provider()
at System.Web.Security.Membership.GetAllUsers(Int32 pageIndex, Int32 pageSize, Int32& totalRecords)
at System.Web.Security.Membership.GetAllUsers()
at SiteStiri.Administration.ManageUsers.BindUserAccounts() in d:\ProiecteVisual\SiteStiri\SiteStiri\Administration\ManageUsers.aspx.cs:line 23
at SiteStiri.Administration.ManageUsers.Page_Load(Object sender, EventArgs e) in d:\ProiecteVisual\SiteStiri\SiteStiri\Administration\ManageUsers.aspx.cs:line 17
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
这是Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<allow roles="canEdit" />
<deny users="*"/>
</authorization>
</system.web>
</configuration>
根据我的阅读,我必须在网络配置中添加一些东西吗?
答案 0 :(得分:0)
请查看this post有关如何正确配置会员提供商的信息。
简而言之 - 您需要在Membership部分中设置defaultProvider:
<configuration>
<system.web>
<membership defaultProvider="SqlProvider">
<providers>
<clear />
<add name="SqlProvider"
many more settings here...
/>
</providers>
</membership>
</system.web>
</configuration>