过去,我使用默认的 SQL 成员资格提供程序来保护网站。这运作良好,但需要创建 ASP_Authentication 数据库(使用 reg_sql 工具)和数十个表/存储过程等。
我现在在每月 10 英镑的主机上有一个简单的网站。作为交易的一部分,我获得了一个 SQL Server 实例,但无法通过 SQL Management Studio 连接到它。我无法运行 reg_sql 工具,甚至无法从以前生成的数据库中获取脚本并运行它。
实际上,ASP_Authentication 数据库对于我的需要来说是多余的。我只是一个简单的用户名/登录存储,我可以对其进行身份验证。我不需要小组/角色等。
有谁知道一篇好的博客文章或类似的文章描述了如何做到这一点?
非常感谢
罗布。
In the past I've used the default SQL Membership provider to secure a website. This worked well but required the creation of the ASP_Authentication database (using the reg_sql tool) and dozens of tables / stored procs etc.
I now have a simple website on a £10 per month host. I get a SQL Server instance as part of the deal but don't have the ability to connect to it through SQL Management Studio. I can't run the reg_sql tool or even take a script from a previously generated database and run that.
Actually, the ASP_Authentication database is overkill for what I need. I just was a simple username / login store that I can authenticate against. I have no need for group / roles etc.
Does anyone know of a good blog article or similar that describes how to do this?
Many thanks
Rob.
发布评论
评论(3)
如果您只想要一个简单的登录机制,我建议您坚持使用 sql 会员资格。您不必使用角色或任何附加功能,例如秘密问题/答案。
通过命令行
您可以在本地使用 aspnet_regsql 工具来生成 sql 脚本。您必须能够访问某种管理数据库的工具,所以这对您来说可能就足够了?
我写了一篇关于通过命令行使用此工具的文章。我还解决了仅添加您实际想要使用的表的问题(不需要个性化、Web 部件等表)。
该文章位于我的博客上:
它没有介绍如何将 sql 脚本转储到文件中,但它确实给了您一个提示(它说您可以使用 -? 查看所有命令行参数)。打开命令窗口(开始 | 运行 | cmd | Enter)并键入:
asp.net v2:
asp.net v4:
如果 v4 不起作用,则查看下一个窗口并使用其中最新的 v4 文件夹。
然后,您将在 C: 驱动器的根目录中找到一个名为
aspnetmembership.sql
的文件,您可以将其与他们提供的任何数据库管理一起使用。通过代码
还有另一种设置表的选项,但社区通常不太为人所知;实际上,您可以通过 System.Web.Management 命名空间中的方法来完成此操作。我在 Peter Bromberg 的一篇文章中学到了这项技术,并将其收藏起来。这是一个简单的一行:
您可以阅读 他的建议在这里。
自定义会员资格提供商
要真正回答您的问题,网络上有大量文章解释如何创建自定义会员资格提供商:
如果您决定“滚动你自己的”那么请坚持该计划并使用会员提供商框架而不是从头开始编写自己的内容。
I would advise you to stick with the sql membership if you just want a simple login mechanism. You dont have to use the roles or any additional features such as secret question/answer.
Via The Commandline
You can use the aspnet_regsql tool locally to just generate sql scripts. You must have access to some kind of tool for managing the database so perhaps this will be enough for you?
I have written an article on using this tool via the commandline. I also address the issue of only adding the tables you actually want to use (no need for the personalization, web parts, etc tables).
The article is on my blog here:
It doesn't cover how you can dump the sql scripts out to a file but it does give you a hint (it says you can use -? to view all commandline arguments). Open up a command window (start | run | cmd | enter) and type:
asp.net v2:
asp.net v4:
If the v4 doesn't work then look in the next one up and use the latest v4 folder in there.
You will then find a file called
aspnetmembership.sql
in the root of your C: drive which you can use with whatever database management they provide.Via Code
There is another option to getting the tables set up which is generally less well known by the community; you can actually do it through a method in the System.Web.Management namespace. I learned this technique in a post by
Peter Bromberg
and keep it tucked away. Its a simple one liner:You can read the rest of his advice here.
Custom Membership Provider
To actually answer your question though, there are tons of articles on the web which explain how to create custom membership providers:
If you do decided to "roll your own" then please stick to the plan and use the membership provider framework rather than writing your own from the ground up.
不确定您使用的是 ASP.NET WebForms 还是 MVC,但我创建了一个 NuGet 包来在 ASP.NET MVC3 中启用 SimpleMembership: http://nuget.org/List/Packages/SimpleMembership.Mvc3
这是来自 ASP.NET 的 SimpleMembership API网页/WebMatrix。非常简单且功能齐全。
它也应该与 ASP.NET WebForms 一起使用。
Not sure if you're using ASP.NET WebForms or MVC, but I created a NuGet package to enable SimpleMembership in ASP.NET MVC3: http://nuget.org/List/Packages/SimpleMembership.Mvc3
This is the SimpleMembership API from ASP.NET WebPages/WebMatrix. Very easy and full-featured.
It should work with ASP.NET WebForms as well.
您应该查看这篇文章,其中显示了 simplemembership 的功能,这正是适合您使用的功能
http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5- web-forms-and-asp-net-mvc-4-templates.aspx
you should look at this post which shows the features of simplemembership which is what is suited for your use
http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx