Two Instance of membership provider in ASP.NET - asp.net-membership

I am in between of some application and found one scenario which i can not get through.
In my ASP.NET 2.0 webiste, i have implemented membership for user management. I currently have two providers registered in web.config file.
Provider for Active Directory - Default
Provider Connected with SQL DB
As i mentioned, my default provider is active directory provider. My server just got disconnected for maintenance and i found that my web site started throwing exceptions. As my default provider is active directory one, when i try to get secondary provider which is actually for SQL db,
var oProvider = Membership.Providers["MyMembershipProvider"];
my application throws error "The server is not operational."
I suspect that when i execute the above line of code, membership creates instances for all the registered providers.
Question:
Is there any way i can create object of the particular provider registered in web.config and avoid this error?
How can i create a dynamic object of provider from the provider name?
How can i ignore the providers which are not accessible or down?

Related

set up MVC .NET application with Azure Connected Services

What we are trying to do is set up our MVC .NET application with Azure Connected Services within Visual Studio. We are trying to connect to the Existing Azure AD Application. We have the correct domain selected, and also the correct redirect URI
We need to be able to read directory data to determine user group but we don’t have client secret
This is the error we get
Make sure your existing Azure AD application is registered as:
Accounts in this organizational directory only (Devchat only - Single tenant) or Accounts in any organizational directory (Any Azure AD directory - Multitenant).
Other types are not supported to be updated in this case.
You can refer to this document to register an application for a quick test.

Directory Listing Denied with custom application pool identity

I have an ASP.Net MVC3 application that has been running fine in the default Application Pool on my IIS 6 server.
I need to get it running under its own service account, so I created a new Application Pool and moved the application into it. With default settings the application continued to work fine.
I set a custom Identity on the application pool, and the application now just gives me the "Directory Listing Denied" error.
I tried switching the identity back to Network Service, and the application started working again.
What could be preventing the application from running with the custom Identity? It's like ASP.Net is not even starting up.
I've run aspnet_regiis -ga <domain\username> and added the account to the IIS_WPG group, so the identity account should have access to ASP.Net.
More Info
I've been doing some diagnostics with Process Monitor and it shows that aspnet_isapi.dll is not being loaded with the custom identity.
When the identity is "Network Service" I can see aspnet_isapi.dll being loaded followed by webengine4.dll. This happens immediately after the NTLM authentication occurs.
With the custom identity, the NTLM authentication happens and then the w3wp process just starts looking for the default files (Default.aspx, Default.htm, etc).
I've checked, and the account has access to the framework version folder where these DLLs are stored.
you need to give the user that you are specifying in the custom identity explicit read or read/write at the folder level of you application. Right click on the containing folder then "Properties" and add the user with the permissions required by the app to the security tab.
Turns out I needed a wildcard mapping to aspnet.isapi.dll, though I'm not sure why.
Without the custom identity the application works fine without a wildcard mapping. With the custom identity I need the mapping. On another server the custom identity work fine without a mapping. Weird.
Did you already check Directory browse settings?
http://www.iis.net/configreference/system.webserver/directorybrowse
Now that you are using a different user then the default one, make sure that you have set the Anonymous Authentication to use the app pool user. There could also be something related to what #Gabe Thorns mentioned, it might be an issue with wildcard mappings. If you do not have wildcard mappings set to run the asp process then it will try and look for files, avoiding asp processors.
Hope that helps.
Have you explicitly granted permissions to the application pool identity on the application folder?
The account should be something like IIS AppPool\MyAppPoolName
More info on this can be found here:
http://www.iis.net/learn/manage/configuring-security/application-pool-identities

Azure Cloud Services deployment error: "The instance of SQL Server you attempted to connect to does not support encryption. "

