如何实现 如 http://localhost/123/这种网址可以打开,但实际上123目录在web服务器中是不存在的要求用asp.net 级别的url重写,如何实现?测试通过给满分

解决方案 »

  1.   

    <RewriterRule> 
    <LookFor>~/123</LookFor> 
    <SendTo>~/123/index.aspx </SendTo> 
    </RewriterRule> 
      

  2.   


    问题是没有目录,iis那一层就直接给我返回了,根本不会执行.net中的dll我现在就是不知道如何设置iis
      

  3.   

    最省事的你可以用URLRewriter组件来重写,
    假设你要把跟目录下的list.aspx重写为http://localhost/123/
    config配置可以这样写,
    <RewriterRule> 
    <LookFor>~/123 </LookFor> 
    <SendTo>~/list.aspx </SendTo> 
    </RewriterRule> 
      

  4.   

    http://blog.csdn.net/mngzilin/archive/2009/12/07/4959744.aspx
      

  5.   

    http://hi.baidu.com/i_love_yan/blog/item/0acd2459e294a7222934f0ce.html
    自个看
      

  6.   

    写个HttpMoudle或者HttpHandler,后面的问题主要是正则
      

  7.   

    当然用微软的URLRewriter更省事
      

  8.   

    需要用到两个技术点:
    一,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请求过来时会自动触发此事件
      

  9.   

    写个HttpMoudle
     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>进行相应的配置就可以了
      

  10.   


    你可以调试一下,.net1.0  像http://localhost/123/这种网址的话
    .net 服务端根本不会理的
    就是不会进void Application_BeginRequest(object sender,EventArgs e)
    这个函数的需要iis特殊设置,问题就是我现在不知道如何设置
      

  11.   

    还有就是14楼的思路跟15楼的思路,在urlrewrite上,那个效率更高我现在用的14楼的思路
      

  12.   

    在web.config配置如下,如果在web.config中没有配置是不生效的。
    <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
    所以呢效率那高你一看就明白了。
      

  13.   

    现在的问题是http://localhost/123/这种网址,IIS那一层检测出没有123目录就返回了,
    根本不会调用asp.net的dll,这是问题的关键,可能大家都没上机去测过
    程序是需要调试出来的,实践出真知,大家最好先上机调试下,成功了再跟我说下,非常渴望答案
      

  14.   

    楼主,你用的是httpmodel吗?你调试过没有?我给的代码是调过的,没有问题。
    你可以把你调试的代码贴出来,web.config配置也贴出来。
    httpmodel如果web.config配置错了是不生效的。
    程式是需要调的,你怎么调的?在什么环境调的?
      

  15.   

    对你这样的人没什么说的了,只有给一个全部代码,你去下吧,下了调试看看是你说的那样吗?
    顺便说一句:学都不会学呀。
    http://download.csdn.net/source/1964900
      

  16.   


    总感觉这里回答问题的人太浮躁了,希望大家回复的时候能给出建设性的建议.net1.0实现以上效果,马上给分,说话算话
      

  17.   


    其实我要下面这两幅图片就够了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