如何实现 如 http://localhost/123/这种网址可以打开,但实际上123目录在web服务器中是不存在的要求用asp.net 级别的url重写,如何实现?测试通过给满分
解决方案 »
- UDP打洞求解
- using Microsoft.Office.Interop.Excel 在哪里引入??
- .NET 操作FTP With Implicit SSL
- 归递返回问题
- 请问有没有断点续传的源代码?
- vs 2005 的TREE控件如果快速加载(WEB)
- 请问c#,winform的虚拟内存怎么释放
- 页面无刷新
- 自己写的小程序,中文繁简通,欢迎下载。散分!!!
- SOS各位阿哥:能否帮我改一下这个24点程序,用面向对象的方法,消除相同的输出字符串表达式,增加程序的可读性.急啊....各位大哥.谢谢拉/....
- 多线程条件下,如何让最后一个完成的线程通知主线程完成了
- 一个100分的程序 十个90分的程序 50个80分的程序 哪种更效率?
<LookFor>~/123</LookFor>
<SendTo>~/123/index.aspx </SendTo>
</RewriterRule>
问题是没有目录,iis那一层就直接给我返回了,根本不会执行.net中的dll我现在就是不知道如何设置iis
假设你要把跟目录下的list.aspx重写为http://localhost/123/
config配置可以这样写,
<RewriterRule>
<LookFor>~/123 </LookFor>
<SendTo>~/list.aspx </SendTo>
</RewriterRule>
自个看
一,Application_BeginRequest事件,这是Http请求激发的第一个事件,用它来判断页面的URL二,HttpContext的RewritePath方法,实现页面重定向靠它在网站根目录下添加一个全局类:Global.asax,在其中输入一个函数:
void Application_BeginRequest(object sender,EventArgs e)
{
string url=Request.Url.AbsolutePath;//获取请求的路径
if(url=="http://localhost/123/")
HttpContext.Current.RewritePath("~/default.aspx");
}Http请求过来时会自动触发此事件
public class testmodel : System.Web.IHttpModule
{
#region IHttpModule 成员 /// <summary>
/// 处置由实现 System.Web.IHttpModule 的模块使用的资源(内存除外)
/// </summary>
public void Dispose()
{
} /// <summary>
/// 初始化模块,并使其为处理请求做好准备。
/// </summary>
/// <param name="context"></param>
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
} void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
HttpContext context = application.Context;
string url = context.Request.Url.PathAndQuery;
if (url.IndexOf("/abc/") >= 0)
{
url = url.Replace("/abc/", ""); context.Response.Redirect("/" +url);
}
} #endregion
}
然后后在web.config的<httpModules></httpModules>进行相应的配置就可以了
你可以调试一下,.net1.0 像http://localhost/123/这种网址的话
.net 服务端根本不会理的
就是不会进void Application_BeginRequest(object sender,EventArgs e)
这个函数的需要iis特殊设置,问题就是我现在不知道如何设置
<configuration>
<system.web>
<httpModules>
<add name="testmodel" type="TestWeb.testmodel,testmodel" />
</httpModules>
</system.web>
</configuration>
效率问题:
httpmodules中部分事件同Global.asax中的事件相对应,对应关系如下:
HttpModule Global.asax
BeginRequest Application_BeginRequest
AuthenticateRequest Application_AuthenticateRequest
EndRequest Application_EndRequest
所以呢效率那高你一看就明白了。
根本不会调用asp.net的dll,这是问题的关键,可能大家都没上机去测过
程序是需要调试出来的,实践出真知,大家最好先上机调试下,成功了再跟我说下,非常渴望答案
你可以把你调试的代码贴出来,web.config配置也贴出来。
httpmodel如果web.config配置错了是不生效的。
程式是需要调的,你怎么调的?在什么环境调的?
顺便说一句:学都不会学呀。
http://download.csdn.net/source/1964900
总感觉这里回答问题的人太浮躁了,希望大家回复的时候能给出建设性的建议.net1.0实现以上效果,马上给分,说话算话
其实我要下面这两幅图片就够了windows2003
windows xp iis
IIS 设置
executable:C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll
extension : .*
limitto:HEAD,GET,POST
script engine checked
check the file exists unchecked