2014-10-18 63 views
0

我想做一個頁面,管理員可以編輯用戶。這我的代碼是:Aspnetdb.mdf異常時調用方法

<%@ 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> 

從我讀過,我必須添加一些web配置?

回答

0

請查看this post關於如何正確配置成員資格提供者。

總之 - 你需要設置defaultProvider在會員節:

<configuration> 
    <system.web> 
     <membership defaultProvider="SqlProvider"> 
      <providers> 
       <clear /> 
       <add name="SqlProvider" 
        many more settings here... 
       /> 
      </providers> 
     </membership> 
    </system.web> 
</configuration> 
+0

葉氏,我會補充一點,你可以再補充'<會員defaultProvider = 「DefaultMembershipProvider」>'withouy指定的天氣是'SQL' ,「AD」或其他提供商。 – Leron 2014-10-18 16:17:47

+0

解析器錯誤消息:在應用程序級別之外使用註冊爲allowDefinition ='MachineToApplication'的節是錯誤的。此錯誤可能是由於虛擬目錄未被配置爲IIS中的應用程序。當我添加這個時,我會得到這個。我必須安裝什麼? – 2014-10-18 16:33:32

+0

您是否在根應用程序Web.config文件中使用這些設置?您是否使用IIS Express,IIS或Web開發服務器獲取此錯誤? – dotnetom 2014-10-19 07:07:43

相關問題