To provide authentication mechanism on Intranet websites is pretty easy. Use LDAP and all the users accessing your application on the Intranet get authenticated automatically. But how to achieve this in the internet scenario ??
It might happen that your application needs to be SCALABLE to allow your Windows domain users to access the website from internet. To achieve this, you just need to tweak the webconfig a bit with the entries shown below
Happy Coding :)
Sunday, April 3, 2011
Solution for System.IO.IOException: The device is not ready. error
Many times our applications refer a file on disk. At the time of development, most of the developers refer to the file by it's absolute path.
The trap here is, the absolute path on the development environment most of the times differ from the path on the deployment server. So though you're able to build and ship the DLLs you will always encounter a runtime error. Thats simply because the AppDomain is not able to locate the file from the path you mentioned. Moreover, the path does not exist in itself :P
So to get rid of this scenario always use Server.MapPath which would resolve the file path on the server. Also refer the url below for code snippets.
Server.MapPath example
Happy Coding :)
The trap here is, the absolute path on the development environment most of the times differ from the path on the deployment server. So though you're able to build and ship the DLLs you will always encounter a runtime error. Thats simply because the AppDomain is not able to locate the file from the path you mentioned. Moreover, the path does not exist in itself :P
So to get rid of this scenario always use Server.MapPath which would resolve the file path on the server. Also refer the url below for code snippets.
Server.MapPath example
Happy Coding :)
Saturday, February 19, 2011
How to use different target framework in Visual Studio 2010
In VS 2010 there is one beautiful feature wherein you can execute your legacy applications along with your new apps. This is possible because of the multi-targeting feature available in VS 2010.
Now you can decide which .Net Framework to use for your code through VS 2010.
Just Go to Solution Explorer -> Properties -> Build -> Target Framework.
You're done with it !!!
Now you can decide which .Net Framework to use for your code through VS 2010.
Just Go to Solution Explorer -> Properties -> Build -> Target Framework.
You're done with it !!!
How to fetch value from dynamically created control
There are some cases wherein you can not create the controls to display data at compile time. For example, displaying values from a Hashtable in a TextBox control, you never know how many key-pairs you are going to deal with (provided the Hashtable contains dynamic data). The logic for displaying the data is pretty much simple. You create an array of TextBoxes or any other control to display the data and you are done with it.
But the main problem lies in fetching the data which might have got changed from the UI. If you try to find out the TextBox controls from Page.FindControl() you won't be able to do so, thats because there isn't any markup for the FindControl() to look for and thats why it will always be null.
So to tide over your problem you can simple fetch the value from just one line
Request.Form[yourcontrolID]
The Request object as we all know is base of the web architecture. So whatever is being communicated between client and a Server has to have its presence in the Request object. Technically speaking whatever controls you can find in the html markup of you page on the client side will be available in this Request object.
Happy Coding :)
But the main problem lies in fetching the data which might have got changed from the UI. If you try to find out the TextBox controls from Page.FindControl() you won't be able to do so, thats because there isn't any markup for the FindControl() to look for and thats why it will always be null.
So to tide over your problem you can simple fetch the value from just one line
Request.Form[yourcontrolID]
The Request object as we all know is base of the web architecture. So whatever is being communicated between client and a Server has to have its presence in the Request object. Technically speaking whatever controls you can find in the html markup of you page on the client side will be available in this Request object.
Happy Coding :)
Saturday, January 8, 2011
Compatibility between data types in Java and .Net
Recently I came across an interesting scenario where a Java app was consuming a .Net webservice. The challenge here was to consume a DataSet returned from a webmethod written in .Net to the calling Java UI.
One approach is to return the data in plain XML which can be done by GetXML() of the dataset but this was not acceptable. So I did a search on some similar scenarios and found out one link which lists the compatibility between different data types .. sor of a rule book you can use when you have Java UI/.Net webservice to a .Net UI/Java webservice.
http://msdn.microsoft.com/en-us/netframework/gg413252
Happy coding :)
One approach is to return the data in plain XML which can be done by GetXML() of the dataset but this was not acceptable. So I did a search on some similar scenarios and found out one link which lists the compatibility between different data types .. sor of a rule book you can use when you have Java UI/.Net webservice to a .Net UI/Java webservice.
http://msdn.microsoft.com/en-us/netframework/gg413252
Happy coding :)
Tree node event for fetching the selected node
Back after one year of CHANGE !!!
A few days ago one of my friend had a question about tree node, he wanted to copy the text of selected node else the app should not copy. So I did some R&D on events available with tree node. Its the OnSelectedNodeChanged..
Here is sample code for the same :)
*********ASPX Code****************
***************************************
*****Code behind***********
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind_tree();
}
}
public void Bind_tree()
{
DataTable dt = Get_District();
for (int i = 0; i < dt.Rows.Count; i++)
{
TreeNode no = new TreeNode();
no.Text = dt.Rows[i]["District"].ToString();
no.Value = dt.Rows[i]["District"].ToString();
Get_allNodes(no);
this.TreeView1.Nodes.Add(no);
}
}
public void Get_allNodes(TreeNode no)
{
DataTable dt = Get_Arealist();
DataRow[] rows = dt.Select("District='" + no.Value + "'");
for (int i = 0; i < rows.Length; i++)
{
TreeNode child = new TreeNode();
child.Text = rows[i]["Area"].ToString();
child.Value = rows[i]["Area"].ToString();
no.ChildNodes.Add(child);
Get_allNodes(child);
}
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_District()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "District_1,District_2,District_3";
string ID = "1,2,3";
string[] list1 = Name.Split(',');
string[] list2 = ID.Split(',');
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["District"] = list1[i];
dr["ID"] = list2[i];
dt.Rows.Add(dr);
}
return dt;
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_Arealist()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "Area_1,Area_2,Area_3,Area_4,Area_5";
string Dis = "District_1,District_1,District_1,District_3,Area_1";
string ID = "1,2,3,4,5";
string[] list1 = Name.Split(',');
string[] list2 = Dis.Split(',');
string[] list3 = ID.Split(',');
dt.Columns.Add(new DataColumn("Area"));
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["Area"] = list1[i];
dr["District"] = list2[i];
dr["ID"] = list3[i];
dt.Rows.Add(dr);
}
return dt;
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
TreeNodeCollection ts = null;
if (e.Node.Parent == null)
{
ts = ((TreeView)sender).Nodes;
}
else
ts = e.Node.Parent.ChildNodes;
foreach (TreeNode node in ts)
{
if (node == e.Node)
{
node.Expand();
}
else
{
node.Collapse();
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNodeEventArgs xm = new TreeNodeEventArgs(this.TreeView1.SelectedNode);
TreeView1_TreeNodeExpanded(sender, xm);
string value = this.TreeView1.SelectedNode.Text;
this.Label1.Text = value;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Ming", "Getvalue('" + value + "')", true);
}
Happy Coding :)
A few days ago one of my friend had a question about tree node, he wanted to copy the text of selected node else the app should not copy. So I did some R&D on events available with tree node. Its the OnSelectedNodeChanged..
Here is sample code for the same :)
*********ASPX Code****************
***************************************
*****Code behind***********
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind_tree();
}
}
public void Bind_tree()
{
DataTable dt = Get_District();
for (int i = 0; i < dt.Rows.Count; i++)
{
TreeNode no = new TreeNode();
no.Text = dt.Rows[i]["District"].ToString();
no.Value = dt.Rows[i]["District"].ToString();
Get_allNodes(no);
this.TreeView1.Nodes.Add(no);
}
}
public void Get_allNodes(TreeNode no)
{
DataTable dt = Get_Arealist();
DataRow[] rows = dt.Select("District='" + no.Value + "'");
for (int i = 0; i < rows.Length; i++)
{
TreeNode child = new TreeNode();
child.Text = rows[i]["Area"].ToString();
child.Value = rows[i]["Area"].ToString();
no.ChildNodes.Add(child);
Get_allNodes(child);
}
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_District()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "District_1,District_2,District_3";
string ID = "1,2,3";
string[] list1 = Name.Split(',');
string[] list2 = ID.Split(',');
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["District"] = list1[i];
dr["ID"] = list2[i];
dt.Rows.Add(dr);
}
return dt;
}
// You can get the data from your own database.
// I get the datatable like this in order to run the sample more conveniently.
public DataTable Get_Arealist()
{
DataTable dt = new DataTable();
DataRow dr;
string Name = "Area_1,Area_2,Area_3,Area_4,Area_5";
string Dis = "District_1,District_1,District_1,District_3,Area_1";
string ID = "1,2,3,4,5";
string[] list1 = Name.Split(',');
string[] list2 = Dis.Split(',');
string[] list3 = ID.Split(',');
dt.Columns.Add(new DataColumn("Area"));
dt.Columns.Add(new DataColumn("District"));
dt.Columns.Add(new DataColumn("ID"));
for (int i = 0; i < list1.Length; i++)
{
dr = dt.NewRow();
dr["Area"] = list1[i];
dr["District"] = list2[i];
dr["ID"] = list3[i];
dt.Rows.Add(dr);
}
return dt;
}
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
TreeNodeCollection ts = null;
if (e.Node.Parent == null)
{
ts = ((TreeView)sender).Nodes;
}
else
ts = e.Node.Parent.ChildNodes;
foreach (TreeNode node in ts)
{
if (node == e.Node)
{
node.Expand();
}
else
{
node.Collapse();
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNodeEventArgs xm = new TreeNodeEventArgs(this.TreeView1.SelectedNode);
TreeView1_TreeNodeExpanded(sender, xm);
string value = this.TreeView1.SelectedNode.Text;
this.Label1.Text = value;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Ming", "Getvalue('" + value + "')", true);
}
Happy Coding :)
Monday, January 4, 2010
How to debug Windows service
In web apps we generally press F5 or attach the process for debugging but what to do when it comes to Windows services ???
You"ll come across docs which tell you to do loads of steps for that, but I prefer the most easy way ;)
The process of attaching debugger can be done in just ONE simple line. Use
System.Diagnostics.Debugger.Launch()
The Launch() is a static method of Debugger class. It initializes the debugger.
Now where to put this line ?? Well I prefer in the OnStart() of the Windows service which acts as a starting point of the service.
So you are all set with debugging the Windows service. Happy Debugging :)
You"ll come across docs which tell you to do loads of steps for that, but I prefer the most easy way ;)
The process of attaching debugger can be done in just ONE simple line. Use
System.Diagnostics.Debugger.Launch()
The Launch() is a static method of Debugger class. It initializes the debugger.
Now where to put this line ?? Well I prefer in the OnStart() of the Windows service which acts as a starting point of the service.
So you are all set with debugging the Windows service. Happy Debugging :)
Subscribe to:
Posts (Atom)

