Here's a tip: How to extract a domain or host name from a long url string (top distinct referring domains to your website from all referring urls)

The scenario is the url's are coming from a database and can be in format:

http://mywebsite.com/asdasd/asda/sda/sd/asd/asd.htm
http://www.mywebsite.com/asdasd/asd/asd/asd/asd.htm
or even
http://localhost/asd/asd/asd/asd.htm

They are also not distinct, but are sorted by top occurance in the database. Basically they are the top referring urls to your website. You wan to display a distinct/unique list of the top domains extracted from the urls.

 

1            /// <summary>
2            /// Builds a data table result of the top X referring domains
3            /// </summary>
4            /// <param name="ApplicationID">The ID of the application to list results for</param>
5            /// <returns>DataTable</returns>
6            public static DataTable ListTopReferringDomains(int ApplicationID)
7            {
8                DataTable _retVal = new DataTable();
9                DataTable _dtDomains = new DataTable();
10               //Add column to return table
11               _dtDomains.Columns.Add("Domain");
12       
13               try
14               {
15                   //Grab core data to work with
16                   DataTable _tmpData = ListTopReferringUrls(ApplicationID);
17                   //Loop through data rows
18                   foreach(DataRow _dr in _tmpData.Rows)
19                   {
20                       //Get the referring url
21                       string _refDomainUrl = _dr["client_url_ref"].ToString();
22   
23                       //Create a new row for return table
24                       DataRow _dtDomainsNewRow = _dtDomains.NewRow();
25                       
26                       //Extract domain from long url
27                       char[] _trimStart = { 'h', 't', 't', 'p', ':', '/', '/' };
28                       string[] _urlTemp = _refDomainUrl.TrimStart(_trimStart).Split('/');
29                       
30                       //Set return row column value to domain of url
31                       _dtDomainsNewRow["Domain"] = _urlTemp[0];
32                       _dtDomains.Rows.Add(_dtDomainsNewRow);
33                   }
34   
35                   //Select distinct from the results
36                   DataView _dvDomains = new DataView(_dtDomains);
37                   _retVal = _dvDomains.ToTable("ResultsTable", true, new string[] { "Domain" });
38               }
39               catch (Exception ex)
40               {
41                   throw new DataObjectsException(ex.Message, ex.InnerException);
42               }
43               return _retVal;
44           }

 

 


Sincerely,

remedy
MCP + Senior .NET Developer
Vista: Worth every penny.
0
remedy
5/22/2006 2:22:42 AM
asp.net.tips-tricks 851 articles. 0 followers. Follow

0 Replies
700 Views

Similar Articles

[PageSpeed] 15

Reply:

Similar Artilces:

superreview cancelled: [Bug 254745] Firefox displays URL domain name next to lock icon if URL name and Certificate name don't match : [Attachment 159032] Patch v.1
Gavin Sharp <gavin.sharp@gmail.com> has cancelled chris hofmann <chofmann@gmail.com>'s request for superreview: Bug 254745: Firefox displays URL domain name next to lock icon if URL name and Certificate name don't match https://bugzilla.mozilla.org/show_bug.cgi?id=254745 Attachment 159032: Patch v.1 https://bugzilla.mozilla.org/attachment.cgi?id=159032&action=edit ...

superreview requested: [Bug 254745] Firefox displays URL domain name next to lock icon if URL name and Certificate name don't match : [Attachment 159032] Patch v.1
chris hofmann <chofmann@gmail.com> has asked Daniel Veditz <dveditz@cruzio.com> for superreview: Bug 254745: Firefox displays URL domain name next to lock icon if URL name and Certificate name don't match https://bugzilla.mozilla.org/show_bug.cgi?id=254745 Attachment 159032: Patch v.1 https://bugzilla.mozilla.org/attachment.cgi?id=159032&action=edit ------- Additional Comments from chris hofmann <chofmann@gmail.com> lets get some reviews. ...

Error when I use the name's domain on URL instead of IP
 HI,I have my ASp.NET page installed on IIS on Windows Server 2003. It works fine when I call the server through the IP, but when I use the name on the URL it crashes..anyone know what could cause that?  thanks what does "crashes" mean? What's the error? Odds are it's a DNS issue, but without the details we cant say. It sounds like your DNS entry on the server.Re-enter your DNS entry and then reset IIS. I had the same issue on one of my servers and I had to remove the dns, re-enter it, then reset IIS and then i was able to hit the site via the name and not t...

multiple SMTP's and different IP's, domain names to send email from this server using different SMTP's
Is anybody can help me with this 2 issues we have: 1. We need to have multiple SMTP's installed on our server - how do you do that 2. We need to rotate different IP's, domain names to send email from this server using different SMTP's          Thanks   Third party mail server.  Look at Smartermail or iMail, Exchange if you need that much. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. Is this only option? &n...

Rewriting URL - to domain's alias
Hi!So I want to redirect users from http://www.mydomain.com/default.aspx?user=johnto http://www.john.mydomain.com/default.aspx Can I do this? I want to make it works smart, adding manually in web.config rules are not good way, cause what I will do when I will have 1000 rules (users)?Is there any way to redirecting like this? Thanks.   You can use regexes http://msdn2.microsoft.com/en-us/library/ms972974.aspxAlso visit my website.Once your questions have been answered, remember to mark the question as answered, this rewards the people helping you and helps others to move...

