【问题标题】:Url Rewriting of aspx page.pls give me suggestionurl重写aspx page.pls给我建议
【发布时间】:2016-05-10 17:39:46
【问题描述】:

我是 asp.net 的新手。我有 iis 版本 6.0。我想重写网址。其实我在一个网站上工作。当我在web.config 中使用这个标签时

  <urlrewritingnet
    rewriteOnlyVirtualUrls="true"
    contextItemsPrefix="QueryString"
    defaultPage="default.aspx"
    defaultProvider="RegEx"
    xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >
    <rewrites>
      <add name="this-is-a-long-page-name"  virtualUrl="^~/this-is-a-long-page-name"
            rewriteUrlParameter="ExcludeFromClientQueryString"
            destinationUrl="~/Default.aspx"
            ignoreCase="true" />
    </rewrites>
  </urlrewritingnet>

当我运行它时,它显示错误“无法识别的配置节重写器”。

【问题讨论】:

    标签: c# asp.net iis url-rewriting


    【解决方案1】:

    用户,

    你需要实现 urlrewritemodule ,所有的请求都来自 urlrewritemodule。 你可以在那里写你的逻辑

    public  class UrlModule : IHttpModule
        {
            public virtual void Init(HttpApplication application)
            {
                application.BeginRequest += new EventHandler(this.BaseUrlModule_BeginRequest);
            }
            public virtual void Dispose()
            {
            }
            protected virtual void BaseUrlModule_BeginRequest(object sender, EventArgs e)
            {
                HttpApplication application = (HttpApplication)sender;
                Rewritethepath(application.Request.Path, application);
            }
    
            private  void Rewritethepath(string requestedPath, HttpApplication application)
            {
               application.Context.RewritePath("/yournewurl", String.Empty, QueryString);                
            }
        }
    

    在您的 web.config 中创建此条目

    <httpModules>
                    <add type="namespace.UrlModule, namespace" name="UrlModule"/>
                </httpModules>
    

    在你的 web.config 中注册你的 httpmodule,一旦每一个请求都来了,你可以根据需要重写 url,

    我最近实现了这一点,如果您需要任何帮助,请告诉我,我将竭诚为您提供帮助。

    【讨论】:

    • 请告诉我我对 web.config 做了任何更改
    • 在您的配置部分添加 httpModules,如果它是一个单独的 dll,则将此 dll 放在 bin 文件夹中。
    • 哪个 dll.i 不知道请建议我` ` 我在 web.config 中添加这个给出错误
    • 无法加载文件或程序集“命名空间”或其依赖项之一。该系统找不到指定的文件。我添加了它` `
    • 用户,您应该更改命名空间,使用您的库名称,您在项目中定义 urlModule 的位置,在此处给出该名称
    【解决方案2】:

    我的回复没有直接回答您的问题(关于 UrlRewritingNet 库)。相反,我建议考虑微软官方的IIS URL Rewrite 库,它需要IIS 7.x 或IIS Express。 UrlRewritingNet 库虽然在几年前很有用,但现在在 IIS/ASP.NET 中重写 URL 的方法并不理想。我提出这个建议是因为您提到您是 ASP.NET 的新手。 :)

    【讨论】:

    • 我有 iis6.0。有什么办法可以用 iis6.0 重写 url
    猜你喜欢
    • 2011-12-24
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 2013-09-15
    • 2011-01-07
    • 1970-01-01
    相关资源
    最近更新 更多