Asp tutorial. net pseudo-static implementation and second-level domain name wildcard resolution
App. context. rewritepath (path, string. empty, strb. tostring (). split ('? ') [1]);
In web. config, configure the following:
Add the following code in <system. web>.
<Httpmodules>
<Add type = "common. urlrewriter" name = "common"/>
When setting iis, remember to set the iis header to null.
You can achieve this by running
</Httpmodules>
Httpapplication app = (httpapplication) sender;
Httpcontext context = app. context;
String url = context. request. url. absoluteuri; // complete url
String turl = url. split ('.') [0];
String surl = turl. tolower (). replace ("http ://","");
Stringbuilder strb = new stringbuilder ();
Strb. append (url );
Strb. append (surl );
Detailed instance methods
Protected void page_load (object sender, eventargs e)
{
Checkdomain ();
}
/// <Summary>
/// Obtain the second-level domain host header value and perform redirection
/// </Summary>
Public void checkdomain ()
{
String hostname = httpcontext. current. request. url. host. tostring (); // obtain the url host address
String [] userhost = hostname. split (new char [] {'.'}); // array, separated "."
// Determine whether the second-level domain name address complies with the abc. Domain Name. com format, and the length of the array userhost is not greater than 3. Otherwise, the second-level domain name will jump to other pages.
If (userhost. length> 3)
{
Httpcontext. current. response. redirect ("http://www.bKjia. c0m/"); // jump to the error page
Return;
}
String userdomainname = userhost [0]. tostring (); // obtain the first value of the array and the Host header of the second-level domain name.
// Make specific judgments and do not use the Host Header as the second-level domain name
If (userdomainname. tolower () = "www" | userdomainname. tolower () = "Domain Name" | userdomainname = null | userdomainname. tostring () = "")
{
Httpcontext. current. response. redirect ("http://www.bKjia. c0m/"); // jump to the error page
Return;
}
Else
{
// Method 1
String post = string. format ("http://www.xxx.com/u/4250#/index.html", userdomainname );
Httpcontext. current. response. redirect (post); // jump to the user directory, that is, the directory to which the second-level domain name is going. Of course, you can also jump to *. aspx? Userid = xxx
// Method 2: The Host header is saved through the session. When the page is loaded, it is judged here. When the page is opened, you enter xxx. bKjia. c0m is the user information of xxx.
// Session ["username"] = userdomainname;
// Method 3
Return;
}
}