惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
小众软件
小众软件
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
博客园 - 三生石上(FineUI控件)
博客园_首页
N
Netflix TechBlog - Medium
IT之家
IT之家
H
Help Net Security
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
罗磊的独立博客
T
Tailwind CSS Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
V
V2EX
量子位
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
博客园 - 司徒正美
The Cloudflare Blog
Engineering at Meta
Engineering at Meta

博客园 - wander

代码编写规范说明书(c#.net与asp.net)转 常用正则表达式 b/s开发常用javaScript技术分类 在c#中如何在WINDOWS FORM 中访问超级链接? - wander 收藏 Meta标签详解 在ASP.NET中上传图片并生成带版权信息的缩略图 ASP.NET 数据绑定常用代码 (转) Ajax无刷新实现图片切换特效 在.NET下多层架构企业管理系统的开发 浏览器滚动条的参数总结 在ASP.NET中实现AJAX AJAX实现无刷新三联动下拉框 初识AJAX Visual C#实现Windows信使服务 c#.net常用的小函数和方法集 DataGrid使用心得 ASP.NET之精通弹出窗口 利用OWC生成统计图表(代码+注释)
基于动态页面的静态页面实现
wander · 2006-08-11 · via 博客园 - wander

只需要在Global.asax加上几行代码就行了,我们是通过捕获用户的请求,然后通过RewritePath来实现的:
这是我程序中的一段代码,它就负责把上面的那些请求转化为真正的页面请求,
我们是通过正则表达式来区分各种类别的请求的:

protected void Application_BeginRequest(Object sender, EventArgs e)
        
{                                                                        
            
string url = Request.Url.AbsoluteUri ;
            
string strMatch = @"http://www\.2shoushichang\.com/([^/]+)/" ;
                        
            
string newUrl = "" ;
            
string strCmd = SplitInfo(url,strMatch) ;
            
if (strCmd != null)
            
{
                
switch(strCmd.ToLower())
                
{

                    
case "product":
                        strMatch 
= @"/product/(\d+)\.aspx" ;
                        
string strProductId = SplitInfo(url,strMatch) ;
                                                
                        
if (strProductId != null)
                        
{
                            newUrl 
= string.Format("..\\Product.aspx?id={0}",strProductId) ;
                            
this.Context.RewritePath(newUrl) ;        
                        }

                        
break ;
                                
                    
case "midtype"://s-100100-All-2.aspx
                        strMatch = @"/midtype/(\S+-\d+-\S+-\d+)\.aspx" ;
                        
string strResult = SplitInfo(url,strMatch) ;
                                                
                        
if (strResult != null)
                        
{
                            
string[] strParam = strResult.Split('-') ;//MidtypeList.aspx?id=100100&city=威海&type=s&Page=3
                            if (strParam.Length != 4)
                                
break ;
                            
string city = AppGlobal.GetCityNameByCode(strParam[2]) ;
                            newUrl 
= string.Format("..\\MidtypeList.aspx?type={0}&id={1}&city={2}&page={3}",strParam[0],strParam[1],city,strParam[3]) ;
                            
this.Context.RewritePath(newUrl) ;        
                        }

                        
break ;                                        
                    
case "其它处理":
                        
break;
                    
default:
                        
break ;
                }


            }
                        
        }