Caveman's Blog

My commitment to learning.

Archive for March, 2008

Host Multiple Sites from One IP Address

Posted by cavemansblog on March 31, 2008

IIS allows you to assign any number of sites to a single IP address. Host headers can be used to acheive this. When IIS receives a request for a Web page, it looks at the information sent in by the browser. The HTTP header contains the actual domain name requested. IIS uses this to determine which site should answer the request. [1]

Step-by-step procedure about how to configure host header names [1]:

1. Start the Internet Service Manager (Inetmgr.exe).
2. Right-click the Web site to be configured, and then click Properties.
3. On the Web Site tab, select the IP address that the site will use.

Note: if you only have one IP address on the server, select All Unassigned, and set the TCP Port that should be used (usually 80).

4. Click Advanced.
5. In the Multiple identities for this Web Site list, select the identity that you want to use.
6. Click Edit, and then add the desired host header name.

NOTE: If you want this site to respond to more than one host header name, use the Add button to add additional identities to this list. Specify a different host header name for each identity, but be sure to use the same IP address and port.

7. Apply these changes and start the Web site (if it is not already running).
8. Register the host header name with the appropriate name resolution system.

If the computer is on an intranet (a private LAN that uses Internet technology), register it with the intranet’s name resolution system, such as the Windows Internet Name Service (WINS).
If the computer is on the Internet, register the host header name with the Domain Name System (DNS), which is administered by InterNic.

9. After the host header name is registered with the name resolution system, test it from a browser by attempting to browse the host header name. The browser should open the expected Web site.

Reference:
1. Microsoft Help and Support

Posted in IIS, Sudheer Reddy Battula, Web Applications | Tagged: , , | Leave a Comment »

SQL Server: how to print all the column names of a query output

Posted by cavemansblog on March 31, 2008

How to print all the column names of a query output ?

DECLARE @Fields as NVARCHAR(3000)
set @Fields = ''SELECT @Fields = @Fields + ', ' + COLUMN_NAME FROM .INFORMATION_SCHEMA.COLUMNS
where Table_Name = 'Employee'

print SUBSTRING(@Fields, 3, len(@Fields))

–OutPut
–emp_id, emp_name, emp_age, emp_salary

how to return multiple rows of a query output as one string?

DECLARE @SingleLine varchar(100)
SELECT top 10 @SingleLine = COALESCE(@EmployeeList + ', ', '') +
CAST(account_num AS varchar(5))
FROM cl_accountSELECT @SingleLine

--OutPut
--*, 70, 71, 72, 73, 74, 75, 76, 77, 78

Posted in Sql Server, Sudheer Reddy Battula | Tagged: , | Leave a Comment »

Replace special characters in XML, using C#

Posted by cavemansblog on March 25, 2008

We can use the SecurityElement.Escape method to replace the invalid XML characters in a string with their valid XML equivalent [1]. The following table shows the invalid XML characters and their respective replacements.

invalid XML Character

Replaced With

“<”

“&lt;”

“>”

“&gt;”

“\”"

“&quot;”

“\’”

“&apos;”

“&”

“&amp;”


//Usage
srtXML = SecurityElement.Escape(strXML);

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

I have used the HttpUtility classes UrlEncode and UrlDecode methods to handle cross-site scripting attacks and this also helped me to get rid of the XmlException – “Data at the root level is invalid”.

Reference:
1. MSDN

Posted in General Programming, Sudheer Reddy Battula | Tagged: , | Leave a Comment »

Cookie Viewer

Posted by cavemansblog on March 14, 2008

During the development of a web application that supports cookies, it is almost always a necessity to have the knowledge of what is being persisted in the cookie.

Okay…. what options does one have to achieve this?

hmm….. lets see… well I can think of three ways of doing this:

1. Write a web page application to read all the cookie key/value pairs and display them.
2. Write a windows application to read all the cookie key/value pairs and display them.
3. Open the cookie file manually and go through the content.

I have been there and done that … I mean during the course of my s/w development activities in the past I have myself implemented all three ways that I mentioned above and yet was not happy with the ease of use.

What if I could find some freeware that does the hard part of fetching all the cookies and enumerating them on a pane that is visually appealing.

Finally !!! I have stumbled on one such freeware utility called IE Cookies Viewer. This utility that displays the details of all cookies that Internet Explorer stores on your computer.


Following are a few things that this utility allows you to do:

1. Sort the cookies list by any column you want, by clicking the column header. A second click sorts the column in descending order.
2. Find a cookie in the list by specifying the name of the Web site.
3. Select and delete the unwanted cookies.
4. Save the cookies to a readable text file.
5. Copy cookie information into the clipboard.
6. Automatically refresh the cookies list when a Web site sends you a cookie.
7. Display the cookies of other users and from other computers.
8. Open the IECookiesView utility directly from Internet Explorer toolbar.
9. Change the content of a cookie !
10. Export your cookies to Netscape/Mozilla cookies file.
11. Block specific Web sites from using cookies through the cookies blocking mechanism of Internet Explorer 6.0.

It can be downloaded at NirSoft. This site has a lot of some cool stuff/utilities that is free for download.

ASP.Net Permanent Cookie vs Temporary Cookie (Update: 03/17/08)

When a cookie is assigned a value without defining the “Expires” property, that cookie would expire as soon as the browser is closed and will be called as a temporary cookie.

A permanent cookie is one where the “Expires” property is defined for that cookie, it will be persisted on the client computer and will expire as per the definition of the “Expires” property.

Internet Explorer on Windows (XP/2000/2003) writes its cookies in the C:\Documents and Settings\[user_name]\Cookies folder.

References:
1. NirSoft

Posted in Cookies, Sudheer Reddy Battula, Tools | Tagged: , | Leave a Comment »