I'm using ASP.NET MVC Framwork and trying to grok the ASP Membership 3.5 stuff.
我正在使用ASP.NET MVC Framwork并尝试了解ASP Membership 3.5的内容。
What is the best way to add the first administrator user without having to log in? I've been staring at the membership starter kit's source without finding it.
无需登录即可添加第一个管理员用户的最佳方法是什么?我一直在盯着会员入门套件的来源而没有找到它。
3 个解决方案
#1
A simple solution (especially or rather only for dev. purposes) by doing it in a "setup" action:
一个简单的解决方案(特别是或仅用于开发目的)通过“设置”操作执行:
if (!Roles.RoleExists("Administrator"))
{
Roles.CreateRole("Administrator");
}
if (Membership.GetUser("Admin") == null)
{
Membership.CreateUser("Admin", "Admin");
Roles.AddUserToRole("Admin", "Administrator");
}
#2
Depends on what memebership provider your are using.. If your using a SQL memembershipprovider you should be able to use the regular Asp.Net Configuration tool. (Project menu -> Asp.Net Configuration)
取决于您正在使用的memebership提供程序..如果您使用SQL memembershipprovider,您应该能够使用常规的Asp.Net配置工具。 (项目菜单 - > Asp.Net配置)
#3
You said you were going to share the project. I would recommend creating a one-time-run page that creates the user and assigns it the roel you want. After that any concurrent runs of the page should than check for the user you want and if it exists to redirect away or some other mechanic.
你说你打算分享这个项目。我建议创建一个一次性运行的页面来创建用户并为其分配您想要的内容。在此之后,页面的任何并发运行应该检查您想要的用户以及是否存在重定向或其他机制。
#1
A simple solution (especially or rather only for dev. purposes) by doing it in a "setup" action:
一个简单的解决方案(特别是或仅用于开发目的)通过“设置”操作执行:
if (!Roles.RoleExists("Administrator"))
{
Roles.CreateRole("Administrator");
}
if (Membership.GetUser("Admin") == null)
{
Membership.CreateUser("Admin", "Admin");
Roles.AddUserToRole("Admin", "Administrator");
}
#2
Depends on what memebership provider your are using.. If your using a SQL memembershipprovider you should be able to use the regular Asp.Net Configuration tool. (Project menu -> Asp.Net Configuration)
取决于您正在使用的memebership提供程序..如果您使用SQL memembershipprovider,您应该能够使用常规的Asp.Net配置工具。 (项目菜单 - > Asp.Net配置)
#3
You said you were going to share the project. I would recommend creating a one-time-run page that creates the user and assigns it the roel you want. After that any concurrent runs of the page should than check for the user you want and if it exists to redirect away or some other mechanic.
你说你打算分享这个项目。我建议创建一个一次性运行的页面来创建用户并为其分配您想要的内容。在此之后,页面的任何并发运行应该检查您想要的用户以及是否存在重定向或其他机制。