Translate

Thursday 4 October 2012

Web Config Helps


1. Connection String:


<connectionStrings>
    <add name="constr"  connectionString="Initial catalog=DB_Name;uid=sa;pwd=Password;Data Source=Server_IP" providerName="System.Data.SqlClient"/>
  </connectionStrings>


2.  Error - Operation is not valid due to the current state of the object

Whenever a postback is done, this error occurs when form fields are very large (text) in number. The stack trace is:
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection()
By default, the maximum value of MaxHttpCollection is 1000.
To solve this error, increase the MaxHttpCollection value. Try adding the following setting in yourweb.config's <appsettings> block.
  <configuration>
      <appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="9999" />
  </appSettings>
</configuration>
It can solve your problem. If you have very large records on your page, say 600 records in a grid, and you click on Submit, then increase the value of MaxHttpCollection.

2. EnCrypt and Decrypt of Connection String in webconfig:

Encrypt connectionStrings in web.config of IIS based site
 
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
aspnet_regiis.exe -pe "connectionStrings" -app "/SampleWebSite"
Here –pe indicates that the application is built as IIS based site. Second argument connectionStrings is the name ofconfiguration section needs to be encrypted. The Third argument -app indicates virtual directory and last argument is the name of virtual directory where application is deployed.
 
Decrypt connectionStrings in
 web.config of IIS based site
 
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
aspnet_regiis.exe -pd "connectionStrings" -app "/SampleWebSite"
Till now we learned how to encrypt and decrypt connectionStrings section in web.config file using aspnet_regiis.exe command line tool now I will explain code behind method to encrypt and decrypt the connection string section inweb.config.

3. How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
Or

CurrentCulture incorrectly defaulting to en-US in ASP.net


<globalization uiCulture="en" culture="en-US" />

4. How to increase Session Timeout:

<httpRuntime executionTimeout="999999" maxRequestLength="2097151"/>

5. How to Set: Dundas chart Temporary location, Default Excel version , Date and Time in Web config.

<appSettings>
    <add key="CommandTimeout" value="60000"/>
    <add key="DefaultDate" value="12/30/1899"/>
    <add key="DefaultTime" value="12/30/1899"/>
    <add key="OLEDBConnection2" value="Microsoft.Jet.OLEDB.4.0"/>
    <add key="OLEDBConnection" value="Microsoft.ACE.OLEDB.12.0"/>
    <add key="ExcelVersion" value="Excel 12.0"/>
    <add key="ChartHttpHandler" value="Storage=memory;Timeout=180;Url=~/temp/;"/>
</appSettings>