locked
If (Roles.IsUserInRole("Administrator")) Then ........ End If not working once deployed RRS feed

  • Question

  • User-1360958501 posted

    Error is.....System.ComponentModel.Win32Exception: The system cannot find the file specified.

    If (Roles.IsUserInRole("Administrator")) Then......

    Can anyone suggest why this is failing yet works fine on development PC.  Thanks

    Tuesday, July 7, 2020 5:13 AM

Answers

  • User-1360958501 posted

    I've fixed my problem.  It was all to do with me using a mix of Identity 1.0 and Identity 2.0  and probably some earlier authentication approaches

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 12, 2020 11:06 PM

All replies

  • User288213138 posted

    Hi geoffHome,

    System.ComponentModel.Win32Exception: The system cannot find the file specified

    If (Roles.IsUserInRole("Administrator")) Then.

    Can you show me a screenshot of your error message?

    Is this error caused by this row of code?

    Usually, this error is caused by the connectionstring.

    Best regards,

    Sam

    Tuesday, July 7, 2020 10:29 AM
  • User-1360958501 posted
    Thanks Sam.
    It seems that 'Roles.IsUserInRole' is the line causing the error.  Any reference to Role identity seems to be the cause of the error.
    When I remove reference to Roles the problem goes.
    If an folder is protected by <authorization>
    <allow roles="Administrator" />
    <deny users="*" />
    </authorization> via the web.config the error happens. Yet everything works fine on my development PC.
    I'm doing something wrong wrt use of Roles but what is it.  Something must have changed?. 
    My connection string is correct. 
    Any suggestions most welcome.
    [Win32Exception (0x80004005): The system cannot find the file specified]
    
    [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
       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) +947
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +342
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +726
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +91
       System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +438
       System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +79
       System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +201
       System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +156
       System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +22
       System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +92
       System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +219
       System.Data.SqlClient.SqlConnection.Open() +101
       System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +90
       System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +249
       System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) +845
       System.Web.Security.RolePrincipal.IsInRole(String role) +9820365
       System.Web.Security.Roles.IsUserInRole(String username, String roleName) +320
       System.Web.Security.Roles.IsUserInRole(String roleName) +22
    Thursday, July 9, 2020 3:17 AM
  • User-1360958501 posted

    Sorry about the markups (thats the type of day(s) I'm having !

    Thursday, July 9, 2020 3:21 AM
  • User288213138 posted

    Hi geoffHome,

    When I remove reference to Roles the problem goes.If an folder is protected by via the web.config the error happens. Yet everything works fine on my development PC.

    In the iis request filtering, the web.config cannot be accessed. you can remove it in the request filtering.

    Best regards,

    Sam

    Thursday, July 9, 2020 6:32 AM
  • User-1360958501 posted

    I've fixed my problem.  It was all to do with me using a mix of Identity 1.0 and Identity 2.0  and probably some earlier authentication approaches

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 12, 2020 11:06 PM