C Programming Tutorials and advice
CProgrammingTrends News Archives About Us Feedback

Recent Articles


Working With Weeks In C# (Not That Obvious)
For some reason, Microsoft didn't add a Week property to the DateTime class. I never could figure out why. Instead they gave us the System.Globalization namespace, filled with date related functionality like the different...

Creating Safe Events In C#
Whenever you write class libraries, custom control or just about anything else, you probably raise a lot of home made events. That's a simple thing to do, but tedious to write over and over again. That's why I always use...

Assigining a TypeConverter to a Class you Don't Own
I ran into problems with the XNA Beta1, where by I had a class that had a Vector2 struct in. The problem with the XNA Vector2 struct is that there is no TypeConverter for it at the moment. This means that there is no support in the designer. I initially solved this problem by...

Rational Betas Have C++ Goodies
Features in the Rational Software Architect v7.0 beta include improved support for C++, and developers can try out the open beta by pre-registering for it with IBM. Open betas for IBM Rational Software Architect V7.0...

Revisiting C/C++ On Eclipse
The tutorial from IBM's developerWorks on using the C/C++ Development Toolkit (CDT) for Eclipse received a refresh over the summer, and it merits a look from those who may have missed it since then.

Using Immediate Window to Work with Values
This article is an excerpt from the book: Murach's ASP.NET 2.0 Web Programming with C# 2005. The Immediate window, shown in figure 4-14, is useful for displaying the values of variables or properties that...


11.30.06


Retrieve Subdomain From A URL In C#


By Mads Kristensen

I had to come up with a method that retrieved the subdomain from the current web request on an ASP.NET website.

I thought that the System.Uri class contained that information in an easy retrievable way, but no.

Here's what I came up with instead. It still uses the System.Uri to find the subdomain.



To use it, simply put in the URL of your choice like so:



Low Rate eCommerce & Retail Plans

Update

Based on the comments I've had so far on this post, I've made some changes to the GetSubDomain() method as shown below.

Thanks to Anders and Jacob for the comments.



About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

About CProgrammingTrends
A collection of articles and tutorials designed to help C and C variant programmers in their programming work. C Programming Tutorials and advice

CProgrammingTrends is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagmentNews.com


-- CProgrammingTrends is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2006 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal


archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


">Unsubscribe from CProgrammingTrends.
To unsubscribe from CProgrammingTrends or any other iEntry publication, simply send an email request to: support@ientry.com
CProgrammingTrends Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact