用global.asax在ASP.NET实现无组件无扩展名伪静态
2011-07-07 01:50
274 查看
用global.asax在ASP.NET实现无组件无扩展名伪静态
最讨厌安装组件什么了的,于是查了很多资料,总结了一个ASP.NET不用组件实现伪静态的方法。一、IIS设置
1、在主目录-配置里,将.aspx扩展名的"确认文件是否存在"的钩去掉。
2、接着在下面的映射里,添加.aspx扩展名里的可执行文件路径。
3、默认文档一定要以.aspx为扩展名的文件名为第一个。
二、程序部分
1、在网站根目录新建global.asax。
2、添加如下代码:将saoluche指向扫路车
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
string requestPath = context.Request.Path.ToLower();
if( requestPath.IndexOf(".") < 0 )
{
//特殊的SEO重写
Hashtable ht = new Hashtable();
//分类信息
ht.Add("/saoluche","/album.aspx?id=58");
foreach(DictionaryEntry de in ht)
{
if( requestPath.IndexOf(de.Key.ToString()) >= 0 )
{
requestPath = requestPath.Replace(de.Key.ToString(),de.Value.ToString());
if( requestPath == "/" || requestPath == "" )
requestPath = "index.aspx";
requestPath = requestPath.TrimEnd("/");
Context.RewritePath(requestPath);
break;
}
}
}
}
相关文章推荐
- 在global.asax中实现定时生成静态首页 (asp.net C#)
- 在global.asax中实现定时生成静态首页 (asp.net C#)
- 使用Global.asax实现ASP.Net的URL重写
- 使用Global.asax实现ASP.Net的URL重写
- Servlet实现asp.net中的Global.asax启动事件(Servlet和Listener使用)
- 基于Global.asax实现显示当前在线人数--ASP.NET基础
- Asp.Net在Global.asax中实现URL 的重写
- asp.net利用Global.asax来实现定点执行任务的简易解决办法
- .net知识系列之七:底层解密(ASP.NET底层之旅,HttpApplication类实例,HttpApplication及Global.asax,实现自定义文件类型处理)
- Asp.Net的Web.config和Global.asax
- 基于ASP.NET MVC(C#)和Quartz.Net组件实现的定时执行任务调度
- asp.net web 定时执行任务 定时器 Global.asax
- 使用ASP.NET Global.asax 文件
- 基于ASP.NET MVC(C#)和Quartz.Net组件实现的定时执行任务调度
- Asp.NET实现下拉框二级联动组件
- [ASP.NET]Global.asax以及Web应用的生命周期
- 在ASP.NET中使用Global.asax文件
- 使用ASP.NET Global.asax 文件(转)
- ASP.NET-Global.asax 文件是什么?
- ASP.NET MVC中的Global.asax文件