Sunday, July 15, 2007

Design Time Debugging during server control development in asp.net2.0

Design Time Debugging during server control development in asp.net2.0 in Visual Studio 2005
source:
http://brennan.offwhite.net/blog/2006/08/30/design-time-debugging-aspnet-20-in-visual-studio-2005/

Rules for better software development

Rules to follow for the whole software development life cycle.You will find rules to follow for Management, Application Design, Website, Communication, Networking, Third Party product, Testing, Documentation etc.


Friday, July 13, 2007

ASP.NET Website Paths


Determining Physical Path of an Application

The MapPath method returns the complete physical path for a virtual path that you pass to the method. For example, the following code returns the file path for the root of your Web site:
String rootPath = Server.MapPath("~");

Client Elements

Elements that are not Web server controls on a page—client elements—are passed through as-is to the browser. Therefore, when referring to a resource from a client element, you construct paths according to standard rules for URLs in HTML. You can use a fully qualified (which is also known as absolute) URL path or various types of relative paths. For example, if your page contains an img element, you can set its src attribute using one of the following paths:

1) An absolute URL path. An absolute URL path is useful if you are referencing resources in another location, such as an external Web site.
img src="http://www.yahoo.com/MyApplication/Images/SampleImage.jpg"

2) A site-root relative path, which is resolved against the site root (not the application root). Site-root relative paths are useful if you keep cross-application resources, such as images or client script files, in a folder that is located under the Web site root.

This example path assumes that an Images folder is located under the Web site root.
img src="/Images/SampleImage.jpg"

Here, If your Web site is http://www.yahoo.com, the path would resolve to the following.
http://www.yahoo.com/Images/SampleImage.jpg

3) A relative path that is resolved against the current page path.
img src="Images/SampleImage.jpg"

4) A relative path that is resolved as a peer of the current page path.
img src="../Images/SampleImage.jpg"


Server Controls

Absolute and relative path references in a server control have the following disadvantages:

i) Absolute paths are not portable between applications. If you move the application that the absolute path points to, the links will break.

ii) Relative paths in the style of client elements can be difficult to maintain if you move resources or pages to different folders.

To overcome these disadvantages, ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.

The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.
asp:image runat="server" id="Image1" ImageUrl="~/Images/SampleImage.jpg"

Difference between "==" and "object.equalsto"

What is the difference between "==" and "object.EqualsTo"

"==" Vs "Object.EqualsTo"

'==' only compares the value where as 'object.equalsto' compares the both value as well as type

Both are used for comparison and both returns the boolean value (true/false)

Case 1. In case a and b both are different datatype then also a.Equals(b) can be used to compare but incase of == we cant even compile the code if a and b are different data type

Example1 for "==" Vs "Object.EqualsTo":

int a=0;
string b="o";

if(a.Equals(b))
{
//do something
}

//above code will compile successfully and internally the int b will convert to object type and compare

if(a==b)
{
//do something
}
//above code will give you the compilation error


Case 2. by using == we cant compare two object but Equals method will able to compare both the object internally

Example 2 for "==" Vs "Object.EqualsTo":
a==b is used to compare references where as a.Equals(b) is used to compare the values they are having.
for e.g

class Mycar
{
string colour;
Mycar(string str)
{
colour = str;
}
}

Mycar a = new Mycar("blue");
Mycar b = new Mycar("blue");
a==b // Returns false
a.Equals(b) // Returns true