[英]Url Rewriting of aspx page.pls give me suggestion
我是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>
當我運行它時,它顯示錯誤“無法識別的配置節重寫器”。
用戶,
您需要實現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,
我最近實施了此功能,如果您需要任何幫助,請告訴我,我們將竭誠為您服務。
我的回答沒有直接回答您的問題(與UrlRewritingNet庫有關)。 相反,我建議考慮使用Microsoft的正式IIS URL Rewrite庫,該庫需要IIS 7.x或IIS Express 。 UrlRewritingNet庫雖然在幾年前很有用,但現在已經不是在IIS / ASP.NET中重寫URL的理想方法。 因為您提到您是ASP.NET的新手,所以我提供了此建議。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.