Summary
The following article will describe how to use aspNetDns from Visual Studio .NET using C#. This brief tutorial assumes you have IIS installed locally on your machine, and have downloaded and installed aspNetDns from www.aspNetDns.com.
To skip this article, and view to the entire source, go here.
Instructions Using Visual Studio .NET (VS.NET ) You will create a single webform (lookup.aspx) that allows users to perform a Pointer (Reverse Lookup ) of an IP address.. Lookup.aspx will use aspNetDns to perform the reverse lookup.
1. Launch Visual Studio .NET
2. From the main menu, select the File | New | Project command.
3. The New Project dialog box appears. Under Project Types, Select Visual C# Projects. Under Templates, select ASP.NET Web Application. In the Location textbox, enter http://localhost/aspNetDnsTest
Setting the Reference to aspNetDns. There are two ways to set a reference in VS.NET . Because aspNetDns is installed in the GAC (Global Assembly Cache) you can set a reference to the GAC copy, or you can import the aspNetDns.dll to the project and set a reference to the imported copy. We will upload a copy, and set a reference to the imported copy. This method will promote XCOPY deployment. (A comment about licensing: Please be sure you are compliant with your licenses. Check http://www.aspNetDns.com/licen.aspx for more information.)
1. In the Solution Explorer, right-click the project name, aspNetDnsTest, and select the Add | Add Existing Item command.
2. The Add Existing Item dialog box appears. Under Files of Type, select All Files(*.*). Navigate to the aspNetDns install directory. By default, this directory is C:\Program Files\AdvancedIntellect\aspNetDns. Double-click the aspNetDns.dll. The Add Existing Item dialog box closes, and the aspNetDns.dll was imported to the root directory of your project.
3. In the Solution Explorer, right-click the project name aspNetDnsTest and select Add Reference. The Add Reference dialog box appears. Click the Browse button. The Select Component dialog box appears. Double-click the aspNetDns.dll file. The Select Component dialog box closes. Click OK. The Add Reference dialog box closes, and a reference is set to aspNetDns.
Create a Test Page. Now that we have a reference set, let's create lookup.aspx to use aspNetDns.
1. In the Solution Explorer, right-click the project name aspNetDnsTest, and select Add | Add Webform. The Add New Item dialog box appears. In the Name textbox, enter, lookup.aspx.
2. lookup.aspx loads in the designer window. Select the View | Html Source menu command. The html code of lookup.aspx appears. Between the opening and closing form tags add the following html
Please enter an IP Address to lookup: <br> <input type=text id=txtIPAddress runat=server NAME="txtIPAddress"><input type=submit value="submit"> <asp:Literal ID=litMsg Runat=server></asp:Literal>
This code will create a html text box, a submit button, and a <asp:Literal> tag that we will use for writing out a friendly user message.
3. In the Solution Explorer, right-click lookup.aspx, and select View Code.
4. Add the following using statement to the top of the page.
using aspNetDns; using aspNetDns.Records;
5. Be sure the following two lines of code to wire up the TextBox and <asp:Literal> are available at the class level.
protected System.Web.UI.WebControls.Literal litMsg; protected System.Web.UI.HtmlControls.HtmlInputText txtIPAddress;
6. To the Page_Load method, add the following code.
private void Page_Load(object sender, System.EventArgs e) { if( Page.IsPostBack) { if( txtIPAddress.Value.Length > 0 ) { PointerRecord[] records = PointerRecord.GetPointerRecords( txtIPAddress.Value ); if( records.Length > 0 ) { litMsg.Text = string.Empty; for( int i=0;i<records.Length;i++) { litMsg.Text += "<BR>" + txtIPAddress.Value + " maps to " + records[i].PointerName; } } else { litMsg.Text = "No Records Were Found."; } } else { litMsg.Text = "Please Enter a Valid IP Address"; } } else //populate with the client IP Address { txtIPAddress.Value = Request.UserHostAddress; } }
This code first checks to see if the page was posted. If the page was posted, the IP Address is looked up using the static method of the PointerRecord class. If a record is found, we write out the value of the PointerName to the literal tag.. If the page wasn't posted, we populate the txtIPAddress.Value with the client's IP Address.
Testing The Page Lets compile and test the page.
1. In the Solution Explorer, right-click the project name, aspNetDnsTest, and select Build. The project will be compiled.
2. In the Solution Explorer, right-click lookup.aspx and select View in Browser.
3. The client's IP is populated in the textbox. Click Submit and aspNetDns will perform a reverse lookup of the IP Address.
Summary That's all there is to using aspNetDns from Visual Studio .NET. In these few simple steps you were able to create a project, set a reference to aspNetDns, and reverse lookup an IP address. For more questions or comments, feel free to write support@advancedIntellect.com
Complete Source Code Listing The entire source listing can be found here.
Copyright 2002 - Contact: Webmaster Last Updated: Wednesday, April 30, 2008