asp.net 会员资格 - sql 身份验证

发布于 2024-09-07 04:16:09 字数 544 浏览 2 评论 0原文

我想知道在新网站中设置会员资格的“正确”方法是什么。

当我有新项目时,我可以转到网站/ASP.NET 配置。在那里我可以设置表单身份验证并管理将使用此页面的所有用户。我可以在文件夹上制定角色和规则。所有这些信息都保存到表中,该表将本地保存在数据库 App_Data/ASPNETDB.MDF 中。我想做的是,所有这些信息都将与网站一起位于主机服务器上,但不在本地。

将我在本地创建的网站连接到中央 mssql 服务器的最佳方式是什么?我希望能够进入 asp.net 配置并管理用户,但我希望将数据保存在 mssql 服务器上的表中,而不是保存在 aspnetdb.mdf 文件中。

我已经使用 aspnet_regsql.exe 文件在 mssql 服务器上创建了 asp.net 成员资格表。

更新: 没关系,我找到了解决这个问题的方法。 只需添加 <删除 name="LocalSqlServer"/> 中,然后是我自己的连接字符串。现在它的工作...

I want to know whats the "right" way to setup membership in a new website.

When i have new project i can go to Website/ASP.NET Configuration. There i can setup Forms authentication and manage all users that will be using this page. I can make roles and rules on folders. All of this info are saved into table that will be saved locally in database App_Data/ASPNETDB.MDF. What i'm trying to do is that all this info would be on a host server along with the website but not locally.

What is the best way to connect my website that i made locally to a mssql server that is central. I want to be able to go to the asp.net configuration and manage users but i want the data to be saved in the tables on the mssql server not to the aspnetdb.mdf file.

I have already made the asp.net membership tables on the mssql server by using the aspnet_regsql.exe file.

Update:
Never mind, i found out a way to to this.
Just had to add
<remove name="LocalSqlServer"/>
in <ConnectionStrings> and then my own connection string. Now its working...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满地尘埃落定 2024-09-14 04:16:10

Visual Studio SDK 中有一个名为“aspnet_regsql”的行命令。它会打开一个窗口,您可以使用它在任何 SQL Server 数据库中设置 ASP.NET 成员资格、角色和配置文件支持。

对于大多数应用程序,您可能最终会编写自己的会员管理页面。这并不难,您需要的大部分控件都在 Visual Studio 的工具箱中。以下是我在有关安全性的演示中提供的食谱:

要将 ASP.NET 成员身份和角色添加到现有 SQL Server 数据库:

  1. 打开 Visual Studio 2008 命令窗口。

    (如果您必须在管理员模式下运行 SQL 行命令,您将需要
    以管理员模式打开命令行,然后将路径设置为
    包括 Visual Studio SDK 可执行文件。)

  2. 在该命令窗口中运行 aspnet_regsql。

  3. 对于将使用数据库的 SQL 用户登录名,添加一个或多个
    以下会员提供者角色:

    aspnet_Membership_FullAccess - 如果用户可以自己或其他人注册
    aspnet_Membership_BasicAccess - 用户无法自行注册
    aspnet_Membership_ReportingAccess - 用于成员统计

  4. 对于 SQL 用户登录,添加以下一个或多个角色提供程序角色:

    aspnet_Roles_FullAccess - 创建和删除角色
    aspnet_Roles_BasicAccess - 使用 asp.net 角色

  5. 使用 SQL Server Management Studio 配置初始应用程序和角色:

    exec aspnet_Applications_CreateApplication @ApplicationName='Northwind',@ApplicationID=''

    exec aspnet_Roles_CreateRole @ApplicationName='Northwind', @RoleName='Employee'

    exec aspnet_Roles_CreateRole @ApplicationName='Northwind', @RoleName='Manager'

    exec aspnet_Roles_CreateRole @ApplicationName='Northwind', @RoleName='Master'

  6. 实现您的“New用户”页面,但尚未使用表单授权锁定它。
    您可能想要实现自己的表单,假设您已经存在用户记录
    在您的数据库中,并假设您希望添加角色作为“创建用户”的一部分
    过程。无论如何,请使用此页面为 ASP.NET 创建一组初始用户
    会员资格;这种方式比尝试使其与存储过程一起工作更容易。
    请参阅示例代码,了解不使用 ASP.NET 实现用户创建的情况
    LoginView 控件。

    请注意,示例应用程序中的“添加用户”页面假设了许多事情
    使用 ASP.NET 中的标准登录控件很难做到这一点。如果您要创建用户
    作为一项管理功能,您可能不让用户自行添加
    想要拥有多个角色,并且能够选择角色。更重要的是,
    您的数据库中可能已经建立了“用户”表,并且需要集成
    “新用户”功能,可将记录添加到应用程序的用户表中。这是
    用于创建您自己的登录控件、收集附加数据和
    集成用户记录、ASP.NET 成员记录和 ASP.NET 角色的创建
    作业。所有这些都是在环境事务中完成的,因此它们要么成功
    或作为单个工作单元失败。

  7. 创建用户并将其添加到角色后,您可以设置表单身份验证
    并锁定需要授权的页面。备注:

    a.不需要对顶级目录进行身份验证。此级别的页面
    应可公开访问。
    b.在页面需要身份验证的每个子目录中添加 web.config。
    通常,设置身份验证级别将是这些中的唯一功能
    web.config 文件。

