我通過在應用程序啓動時設置默認超級用戶來解決此問題。
通過添加這gobal.asax
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// check that the minimal security settings are created
Security.SetupSecurity();
}
然後在安全類:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
///
/// Creates minimum roles and user for application access.
///
public class Security
{
// application roles
public static string[] applicationRoles =
{ "Roles1", "Roles2", "Roles3", "Roles4", "Roles5" };
// super user
private static string superUser = "super";
// default password, should be changed on first connection
private static string superUserPassword = "default";
private Security()
{
//
// TODO: Add constructor logic here
//
}
///
/// Creates minimal membership environment.
///
public static void SetupSecurity()
{
SetupRoles();
SetupSuperuser();
}
///
/// Checks roles, creates missing.
///
public static void SetupRoles()
{
// create roles
for (int i = 0; i
/// Checks if superuser account is created.
/// Creates the account and assigns it to all roles.
///
public static void SetupSuperuser()
{
// create super user
MembershipUser user = Membership.GetUser(superUser);
if (user == null)
Membership.CreateUser(superUser, superUserPassword, "[email protected]");
// assign superuser to roles
for (int i = 0; i
一旦你有一個默認的用戶,可以使用AspNetWSAT或其他。
抱歉,我不是更清楚。我已經運行了aspnet_regsql,我希望能夠現在添加用戶和角色。 – sontek 2008-10-01 07:35:58