using System.Web.Security;
using System.Configuration;
using System.Web.Configuration;
Encrypt
Configuration Myconfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = Myconfig .GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
Myconfig .Save();
}
Decrypt
Configuration Myconfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = Myconfig .GetSection("connectionStrings");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
Myconfig .Save();
}
Note
once the data is encrypted, when it's read from an ASP.NET page (i.e., reading the connection string
information from a SqlDataSource control or programmatically, via ConfigurationManager.ConnectionStrings[connStringName].ConnectionString),
ASP.NET automatically decrypts the connection string and returns the plain-text value.
Showing posts with label webconfig. Show all posts
Showing posts with label webconfig. Show all posts
Saturday, April 25, 2009
Tuesday, September 30, 2008
how to omit some files from form authentication
<location path="Default.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
If u want to omit more than one files from form authentication then put all the file within on
common folder and replace the <location path="Default.aspx">
<location path="public/">, here public is the name of the folder
<location path="public/">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
If u want to omit more than one files from form authentication then put all the file within on
common folder and replace the <location path="Default.aspx">
<location path="public/">, here public is the name of the folder
<location path="public/">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
Wednesday, April 9, 2008
How To Create User Defined Tag In WebConfig
WebConfig
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="YourTagName" type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
.
.
.
.
</configSections>
<appSettings>
.
.
.
</appSettings>
<YourTagName>
<add key="YourKeyName1" value="Xploredotnet"/>
<add key="YourKeyName2" value="adminpwd"/>
</YourTagName>
.
.
.
.
.
</configuration>
<configuration>
<configSections>
<section name="YourTagName" type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
.
.
.
.
</configSections>
<appSettings>
.
.
.
</appSettings>
<YourTagName>
<add key="YourKeyName1" value="Xploredotnet"/>
<add key="YourKeyName2" value="adminpwd"/>
</YourTagName>
.
.
.
.
.
</configuration>
Code Behind
This is one of the way to access Custom Tag
string AdUrs,AdPwd;
AdUrs = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName1"] +string.Empty;
AdPwd = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName2"] + string.Empty;
AdUrs = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName1"] +string.Empty;
AdPwd = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName2"] + string.Empty;
Friday, November 2, 2007
Dynamically Writing into Web.config File
Inline
XmlDocument xDoc = new XmlDocument(); // Gobal Declaration
string Path; // Gobal Declaration
int i; // Gobal Declaration
protected void Page_Load(object sender, EventArgs e)
{
i = Convert.ToInt32(ConfigurationManager.AppSettings["Test"].ToString());
}
protected void bt1_Click(object sender, EventArgs e)
{
Path = Server.MapPath("~/web.config");
xDoc.Load(Path);
XmlNodeList NodeList = xDoc.GetElementsByTagName("appSettings");
XmlNodeList tNodeList = NodeList[0].ChildNodes;
XmlAttributeCollection xAttColl = tNodeList[0].Attributes;
xAttColl[0].InnerXml = "Test";
xAttColl[1].InnerXml = Convert.ToString(i + 1);
xDoc.Save(Path);
Response.Write(ConfigurationManager.AppSettings["Test"].ToString());
}Web.Config
<configuration>
<appSettings>
<add key="Test" value="0" /> <!-- Add This In Your WebConfig File -->
</appSettings>
</configuration>
Friday, October 5, 2007
set session timeout in webconfig
<configuration>
<system.web>
<sessionState mode="Off|InProc|StateServer|SQLServer"
<!--
Mode : Specifies where to store the session state.
Off : Indicates that session state is not enabled.
InProc : Indicates that session state is stored locally.
StateServer : Indicates that session state is stored on a remote server.
SQLServer : Indicates that session state is stored on the SQL Server.
-->
cookieless="true|false"
<!--
cookieless : Specifies whether sessions without cookies should be used to identify client sessions.
true : Indicates that sessions without cookies should be used.
false : Indicates that sessions without cookies should not be used. The default is false.
-->
timeout="number of minutes"
<!--
timeout : Specifies the number of minutes a session can be idle before it is abandoned. The default is 20.
-->
stateConnectionString="tcpip=server:port"
<!--
stateConnectionString :Specifies the server name and port where session state is stored remotely.
For example, "tcpip=127.0.0.1:42424". This attribute is required when mode is StateServer.
-->
sqlConnectionString="sql connection string"
<!--
sqlConnectionString : Specifies the connection string for a SQL Server.
For example, "data source=localhost;Integrated Security=SSPI;Initial Catalog=northwind".
This attribute is required when mode is SQLServer.
-->
stateNetworkTimeout="number of seconds"/>
<!--
stateNetworkTimeout : When using StateServer mode to store session state,specifies the number of seconds the TCP/IP network connection between the Web server and the state server can be idle before the session is abandoned. The default is 10.
-->
</system.web>
</configuration>
Subscribe to:
Posts (Atom)