ASP tutorials. NET pseudo-static implementation and two-level domain name Universal parsing
App.context.rewritepath (Path, String.Empty, Strb.tostring (). Split ('? ') [1]);
In Web.config configuration:
<system.web> Add the following code.
<add type= "Common.urlrewriter" name= "common"/>
When you finally set up IIS, remember to set the table header for IIS to NULL.
Run it, and you'll be able to achieve it.
HttpApplication app = (HttpApplication) sender;
HttpContext context = App.context;
string url = Context.request.url.absoluteuri; Full URL
String turl = Url.split ('. ') [0];
String surl = Turl.tolower (). Replace ("http://", "");
StringBuilder strb = new StringBuilder ();
Strb.append (URL);
Strb.append (sURL);
A detailed approach to the instance
Protected void Page_Load (object sender, EventArgs e)
{
Checkdomain ();
}
///<summary>
///obtains a level two domain host header value and implements a switch to
///</ Summary>
public void Checkdomain ()
{
string hostname = httpcontext.current.request.url.host.tostring (); Gets the URL host address
string [] Userhost = Hostname.split (new char[] {'. '}); //Array to "." Separate
Determine whether the level two domain address is in line with ABC. Domain name. com This format, and array userhost length is not greater than 3, otherwise jump to other pages
if (Userhost.length > 3)
{
Httpcontext.current.response.redirect ("http://www.111cn.net/"); Jump to error page
Return
}
String userdomainname = Userhost[0].tostring (); Gets the first set of values in the array, and the two-level domain name host header
Make a specific judgment, and do not use the main header as a two-level domain name
if (userdomainname.tolower () = = "www" | | userdomainname.tolower () = "Domain Name" | | userdomainname = NULL | | userdomainname.tost Ring () = "")
{
Httpcontext.current.response.redirect ("http://www.111cn.net/"); Jump to error page
Return
}
Else
{
Method 1
String post = String.Format ("http://www.xxx.com/u/{0}/index.html", UserDomainName);
Httpcontext.current.response.redirect (POST); Jump to the user directory, that is, a level two domain name to go to the directory, of course, you can also jump to *.aspx?userid=xxx such links
Method 2 is through the session to save the main head, the page loading time to judge here, and then the page opened when you enter xxx.111cn.net is xxx This user's information
session["username"] = userdomainname;
Method 3
Return
}
}