模板路径隐射,怎么处理呢 本帖最后由 zhu885928 于 2010-02-05 13:05:44 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 方法很多1、www.csdn.com/index.aspx 代码跳转到 temp/default/index.aspx Server.Execute("")URLrewriter重写地址 你可以搜索一下url重写,以前做过。用的就是url重写 怪我问题,没有说清楚2楼的、www.csdn.com/index.aspx 代码跳转到 temp/default/index.aspx 这个方法无法实现因为我的程序里面没有www.csdn.com/index.aspx这个页面,只有www.csdn.com/temp/default/index.aspx 这个页面,我怎样在浏览器输入www.csdn.com/index.aspx 就能显示出www.csdn.com/temp/default/index.aspx 这个模板页面的内容呢 就如DZ!NET,那样的方法,在浏览器输入,然后自定义就转入对应的模板页面 //已经实现using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web;using EmShop.Template;using System.Text.RegularExpressions;using EmShop.Config;using Microsoft.Practices.EnterpriseLibrary.Caching;using EmShop.Common;namespace EmShop.Page{ public class HttpModule : IHttpModule { // Fields private string aspxfilepath; private string cachetime; private string tplfilepath; private string tplname; private string viewmode; private string weburl; public HttpModule() { this.tplname = string.Empty; this.tplfilepath = string.Empty; this.aspxfilepath = string.Empty; this.weburl = string.Empty; this.viewmode = string.Empty; this.cachetime = string.Empty; } private void CheckRewrite(string url) { string path = string.Empty; Match match = Regex.Match(url, @"([^-]*)-([0-9]*)\.aspx", RegexOptions.IgnoreCase); if (match.Groups.Count > 1) { path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value; HttpContext.Current.RewritePath(path); } else { match = Regex.Match(url, @"([^-]*)-([0-9]*)_page-([0-9]*)\.aspx", RegexOptions.IgnoreCase); if (match.Groups.Count > 1) { path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value + "&page=" + match.Groups[3].Value; HttpContext.Current.RewritePath(path); } else { match = Regex.Match(url, @"content-([0-9a-zA-Z]*)\.aspx", RegexOptions.IgnoreCase); if (match.Groups.Count > 1) { HttpContext.Current.RewritePath(@"temp\" + this.tplname + @"\content.aspx?wd=" + match.Groups[1].Value); } } } } private void context_EndRequest(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; string str = application.Request.RawUrl.ToLower(); int index = str.IndexOf("lang="); if (index > 0) { application.Response.Redirect(str.Substring(0, index - 1) + str.Substring(index + 7)); } } public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(this.ReUrl_BeginRequest); context.EndRequest += new EventHandler(this.context_EndRequest); } private void ReUrl_BeginRequest(object sender, EventArgs e) { string url = string.Empty; url = HttpContext.Current.Request.Path.ToLower(); string input = url; BaseConfigInfo realBaseConfig = BaseConfigInfoProvider.GetRealBaseConfig(); if (!this.VerifyUrl(url) && (input.IndexOf(realBaseConfig.Language.ToLower()) == -1)) { this.tplname = realBaseConfig.TemplatePath; this.weburl = realBaseConfig.VirtualPath; this.viewmode = realBaseConfig.ViewMode; this.cachetime = realBaseConfig.CacheTime; XTemplate template = new XTemplate(); template.AspxPath = "temp"; template.TplPath = "template"; template.TplName = this.tplname; template.HtmlPath = "cache"; template.WebUrl = this.weburl; template.CacheTime = int.Parse(this.cachetime); template.ViewMode = this.viewmode; string str3 = (HttpContext.Current.Request.QueryString["tpl"] == null) ? "" : HttpContext.Current.Request.QueryString["tpl"]; if (str3 != "") { this.tplname = str3; } string fileName = Regex.Match(HttpContext.Current.Request.Path.ToLower(), @".*?/([^./]*)\.aspx(.*)").Groups[1].ToString(); string str5 = HttpContext.Current.Request["lang"]; if (!string.IsNullOrEmpty(str5)) { Language.SetCurrentLanguageType(str5); } CacheManager cacheManager = CacheFactory.GetCacheManager(); string oldValue = string.Empty; oldValue = Regex.Match(HttpContext.Current.Request.Url.ToString(), @"http://([^\/]*)").Groups[0].ToString(); string str10 = oldValue; oldValue = (str10 + this.weburl + "temp/" + this.tplname + "/" + HttpContext.Current.Request.Url.ToString().Replace(oldValue, "").Replace(this.weburl, "")).ToLower() + Language.GetCurrentLanguageType(string.Empty).ToString(); if (((((HttpContext.Current.Request.Form.Count == 0) && (HttpContext.Current.Request.QueryString["emshopflag"] == null)) && ((fileName.IndexOf("cart") == -1) && (fileName.IndexOf("cartstep") == -1))) && (((fileName.IndexOf("cartend") == -1) && (HttpContext.Current.Request.QueryString["detailprice"] == null)) && (fileName.IndexOf("js_") == -1))) && cacheManager.Contains(oldValue)) { HttpContext.Current.Response.Write(cacheManager.GetData(oldValue)); HttpContext.Current.Response.End(); } else { if (this.viewmode == "Rewrite") { string str8 = string.Empty; str8 = Regex.Match(HttpContext.Current.Request.Path.ToLower(), @"([^-]*)-([0-9]*)_page-([0-9]*)\.aspx", RegexOptions.Compiled).Groups[1].ToString(); if (str8 != "") { fileName = str8; } str8 = Regex.Match(HttpContext.Current.Request.Path.ToLower(), @".*?/([^./-]*)-([0-9]*)\.aspx(.*)").Groups[1].ToString(); if (str8 != "") { fileName = str8; } string path = string.Empty; Match match = Regex.Match(input, @".*?/([^./-]*)-([0-9]*)\.aspx", RegexOptions.IgnoreCase); if (match.Groups.Count > 1) { path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value; HttpContext.Current.RewritePath(path); return; } match = Regex.Match(input, @".*?/([^./-]*)-([0-9]*)_page-([0-9]*)\.aspx", RegexOptions.IgnoreCase); if (match.Groups.Count > 1) { path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value + "&page=" + match.Groups[3].Value; HttpContext.Current.RewritePath(path); return; } } else if (HttpContext.Current.Request.QueryString["adminact"] == "module") { template.CreateTpl(fileName); } template.Display(fileName); } } } private bool VerifyUrl(string url) { return (HttpContext.Current.Request.Url.IsFile || ((url.IndexOf("weblogin") != -1) || ((url.IndexOf("member") != -1) || ((url.IndexOf("bbs") != -1) || ((url.IndexOf("union") != -1) || ((url.IndexOf("install") != -1) || ((url.IndexOf("_module.aspx") != -1) || ((url.IndexOf("webresource.axd") != -1) || (url.IndexOf("scriptresource.axd") != -1))))))))); } }} 然后再WEB.CONFIG,引用该类的,DLL文件现在出现一个新的问题,就是模板路径,无法隐射到,导致页面错位,晕,那位大虾知道咋解决的啊,帮忙顶顶 <add type="EmShop.Page.HttpModule, EmShop.Page" name="HttpModule" /> 10楼正解,用模块截获请求,用HttpContext的RewritePath方法改写URL下传处理 问2个关于菜单的问题 DataGridView 如何自定义排序 递归调用问题 是否可以指定MDI的位置? DataGridView的两个问题 大家推荐一个好用的跨平台的XML解析器(Windows,linux) 64位2008服务器上怎么配置与Excel有关的DCOM 问个客户端导出Excel的问题? 如何提升c# 版web application的速度? 求大神帮忙,为什么会有这个错误 哈希表的用法 winform登陆窗口点击复选框记录密码
1、www.csdn.com/index.aspx 代码跳转到 temp/default/index.aspx
URLrewriter重写地址
2楼的、www.csdn.com/index.aspx 代码跳转到 temp/default/index.aspx 这个方法无法实现
因为我的程序里面没有www.csdn.com/index.aspx这个页面,只有www.csdn.com/temp/default/index.aspx 这个页面,
我怎样在浏览器输入www.csdn.com/index.aspx 就能显示出www.csdn.com/temp/default/index.aspx 这个模板页面的内容呢
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using EmShop.Template;
using System.Text.RegularExpressions;
using EmShop.Config;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using EmShop.Common;namespace EmShop.Page
{
public class HttpModule : IHttpModule
{
// Fields
private string aspxfilepath;
private string cachetime;
private string tplfilepath;
private string tplname;
private string viewmode;
private string weburl; public HttpModule()
{
this.tplname = string.Empty;
this.tplfilepath = string.Empty;
this.aspxfilepath = string.Empty;
this.weburl = string.Empty;
this.viewmode = string.Empty;
this.cachetime = string.Empty;
} private void CheckRewrite(string url)
{
string path = string.Empty;
Match match = Regex.Match(url, @"([^-]*)-([0-9]*)\.aspx", RegexOptions.IgnoreCase);
if (match.Groups.Count > 1)
{
path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value;
HttpContext.Current.RewritePath(path);
}
else
{
match = Regex.Match(url, @"([^-]*)-([0-9]*)_page-([0-9]*)\.aspx", RegexOptions.IgnoreCase);
if (match.Groups.Count > 1)
{
path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value + "&page=" + match.Groups[3].Value;
HttpContext.Current.RewritePath(path);
}
else
{
match = Regex.Match(url, @"content-([0-9a-zA-Z]*)\.aspx", RegexOptions.IgnoreCase);
if (match.Groups.Count > 1)
{
HttpContext.Current.RewritePath(@"temp\" + this.tplname + @"\content.aspx?wd=" + match.Groups[1].Value);
}
}
}
}
private void context_EndRequest(object sender, EventArgs e)
{
HttpApplication application = sender as HttpApplication;
string str = application.Request.RawUrl.ToLower();
int index = str.IndexOf("lang=");
if (index > 0)
{
application.Response.Redirect(str.Substring(0, index - 1) + str.Substring(index + 7));
}
} public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(this.ReUrl_BeginRequest);
context.EndRequest += new EventHandler(this.context_EndRequest);
} private void ReUrl_BeginRequest(object sender, EventArgs e)
{
string url = string.Empty;
url = HttpContext.Current.Request.Path.ToLower();
string input = url;
BaseConfigInfo realBaseConfig = BaseConfigInfoProvider.GetRealBaseConfig();
if (!this.VerifyUrl(url) && (input.IndexOf(realBaseConfig.Language.ToLower()) == -1))
{
this.tplname = realBaseConfig.TemplatePath;
this.weburl = realBaseConfig.VirtualPath;
this.viewmode = realBaseConfig.ViewMode;
this.cachetime = realBaseConfig.CacheTime;
XTemplate template = new XTemplate();
template.AspxPath = "temp";
template.TplPath = "template";
template.TplName = this.tplname;
template.HtmlPath = "cache";
template.WebUrl = this.weburl;
template.CacheTime = int.Parse(this.cachetime);
template.ViewMode = this.viewmode;
string str3 = (HttpContext.Current.Request.QueryString["tpl"] == null) ? "" : HttpContext.Current.Request.QueryString["tpl"];
if (str3 != "")
{
this.tplname = str3;
}
string fileName = Regex.Match(HttpContext.Current.Request.Path.ToLower(), @".*?/([^./]*)\.aspx(.*)").Groups[1].ToString();
string str5 = HttpContext.Current.Request["lang"];
if (!string.IsNullOrEmpty(str5))
{
Language.SetCurrentLanguageType(str5);
}
CacheManager cacheManager = CacheFactory.GetCacheManager();
string oldValue = string.Empty;
oldValue = Regex.Match(HttpContext.Current.Request.Url.ToString(), @"http://([^\/]*)").Groups[0].ToString();
string str10 = oldValue;
oldValue = (str10 + this.weburl + "temp/" + this.tplname + "/" + HttpContext.Current.Request.Url.ToString().Replace(oldValue, "").Replace(this.weburl, "")).ToLower() + Language.GetCurrentLanguageType(string.Empty).ToString();
if (((((HttpContext.Current.Request.Form.Count == 0) && (HttpContext.Current.Request.QueryString["emshopflag"] == null)) && ((fileName.IndexOf("cart") == -1) && (fileName.IndexOf("cartstep") == -1))) && (((fileName.IndexOf("cartend") == -1) && (HttpContext.Current.Request.QueryString["detailprice"] == null)) && (fileName.IndexOf("js_") == -1))) && cacheManager.Contains(oldValue))
{
HttpContext.Current.Response.Write(cacheManager.GetData(oldValue));
HttpContext.Current.Response.End();
}
else
{
if (this.viewmode == "Rewrite")
{
string str8 = string.Empty;
str8 = Regex.Match(HttpContext.Current.Request.Path.ToLower(), @"([^-]*)-([0-9]*)_page-([0-9]*)\.aspx", RegexOptions.Compiled).Groups[1].ToString();
if (str8 != "")
{
fileName = str8;
}
str8 = Regex.Match(HttpContext.Current.Request.Path.ToLower(), @".*?/([^./-]*)-([0-9]*)\.aspx(.*)").Groups[1].ToString();
if (str8 != "")
{
fileName = str8;
}
string path = string.Empty;
Match match = Regex.Match(input, @".*?/([^./-]*)-([0-9]*)\.aspx", RegexOptions.IgnoreCase);
if (match.Groups.Count > 1)
{
path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value;
HttpContext.Current.RewritePath(path);
return;
}
match = Regex.Match(input, @".*?/([^./-]*)-([0-9]*)_page-([0-9]*)\.aspx", RegexOptions.IgnoreCase);
if (match.Groups.Count > 1)
{
path = @"temp\" + this.tplname + @"\" + match.Groups[1].Value + ".aspx?id=" + match.Groups[2].Value + "&page=" + match.Groups[3].Value;
HttpContext.Current.RewritePath(path);
return;
}
}
else if (HttpContext.Current.Request.QueryString["adminact"] == "module")
{
template.CreateTpl(fileName);
}
template.Display(fileName);
}
}
}
private bool VerifyUrl(string url)
{
return (HttpContext.Current.Request.Url.IsFile || ((url.IndexOf("weblogin") != -1) || ((url.IndexOf("member") != -1) || ((url.IndexOf("bbs") != -1) || ((url.IndexOf("union") != -1) || ((url.IndexOf("install") != -1) || ((url.IndexOf("_module.aspx") != -1) || ((url.IndexOf("webresource.axd") != -1) || (url.IndexOf("scriptresource.axd") != -1)))))))));
}
}
}
现在出现一个新的问题,就是模板路径,无法隐射到,导致页面错位,晕,那位大虾知道咋解决的啊,帮忙顶顶