We have an ASP.NET MVC 3 web site which isn't working after it's deployed to the Azure Cloud Services. During development, we've been testing it using the Azure Web Sites platform but in order to get the SSL support for our custom domain, we are now trying to deploy it to Web Role in Cloud Services. But the site's database connection to SQL Azure doesn't work, instead we get: "The instance of SQL Server you attempted to connect to does not support encryption." Retrying the connection doesn't work, that error message persists.
To summarize, here's the platforms where the site works and where it doesn't:
Azure Emulator: Works
Azure Web Sites: Works
Azure Cloud Services (Web Role): Doesn't work
The "How to: Connect to Windows Azure SQL Database Using ADO.NET" states that the error "The instance of SQL Server you attempted to connect to does not support encryption." "indicates a failure during the login process, and is not an encryption failure. Beginning in .NET 4.5, ADO.NET displays a better error message." The Azure Cloud Services are limited to .NET 4.0.
The site is using NHibernate to connect to the DB. Here's an error from the log file:
Creating nhibernate session factory failed.
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
Database was not configured through Database method. --->
System.Data.SqlClient.SqlException: The instance of SQL Server you
attempted to connect to does not support encryption. at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject) at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection) at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory) at
System.Data.SqlClient.SqlConnection.Open() at
YoureOnTime.Data.RetryConnectionStringProvider.<>c_DisplayClass2.b_0()
at YoureOnTime.Common.Retry.RequestWithRetry(RetryPolicy retryPolicy,
Action action) at
YoureOnTime.Data.RetryConnectionStringProvider.GetConnection() at
NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare()
at
NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect
dialect, IConnectionHelper connectionHelper) at
NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory
sessionFactory) at
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping
mapping, Settings settings, EventListeners listeners) at
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() ---
End of inner exception stack trace ---
And here's how the connection is defined in the hibernate.xml:
<property name="connection.connection_string">
data source=database.database.windows.net;Initial Catalog=db;User ID=user;Password=password;Encrypt=true;Trusted_Connection=false;MultipleActiveResultSets=True
</property>
Any ideas?
Bases on my previous experience on seeing this error, it is an intermittent occurrence. SQL Database always enforces encryption and if during an early phase of the login process (before authentication) there is a failure, the protocol libraries (client side) will fall back to this error message. As you mentioned it is a misleading message and not related to encryption.
This article described the exact same error and explains how you can solve your problem by adding retry logic. So if you modify your code to use retry logic, after a few failure you may pass this error and get the connection going.

WebSphere database domain error, please help

Has anyone seen the following error before in Websphere 6.1 Portal? What does it mean the database domain is currently unavailable? I tested DB connections via the Websphere console and they all worked. Not sure what database domain means. We saw this for multiple domains.
0000009f DataStoreCont E com.ibm.wps.datastore.impl.DataStoreContext handleException EJPDB0002E: Error occurred during database access.
com.ibm.wps.datastore.domains.DomainUnavailableException: EJPDB0101E: Database domain [Domain: cust] is currently unavailable.
at com.ibm.wps.datastore.impl.DataStoreContext.handleException(DataStoreContext.java:315)
The customization database holds information like users' private pages. In case they can access ie. shared settings their customized page becomes a new private version of the page. An other usage for the customization database are the portlet preferences. The database domain unavailable error message is a very generic way of telling that the database can not be accessed.
As you saw the error messages for several domains I would say your database server crashed. The connection testing feature of WAS only tests connection - not that any queries actually succeed. Such error messages can also be caused by misconfigured HA solutions.

Can't Connect to Database when Web Application is deployed to IIS

i have developed an application and it is working fine but when ever i create a virtual directory for it in IIS and run the application i am getting connection failure exception and named pipes exception.
thanks!
It looks like you having some issue with the database connection from your application. Can you post your code and the exact nature of the error.
Without any code or details of the language it is hard to guess what the issue can be however a common one that occurs with asp.net could be your database connection string. Are you using a SQl Server / Sql Server Express database with your application? You need to check that the connection string.
The problem is the Integrated Security=True setting in your connection string. IIS uses the ASPNET windows login which will be different to the Windows login used when running from VS. You've got a few options:
Grant the ASPNET user the required access rights on your database
Use Sql Server authentication: Set up a user on the database as a sql login and pass this username / password in on the connection string and set Integrated Security=False
Change the identity IIS runs under to one that has access to the DB.
There may be other options also however I think these are most common. Which to choose depends on the architecture you are deploying to, personally I almost always go for Sql Server Authentication using a username and password. The web.config can be encrypted for further security if required.

Resources