There is a line command in the Visual Studio SDK called "aspnet_regsql". It opens a window, and you can use it to set up the ASP.NET membership, roles, and profile support in any SQL Server database.

For most applications, you'll probably end up writing your own membership admin pages. It's not hard, and most of the controls you need are in the toolbox in Visual Studio. Here's the cookbook I've given in presentations on security:

To add ASP.NET membership and roles to an existing SQL Server database:

  1. Open a Visual Studio 2008 command window.

    (If you must run SQL line commands in Administrator mode, you will need
    to open a command line in administrator mode, then set the path to
    include the Visual Studio SDK executables.)

  2. Run aspnet_regsql in that command window.

  3. For the SQL user logins that will use the database, add one or more
    of the following membership provider roles:

    aspnet_Membership_FullAccess - if users can register themselves or others
    aspnet_Membership_BasicAccess - users cannot register themselves
    aspnet_Membership_ReportingAccess - for membership statistics

  4. For the SQL user logins, add one or more of the following role provider roles:

    aspnet_Roles_FullAccess - create and delete roles
    aspnet_Roles_BasicAccess - use asp.net roles

  5. Configure your initial application and roles using SQL Server Management Studio:

    exec aspnet_Applications_CreateApplication @ApplicationName='Northwind',@ApplicationID=''

    exec aspnet_Roles_CreateRole @ApplicationName='Northwind', @RoleName='Employee'

    exec aspnet_Roles_CreateRole @ApplicationName='Northwind', @RoleName='Manager'

    exec aspnet_Roles_CreateRole @ApplicationName='Northwind', @RoleName='Master'

  6. Implement your "New User" page, but don't lock it down with forms authorization yet.
    You may want to implement your own form, assuming you have user records already existing
    in your database, and assuming that you'd like to add roles as part of the "create user"
    process. In any case, use this page to create an initial set of users for ASP.NET
    membership; it's easier this way than trying to make it work with stored procedures.
    See sample code for an implementation of user creation without using the ASP.NET
    LoginView control.

    Note that this "Add a User" page in the sample application assumes a number of things
    that are hard to do with the standard Login control in ASP.NET. If you're creating users
    as an administrative function, rather than letting users add themselves, you probably
    want to have multiple roles, and be able to select the role. Even more important,
    you may have "user" tables already established in your database, and need to integrate
    "new user" functionality with adding records to your application's user table. This is
    a prototype for creating your own Login control, collecting additional data and
    integrating the creation of user records, ASP.NET membership records, and ASP.NET role
    assignments. All of this is done within an ambient transaction, so they either succeed
    or fail as a single unit of work.

  7. Once you've created users and added them to roles, you can set up forms authentication
    and lock down your pages that require authorization. Notes:

    a. Don't require authentication for your top-level directory. Pages at this level
    should be publicly accessible.
    b. Add a web.config in each subdirectory where pages require authentication.
    Usually, setting the authentication level will be the only function in these
    web.config files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文