开发者

Url Rewriting of aspx page.pls give me suggestion

I am开发者_开发知识库 new in asp.net. I have iis version 6.0. I want to rewrite url. Actually I'm working on a site. When I used this tag in 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>

When I run it, it shows the error "unrecognized configuration section rewriter".


user ,

you need to implement urlrewritemodule , all the requests comes to the urlrewritemodule. you can write your logic there

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);                
        }
    }

make this entry in your web.config

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

Register your httpmodule in your web.config , once everyrequest comes to this you can rewrite the url however you want ,

i recently implemented this and let me know if you need any help, I will defiently help you.


My response doesn't directly answer your question (which is about the UrlRewritingNet library). Instead, I suggest considering Microsoft's official IIS URL Rewrite library, which requires IIS 7.x or IIS Express. The UrlRewritingNet library, though useful a couple years ago, is now a less than ideal way to go about rewriting URLs in IIS/ASP.NET. I offer this suggestion since you mentioned you are new to ASP.NET. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