1

I have actually two projects... an MVC project and a project used for making my own MembershipProvider.

I wish the project that hold the membershipprovider to read my web.config from the MVC project to get the connectionString.

In other words.. when i add the assembly to my project MVC it must be able to go to the web.config and get the connectionString from there.

Rushino
  • 9,415
  • 16
  • 53
  • 93

1 Answers1

2

It is completely possible to read the web.config if your code is on a separate assembly or not.

For example, Entity Framework data models are usually put a separate project so that it could be reusable and entity framework model needs a connection string from web.config unless you provide one inside the constructor.

As an instance, the below method will return connectionString named myConn:

public string GetMyConn() { 

    return System.Configuration.
        ConfigurationManager.ConnectionStrings["MyConn"].ToString();
}

UPDATE

I am not sure what do you want here but if you want to make the ConnectionString name changeable, do it this way:

public string GetMyConn(string connStr) { 

    return System.Configuration.
        ConfigurationManager.ConnectionStrings[connStr].ToString();
}

The point here is that you can access them from a different assembly as well.

tugberk
  • 57,477
  • 67
  • 243
  • 335