【www.bbyears.com--域名投资】
asp教程.net 伪静态实现与二级域名泛解析
app.context.rewritepath(path, string.empty, strb.tostring().split("?")[1]);
在web.config里配置下:
里添加如下代码。
最后设置iis的时候记得要把iis的表头设置为空。
运行下你就能实现了
httpapplication app = (httpapplication)sender;
httpcontext context = app.context;
string url = context.request.url.absoluteuri; //完整url
string turl = url.split(".")[0];
string surl = turl.tolower().replace("http://", "");
stringbuilder strb = new stringbuilder();
strb.append(url);
strb.append(surl);
关于实例的详细方法
protected void page_load(object sender, eventargs e)
{
checkdomain();
}
///
///取得二级域主机头值,并实行转向
///
public void checkdomain()
{
string hostname = httpcontext.current.request.url.host.tostring(); //获取url主机地址
string [] userhost = hostname.split(new char[] { "." }); //数组,以“.”分隔//判断二级域名地址是否符合abc.域名.com 这种格式,及数组userhost长度不大于3,否则就跳传到其它页
if (userhost.length > 3)
{
httpcontext.current.response.redirect("http://www.111cn.net/"); //跳转到出错页面
return;
}string userdomainname = userhost[0].tostring(); //取得数组最前面一组值,及二级域名主机头
//进行特定判断,及是不要用到做为二级域名的主机头
if (userdomainname.tolower() == "www" || userdomainname.tolower() == "域名" || userdomainname == null || userdomainname.tostring() == "")
{
httpcontext.current.response.redirect("http://www.111cn.net/"); //跳转到出错页面
return;
}
else
{
//方法1
string post = string.format("http://www.xxx.com/u/{0}/index.html", userdomainname);
httpcontext.current.response.redirect(post); //跳转到用户目录,即是二级域名所要去到的目录,当然你也可以跳传至*.aspx?userid=xxx这样的链接
//方法2是通过session来把主机头保存进去,页面加载的时候在这里来进行判断,然后页面打开的时候你输入xxx.111cn.net就是xxx这个用户的信息
//session["username"] = userdomainname;
//方法3
return;
}
}