How does the connection for OpenAuth Get Defined in Visual Studio Asp.Net Template

StackOverflow https://stackoverflow.com/questions/19156209

  •  30-06-2022
  •  | 
  •  

Pregunta

Can anybody tell me where the connection details for OpenAuth get defined?

I know that it requires a connectionstring called "DefaultConnection" and that is provided as a default in the web.config however I can't find where OpenAuth defines that it needs a connectionstring call DefaultConnection.

In web.config if you change the name of DefaultConnection to something else and then change the ConnectionString in the membership, roleManager and profile sections to match your new connectionString everything still works as you would expect. However, OpenAuth will no longer work as it expects a connectionstring called DefaultConnection, but it won't give you a sensible error message on build, instead at runtime you will get a very long and complicated error message saying that it can't find the database etc.

I found out this the hard way.

Currently to get around this I have two connectionstrings with the same details which is rather pointless.

Does anybody know?

¿Fue útil?

Solución

The static class OpenAuth has a static string property named ConnectionString. It is initialized to the hardcoded value of "DefaultConnection" in the OpenAuth constructor. You can set it to your own value anytime after that.

namespace Microsoft.AspNet.Membership.OpenAuth
{
    public static class OpenAuth
    {
        public static AuthenticationClientManager AuthenticationClients { get; }
        public static string ConnectionString { get; set; }
        public static string UsersAccountsTableName { get; set; }
        public static string UsersDataTableName { get; set; }
        //....
    }
}

Otros consejos

If you just add the default connection string to your web config it will work. This is the same as the regular one you use to connect to your database.

<add name="DefaultConnection" 
providerName="System.Data.SqlClient" 
connectionString="Data Source=xxxx;Initial Catalog=yyy;
Persist Security Info=True;User ID=your username;Password=password"/>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top