dottext学习笔记3 URL重写
2006-09-17 21:49
302 查看
1 配置
1.1 IIS配置
指定*.*跟*.aspx等一样,其映射到 aspnet_isapi.dll ISAPI 扩展。这样对性能有很大的影响,因为img,目录等资源都要由aspnet_isapi.dll来解析。
如果不这样的话,指定不存在文件就会出现404错误,网上有定义404错误时重导到ASPX页面,再根据path类型返
string errorString = context.Request.RawUrl.ToLower();
errorString == /xxx/404.aspx?404;http://localhost/rewritetest/123456
红体就是原始请求
1.2 Web.config配置
1.2.1 <system.web>节中定义URL重转实现类
1.httpHandlers指定了Error.aspx和*.asmxl类型页面的后台类为系统类,而为指定的所有类型后台类为UrlReWriteHandlerFactory2.httpModules分别指定了EventHttpModule和UrlReWriteModule作为所有页面的URL请求时的处理。
1.2.2 具体URL重转的实现类配置
1. 在configSections指定解释HandlerConfiguration节的配置解析类为XmlSerializerSectionHandler2. 该节捆绑的类为HandlerConfiguration,相当类厂
3. <HttpHandlers>节包含很多HttpHandler, HttpHandler后台捆绑页面或类(增加属性handlerType进行区分),若是类均派生自System.Web.IHttpHandler或者IHttpHandlerFactory。
2 类分析
URL处理调用流顺序依次流过n个HttpMoudules,才到Handlers2.1 HttpModules后台类
均从System.Web.IHttpModule派生Dottext.Common.UrlManager.UrlReWriteModule
捕捉BeginRequest
public void Init(HttpApplication context)
{
context.BeginRequest +=new EventHandler(context_BeginRequest);
}
context_BeginRequest:
else if(context.Request.Path.ToLower().IndexOf("services") > 0 && context.Request.Path.ToLower().IndexOf(".asmx") > 0 )
...{
if(AlllowService(context))
...{
if(context.Request.RequestType!="POST")
...{
string regexstr=@"/w+/services/";
string url=Regex.Replace(context.Request.RawUrl,regexstr,"/services/",RegexOptions.IgnoreCase);
context.RewritePath(url);
}
//string fileName =context.Request; //System.IO.Path.GetFileName(context.Request.Path);
//context.RewritePath("~/Services/" + fileName);
}
else
...{
context.Response.Clear();
context.Response.End();
}
}
另外还有一个HttpModule:
Dottext.Framework.ScheduledEvents.EventHttpModule
处理定时器,定时调用EventManager.Execute();
2.2 HttpHandlers后台类
UrlReWriteHandlerFactory,派生自IHttpHandlerFactory,GetHandler URL重转类厂实现分析:
a. 截取URL的具体页面名
path = Regex.Replace(Request.Path,"^"+Request.ApplicationPath,string.Empty,RegexOptions.IgnoreCase);
b. 把path跟所有类厂所管理的处理器进行匹配,对匹配的处理根据其类型进行不同的处理
Page:默认。根据具体实现类增加配置中的控件名列表到context中,待后面会用。然后PageParser.GetCompiledPageInstance(url,pagepath,context);来生成页面。
Direct:同上设置控件名列表,同时return (IHttpHandler)items[i].Instance();
Factory:转交factory生成,return ((IHttpHandlerFactory)items[i].Instance()).GetHandler(context,requestType,url,path);
3 页面跳转方法
1. Response.Redirect,在客户端跳转,可以使用Session对象传递,不能使用Context对象传递。2. Server.Transfer,在服务器端跳转,可以使用Session对象传递,也可以使用Context传递。
注意的是,Context对象在页面跳转后即消失,Session对象在Session的有效期内始终存在. ViewState是在本页面保存,因为该方式是将要保存的对象序列化后放在客户端页面中保存,所以保存的对象必须是可序列化的.
3. Server.Execute,在当前位置放置另外一个aspx页面,可合并两个源文件的页面
4. HttpContext.RewritePath 方法,分配一个内部重写路径。
RewritePath 允许请求的 URL 与资源的内部路径有所不同。RewritePath 用于无 cookie 的会话状态中。
5. JavaScritp和VBScrio
A. document.URL属性,如document.URL="edit1.htm";
B. window.location.href
<input type="button" name="jump" value="跳转" onclick=window.location.href="page2.asp";>
function logout(){
if (confirm("你确定要注销身份吗?/n是-选择确定,否-选择取消")){
window.location.href="logout.asp?act=logout"
}
C. window.open
window.open("page2.asp?ID="+id+"&act=del","top","width=640,height=400")
function logout(){
if (confirm("你确定要注销身份吗?/n是-选择确定,否-选择取消")){
window.location.href="logout.asp?act=logout"
}
D. Response.Redirect
<%@ Language="VBScript" %>
<%
Response.Redirect(Request.ServerVariables("URL") & "x?" & & Request.QueryString)
//Response.Transfer(Request.ServerVariables("URL") & "x" ) 会出错,因为asp解析器不能解析aspx的文件
%>
相关文章推荐
- Servlet学习笔记---重写URl地址(编码问题)
- 4.19学习笔记:android电量排行、okhttp与SPYD协议、重写editview的addTextChangedListenerBUG
- dottext学习笔记2 master构造
- ASP.NET Core 2 学习笔记(八)URL重写
- dottext学习笔记4 登陆页面
- JSP学习笔记(二十九):利用urlrewrite重写url
- python nltk 学习笔记(3) processing raw text
- 学习笔记之 —— 一个textview控件搞定中间文本左右两张图
- [网络编程学习笔记]Web 概念:URI,URN和URL
- Flask_学习笔记_03: URL反转
- URL重写,asp.net URL重写,URLRewriter.dll下载,URLRewriter,URLRewriter下载,URL重写学习(初级篇)
- learning jQuery 学习笔记十五(+jQuery 1.4.1 API)-- AJAX----load(url, [data], [callback])
- UrlReWriter.net学习笔记
- windows phone7 学习笔记04——重写返回键
- Java学习笔记(12)Exception Handling and Text I/O
- <第三章>Node 学习笔记 |>URL网站解析<|
- 170314学习笔记--url参数乱码
- UrlRewriteFilter 学习笔记
- accelerated C++ 中查找url(学习笔记)
- AutoCompleteTextView与MultiAutoCompleteTextView学习笔记