asp.net pseudo-static implementation and the two-level domain name Universal parsing

Source: Internet
Author: User
Tags httpcontext

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


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.