使用URL重写创建类似路径的动态子域 [英] Create dynamic subdomain like path using URL Rewriting
本文介绍了使用URL重写创建类似路径的动态子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网站中有网址,并且使用查询字符串值例如:
http://foo.com/xyzPage.aspx?barvalue= yehaa
to
http://yehaa.foo.com/
请建议怎么样没有在服务器上实际创建子域名就完成了..
我在服务器机器上安装了IIS 7.5并使用Asp.net 4.0。
I've URLs in my website and which are using query string values For example:
http://foo.com/xyzPage.aspx?barvalue=yehaa
to
http://yehaa.foo.com/
Please suggest how it can be accomplished without actually creating subdomains on server ..
I've IIS 7.5 installed on server machine and using Asp.net 4.0.
推荐答案
protected void Application_BeginRequest(Object sender, EventArgs e)
{
var SubDomain = GetSubDomain(HttpContext.Current.Request.Host);
// this is a simple example, you can place your variables base on subdomain
if(!String.IsNullOrEmpty(SubDomain))
RewritePath(HttpContext.Current.Request.Path + SubDomain + "/", false);
}
// from : http://madskristensen.net/post/Retrieve-the-subdomain-from-a-URL-in-C.aspx
private static string GetSubDomain(Uri url)
{
string host = url.Host;
if (host.Split('.').Length > 1)
{
int index = host.IndexOf(".");
return host.Substring(0, index);
}
return null;
}
这篇关于使用URL重写创建类似路径的动态子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文