On a non server edition of window operating system, we often got the error.
There are too many people accessing the Web site at this time.
OR
HTTP 403.9 - Access Forbidden: Too many users are connected
Internet Information Services
To increase the connection limit, go to :
1 - Go to directory c:\inetpub\AdminScripts
2 - Execute the following command.
adsutil set w3svc/MaxConnections 40
Tuesday, September 29, 2009
Wednesday, August 26, 2009
Read or Write on Registry in C#
Registry is a special place where applications stores its setting. Although Isolated storage for .net is a preferred way for storing
application settings yet registry has its own benefit. Normally it is difficult to find application created registry entries(if created carefully).
Below is a sample C# code.
//It will create a new subkey if not already created. otherwise it opens the existing one with write access.
RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey("App_Name");
//Suppose i want to save last open time when application opened.
objRegistryKey.SetValue("LastOpenTime", DateTime.Now.ToString());
To get the value from registry, you use
string lastOpenDT = objRegistryKey.GetValue("LastOpenTime") as string;
The GetValue return the object type. you can than cast to the appropriate type.
Don't forget to add Microsoft.Win32 namespace.
For further reading,you can see the following two classess at msdn.
Registry,RegistryKey class.
application settings yet registry has its own benefit. Normally it is difficult to find application created registry entries(if created carefully).
Below is a sample C# code.
//It will create a new subkey if not already created. otherwise it opens the existing one with write access.
RegistryKey objRegistryKey = Registry.CurrentUser.CreateSubKey("App_Name");
//Suppose i want to save last open time when application opened.
objRegistryKey.SetValue("LastOpenTime", DateTime.Now.ToString());
To get the value from registry, you use
string lastOpenDT = objRegistryKey.GetValue("LastOpenTime") as string;
The GetValue return the object type. you can than cast to the appropriate type.
Don't forget to add Microsoft.Win32 namespace.
For further reading,you can see the following two classess at msdn.
Registry,RegistryKey class.
Wednesday, May 20, 2009
multiple submit buttons and the enter key
As you know it is the limitation of asp.net that it has only one form, so if you have another section which needs enter key submission, than you can use default button as used below.
The defaultButton property of Panel or Form is used to ensure Enter Key Submission. Typically people used to Enter Key submission and if it is disabled, it might be annoying certain times.
The defaultButton really provides a way to handle Enter Keys for respective portions of the page when the focus is there.
Example:
<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>
<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>
The defaultButton property of Panel or Form is used to ensure Enter Key Submission. Typically people used to Enter Key submission and if it is disabled, it might be annoying certain times.
The defaultButton really provides a way to handle Enter Keys for respective portions of the page when the focus is there.
Example:
<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>
<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>
Friday, April 24, 2009
Extract links from html in C#
private List ExtractLinks(string html)
{
List links = new List();
string startSquence = "<a";
string endSequence = "</a>";
html = html.ToLower();
while (html.IndexOf("<a") != -1)
{
int start = html.IndexOf(startSquence) ;
int end = html.IndexOf(endSequence, start+startSquence.Length);
//Extract the link, and add it to the list
if (end > start)
{
string link = html.Substring(start, end + endSequence.Length - start);
//Check b
if (link.Substring(1).IndexOf(startSquence) != -1)
{
html = html.Substring(start + startSquence.Length);
continue;
}
if (link != string.Empty)
{
links.Add(link);
}
}
else if (end < start)
{
html = html.Substring(start + startSquence.Length);
continue;
}
//Trim the raw data
html = html.Substring(end + endSequence.Length);
}
return links;
}
{
List
string startSquence = "<a";
string endSequence = "</a>";
html = html.ToLower();
while (html.IndexOf("<a") != -1)
{
int start = html.IndexOf(startSquence) ;
int end = html.IndexOf(endSequence, start+startSquence.Length);
//Extract the link, and add it to the list
if (end > start)
{
string link = html.Substring(start, end + endSequence.Length - start);
//Check b
if (link.Substring(1).IndexOf(startSquence) != -1)
{
html = html.Substring(start + startSquence.Length);
continue;
}
if (link != string.Empty)
{
links.Add(link);
}
}
else if (end < start)
{
html = html.Substring(start + startSquence.Length);
continue;
}
//Trim the raw data
html = html.Substring(end + endSequence.Length);
}
return links;
}
Wednesday, April 22, 2009
how to modify web.config in asp.net using C#
You can modify web.config at run time. For exmaple to add a property in app settings section of web.config, you can use the following c# code
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings.Add("CommentsLimit", "10");
myConfiguration.Save();
To update the existing property:
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings["CommentsLimit"].Value = "20";
myConfiguration.Save();
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings.Add("CommentsLimit", "10");
myConfiguration.Save();
To update the existing property:
Configuration myConfiguration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
myConfiguration.AppSettings.Settings["CommentsLimit"].Value = "20";
myConfiguration.Save();
Thursday, April 9, 2009
virtual keyword in C#
If a base class method is to be overriden, it is defined using the keyword virtual
The class member method may be overriden even if the virtual keyword is not used, but its usage makes the code more transparent & meaningful.
When the override keyword is used to override the virtual method, in a scenario where the base class method is required in a child class along with the overriden method, then the base keyword may be used to access the parent class member. The following example will be helpful to understand.
public class Shape
{
string name;
public virtual void SetName(string name)
{ this.name = name; }
}
public class Circle : Shape
{
//This method is being overriden
public override void SetName(string name)
{
base.SetName("circle"); //We are calling parent class method
}
}
The class member method may be overriden even if the virtual keyword is not used, but its usage makes the code more transparent & meaningful.
When the override keyword is used to override the virtual method, in a scenario where the base class method is required in a child class along with the overriden method, then the base keyword may be used to access the parent class member. The following example will be helpful to understand.
public class Shape
{
string name;
public virtual void SetName(string name)
{ this.name = name; }
}
public class Circle : Shape
{
//This method is being overriden
public override void SetName(string name)
{
base.SetName("circle"); //We are calling parent class method
}
}
Wednesday, April 8, 2009
How to Backup MySQL Database automatically in linux
The command for back up a mysql database is:
15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data '+%m-%d-%Y'`.sql.gz
The first part is "15 2 * * *". The five fields mean "minute, hour, day of month, month, day of week" respectively. The character '*' stands for "any".
The next, "root", means "run following command as root account".
You can use cron job so that it takes backup daily.
15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data '+%m-%d-%Y'`.sql.gz
The first part is "15 2 * * *". The five fields mean "minute, hour, day of month, month, day of week" respectively. The character '*' stands for "any".
The next, "root", means "run following command as root account".
You can use cron job so that it takes backup daily.
Subscribe to:
Posts (Atom)