Asp.net pseudo-static implementation and second-level domain name wildcard resolution

Source: Internet
Author: User

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;
}
}


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.