Not able to get connection string from Web.config file in asp.net 4.5

asp.netasp.net-mvc-4connection-stringweb.config

Currently I'm trying to connect SQL server DB from asp.net 4.5, keeping the connection string on Web.config file, using the following code to retrieve the connection string, but its retunr NULL value,

ConnectionStringSettings connString = ConfigurationManager.ConnectionStrings["ConString"];                 
SqlConnection Con = new SqlConnection(connString.ConnectionString);

the connection string in Web.Config is like

<connectionStrings>
  <add name="ConString" 
    connectionString="Data Source=myservername;Initial Catalog=dbname;User ID=userid;Password=password;Integrated Security=True" 
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings> 

I'm not understanding why it return null value, previously, in 3.5 I have used the following code to get the connection string,

Con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

it was working fine asp.net 3.5, but this also getting runtime error while using. Please let me know if I did any mistake.

Best Answer

Although, this is a mere suggestion/things to check, I am adding this as an answer

1) Can you please check if the web.config is at its right location?
2) Also, do you have any web.config (which overrides main web.config) in the same folder as that of your page?