ASP.NET中实现二级或多级域名(URLRewriter),请教大侠
1.URLRewriter.DLL两个文件已经修改好,生成了复制到了Bin文件夹BaseModuleRewriter.cs
protected virtual void BaseModuleRewriter_AuthorizeRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication) sender;
Rewrite(app.Request.Url.AbsoluteUri, app);
}
BaseModuleRewriter.cs
protected override void Rewrite(string requestedPath, System.Web.HttpApplication app)
{
// log information to the Trace object.
app.Context.Trace.Write("ModuleRewriter", "Entering ModuleRewriter");
// get the configuration rules
RewriterRuleCollection rules = RewriterConfiguration.GetConfig().Rules;
// iterate through each rule...
for(int i = 0; i < rules.Count; i++)
{
// get the pattern to look for, and Resolve the Url (convert ~ into the appropriate directory)
string lookFor = "^" + rules[i].LookFor + "$";
// Create a regex (note that IgnoreCase is set...)
Regex re = new Regex(lookFor, RegexOptions.IgnoreCase);
// See if a match is found
if (re.IsMatch(requestedPath))
{
// match found - do any replacement needed
string sendToUrl = RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, re.Replace(requestedPath, rules[i].SendTo));
// log rewriting information to the Trace object
app.Context.Trace.Write("ModuleRewriter", "Rewriting URL to " + sendToUrl);
// Rewrite the URL
RewriterUtils.RewriteUrl(app.Context, sendToUrl);
break; // exit the for loop
}
}
2.已经做了泛解析
3.80端口主机头为空的站点
4.添加ASPNET_ISAPI的通配符应用程序映射,取消"确认文件是否存在"前的钩.
规则,比如域名是abc.com
<RewriterRule>
<LookFor>http://(\d*)\.abc\.com/</LookFor>
<SendTo>~/2.aspx?id=$1</SendTo>
</RewriterRule>
.aspx页面
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/2.aspx?id=2">正常URL</asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="http://2.abc.com/">重写URL</asp:HyperLink>
正常访问 正常URL 参数是 返回参数 2
正常访问 重写URL 提示 http 400错误 无法找到该网页 --------------------编程问答-------------------- 飘过 顶帖@!!! --------------------编程问答-------------------- 过来看看 --------------------编程问答-------------------- 参考 --------------------编程问答-------------------- --> “正常访问 重写URL 提示 http 400错误 无法找到该网页”
你的url是“http://2.abc.com”,浏览器会认为你要访问远程,所以会先进行一系列的解析,这些动作由底层网络协议执行。其中会经过DNS查找和ARP(地址解析协议),具体过程我也不是很清楚,对这个不熟,望见谅。在这个步骤中,如果解析失败,就会抛出404错误,网页不存在。所以这个请求根本到不了IIS里面,更别谈调用重写模块了。
如果你想输入http://2.abc.com可以访问你自己的电脑,请修改“C:\WINDOWS\system32\drivers\etc\hosts”文件(那文件没扩展名的),增加一行:127.0.0.1 2.abc.com。接着在浏览器里输入这个网站,你就看访问你自己的电脑了。 --------------------编程问答-------------------- 应该不用再解析二级域名了吧,只要支持泛型就行,,以前做过URI的重写,二级域名试过,不过不做成。再回来看看高人的。 --------------------编程问答--------------------
请修改“C:\WINDOWS\system32\drivers\etc\hosts”文件(那文件没扩展名的),增加一行:127.0.0.1 2.abc.com
这个我也已经做好了
但提示要输入用户和密码
输入本机的 administrator 和 密码 也进不去 --------------------编程问答--------------------
你IIS的匿名访问没打开? --------------------编程问答-------------------- 打开了 --------------------编程问答-------------------- http://2.abc.com 访问到首页了 --------------------编程问答-------------------- 楼主成功了 祝贺! --------------------编程问答-------------------- 但放到服务器还是不行 --------------------编程问答-------------------- 请大侠帮忙 --------------------编程问答-------------------- 这个需要对域名做泛解析,本机好实现的。如果你的服务器是虚拟主机的话,你就别做指望了。这个需要独立IP服务器,域名做泛解析的时候,指向的是独立IP地址。如:在域名管理里要做,*.123.com指向服务IP --------------------编程问答-------------------- 泛解析 已经做好了 --------------------编程问答-------------------- 服务器是独立IP --------------------编程问答-------------------- 顶一下
补充:.NET技术 , ASP.NET