Appending a domain to a URL on my website for compatibility with another domain on a called page
I have the URL of my website as http://localhost:29304/BillingCombined-31_NewDB_77g/Default.aspx But I need to make it into http://localhost.au.mydomain.com:29304/BillingCombined-31_NewDB_77g/Default.aspx in order to have compatibility with an external page which I am retrieiving a value off.   If I manually add the ".au.mydomain.com" part in, the page works, but I need to make the page automatically add this domain in. Does anyone have any ideas how? Kind regards, p.  I think the answer here is to make sure the page is called with the correct URL...

superreview cancelled: [Bug 261717] Can't copy Website header (URL) in RSS message's header : [Attachment 165556] patch that enables a context menu to copy the URL (now localizable)
Scott MacGregor <mscott@mozilla.org> has cancelled David Fraser <davidf@sjsoft.com>'s request for superreview: Bug 261717: Can't copy Website header (URL) in RSS message's header https://bugzilla.mozilla.org/show_bug.cgi?id=261717 Attachment 165556: patch that enables a context menu to copy the URL (now localizable) https://bugzilla.mozilla.org/attachment.cgi?id=165556&action=edit ...

superreview requested: [Bug 261717] Can't copy Website header (URL) in RSS message's header : [Attachment 165556] patch that enables a context menu to copy the URL (now localizable)
David Fraser <davidf@sjsoft.com> has asked Scott MacGregor <mscott@mozilla.org> for superreview: Bug 261717: Can't copy Website header (URL) in RSS message's header https://bugzilla.mozilla.org/show_bug.cgi?id=261717 Attachment 165556: patch that enables a context menu to copy the URL (now localizable) https://bugzilla.mozilla.org/attachment.cgi?id=165556&action=edit ------- Additional Comments from David Fraser <davidf@sjsoft.com> Requesting review for this. It's a fairly straight forward patch, the main thing is whether it's correct to add ...

How to 301 redirect dynamic URL's to new rewrited URL's for SEO purposes
Hi,I have installed a rewriting for the URL's. It is working. Problem is that our old URL's are still found in Google. To avoid loosing the pagerank in Google we already built up, I want to redirect the most important URL's to the new rewrited ones.For example: http://www.mydomain.nl/medicijn_ervaring.aspx?PK_MedicineID=N01AA45a&PK_CategoryID=13This is rewrited to: http://www.mydomain.nl/mirena.aspxProblem is that the URLs are dynamic, so not physical pages. Our server doesn't support the .htaccess solution.I reckon loads of people have the same issue.. but how to solve i...

redirection of domain name(s) at remotely hosted website
I have a web hosting provider where I have just been, up till now, being going to www.mydomain.net. The default.aspx resides at  the root of that '/' website directory, which GoDaddy points to.  I just registered a new domain www.myOtherDomain.net  GoDaddy points to that isp as well. I was told I could redirect users, whether they choose mydomain or myOtherDomain, all within mydomain.net. How would I do that?  In a web config file? Http Handler.  Thank you, Greghazz...

C# Language and Programmer's Reference (URL)
http://msdn.microsoft.com/library/default.asp?URL=/library/prelim/csref/vcor iCReference.htm ...

superreview granted: [Bug 331614] window.open unnecessarily escapes all URLs (can't handle IDN/extended domain-names) : [Attachment 217983] don't escape
Darin Fisher (Google) <darin@meer.net> has granted Gavin Sharp <gavin.sharp@gmail.com>'s request for superreview: Bug 331614: window.open unnecessarily escapes all URLs (can't handle IDN/extended domain-names) https://bugzilla.mozilla.org/show_bug.cgi?id=331614 Attachment 217983: don't escape https://bugzilla.mozilla.org/attachment.cgi?id=217983&action=edit ------- Additional Comments from Darin Fisher (Google) <darin@meer.net> sr=darin ...

superreview requested: [Bug 331614] window.open unnecessarily escapes all URLs (can't handle IDN/extended domain-names) : [Attachment 217983] don't escape
Gavin Sharp <gavin.sharp@gmail.com> has asked Darin Fisher (Google) <darin@meer.net> for superreview: Bug 331614: window.open unnecessarily escapes all URLs (can't handle IDN/extended domain-names) https://bugzilla.mozilla.org/show_bug.cgi?id=331614 Attachment 217983: don't escape https://bugzilla.mozilla.org/attachment.cgi?id=217983&action=edit ...

Domain name forwarding
HiI have written a portal content management system, so that different users have different sites such as:www.portalsite.com/default.aspx?SiteID=1www.portalsite.com/default.aspx?SiteID=2       etc. I have managed to URL rewrite, in the global.asax, to give friendly URLs such as:www.portalsite.com/user01www.portalsite.com/user02 However some users have their own registered domain names which they can forward to their portal site.  For example a user may have 'www.mydomainname.com' (hosted with another ISP) which they forward to point to their portal address ...

Web resources about - Here's a tip: How to extract a domain or host name from a long url string (top distinct referring domains to your website from all referring urls) - asp.net.tips-tricks

Resources last updated: 11/22/2015 1:47:01 PM