VB.Net表单身份验证-Roles.CreateRole()

问题描述 投票:0回答:1

因此,我最近开始将我的应用程序移交给我的非托管用户使用的更安全的身份验证系统。我看到了VB.Net的表单身份验证,并且没有任何入门问题。我创建了两个新用户,并使用有效的密码重置登录。

我只是尝试使用Roles.CreateRole函数创建一个简单的角色,并且通过与app_data权限相关的错误来创建它。

我已经尝试了50多篇文章,从Windows XP时代删除APP_Data中的SQL文件夹的人,但这对我不起作用。我尝试查找错误引用的自述文件,但是在Visual Studio文件中有超过400多个自述文件,我在查找该信息时迷失了方向。我还尝试过将IIS应用程序池标识更改为本地用户,然后重新启动了整个PC。

[如果有人知道此错误引用的自述文件在哪里,我会很乐意首先阅读。

这里是我尝试运行代码的子目录,当我调用Roles.CreateRole时会引发错误

        Protected Sub gvUsers_RowCommand(sender As Object, e As GridViewCommandEventArgs)
        Dim strUsername = CType(sender, GridView).Rows(e.CommandArgument).Cells(0).Text
        Dim intLevel = Convert.ToInt16(CType(sender, GridView).Rows(e.CommandArgument).Cells(1).Text)
        Dim objMembers = Membership.FindUsersByName(strUsername)
        Dim objUser As MembershipUser = objMembers(strUsername)

        If e.CommandName = "Reset Password" Then
            lblError.Text = "Reset password for: <b>" & strUsername & "</b> New Password: <b>" & objUser.ResetPassword() & "</b>"
        ElseIf e.CommandName = "Delete" Then
            lblError.Text = "Deletion request for user: <b>" & strUsername & "</b> resulted in a <b>" & Membership.DeleteUser(strUsername).ToString & "</b> result."
        ElseIf e.CommandName = "Increase" Then
            Roles.CreateRole("MoldMaintAdmin")
            Roles.AddUserToRole(strUsername, "MoldMaintAdmin")
        ElseIf e.CommandName = "Decrease" Then
            Roles.CreateRole("MoldMaintUser")
            Roles.AddUserToRole(strUsername, "MoldMaintUser")
        End If

    End Sub

这是详细的错误。

Server Error in '/' Application.
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.


Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException (0x80131904): Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) +907
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +5968584
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +507
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +443
   System.Data.SqlClient.SqlConnection.Open() +96
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +75

[HttpException (0x80004005): Unable to connect to SQL Server database.]
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +125
   System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +89
   System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +29
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +386

这里是webconfig

<?xml version="1.0" encoding="utf-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="AuthServices" connectionString="Data Source=localhost\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=authentication;" />
  </connectionStrings>
  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="login.aspx" defaultUrl="main.aspx" />
    </authentication>
    <authorization>
      <allow users="?"/>
      <!--<deny users="?"/>-->
    </authorization>
    <membership defaultProvider="AuthServices" userIsOnlineTimeWindow="30">
      <providers>
        <add
          name="AuthServices"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="AuthServices"
          applicationName="MoldMaint"
          enablePasswordRetrieval="false"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="false"
          requiresUniqueEmail="false"
          passwordFormat="Hashed"
          maxInvalidPasswordAttempts="5"
          passwordAttemptWindow="10" />
      </providers>
    </membership>
    <roleManager
    enabled="true"
    cacheRolesInCookie="true" >
      <providers>
        <add name ="AuthServices"
             type="System.Web.Security.SqlRoleProvider"
             connectionStringName="AuthServices"
             applicationName="MoldMaint"/>
      </providers>
    </roleManager>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.7.2"/>
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

</configuration>
vb.net
1个回答
0
投票

下的角色管理器部分中,在角色管理器内添加默认提供程序。我已经在原始帖子顶部的连接字符串部分中声明了“ AuthServices”。

<roleManager defaultProvider="AuthServices" enabled="true" cacheRolesInCookie="true">
  <providers>
    <add name ="AuthServices"
         type="System.Web.Security.SqlRoleProvider"
         connectionStringName="AuthServices"
         applicationName="MoldMaint"/>
  </providers>
</roleManager>
© www.soinside.com 2019 - 2024. All rights reserved.