使用UrlRewritingNet重写url以.html的伪静态页面后,真实的.html无法访问的解决方法

2013/10/13 已被3651人阅读

当前位置:首页>新闻中心>技术关注【关闭】

1、在web.config中添加以下项目。









2、重写处理方法

Namespace web

{

public class eastClass : IHttpHandler

{

public bool IsReusable

{

get { return true; }

}

public void ProcessRequest(HttpContext context)

{

Uri url = context.Request.Url;

string filepath = context.Request.Url.AbsolutePath;

filepath = context.Server.MapPath("//") + filepath.Replace("/", "//");

if (File.Exists(filepath) == false)

{

if (url.ToString().IndexOf("要处理的url中的关键字") > -1)

{

string uname = url.Segments[url.Segments.Length - 1];//取出带后缀文件名称

string id = uname.Substring(0, uname.IndexOf("."));//真实的文件名

if (id != "")

context.Response.Redirect("/xxx.aspx?id=" + id, true);//跳转

}

else

{

filepath = context.Server.MapPath("//") + "404.htm";

string tempstr;

using (StreamReader sr = new StreamReader(filepath, Encoding.Default))

{

tempstr = sr.ReadToEnd();

}

context.Response.Write(tempstr);

context.Response.End();

}

}

else

{

string tempstr;

using (StreamReader sr = new StreamReader(filepath, Encoding.UTF8))

{

tempstr = sr.ReadToEnd();

}

context.Response.Write(tempstr);

context.Response.End();

}

}

}

}

预约洽谈

多一份方案,多一个参考,预约我们的商务面对面沟通,总有益处 周一至周五,9:00-18:00    咨询热线:021-3100 6558 24小时热线:15900965330

我要预约
电话咨询 在线沟通 QQ咨询 微信聊天