[英]URL Rewrite ASP.net
我有一個asp.net網站,我需要使用URL重寫,所以我寫了一個HTTP模塊,並且已經實現了它,並且它可以正常工作,唯一的問題是當頁面重定向到其對應的地址時,圖像和樣式是未加載。
這是http模塊:
//您的BeginRequest事件處理程序。
private void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
string URL = application.Request.Url.ToString();
//int pid = Convert.ToInt32(application.Request.QueryString["pid"]);
if ((URL.ToLower().Contains(".aspx"))
|| (URL.ToLower().Contains(".js"))
|| (URL.ToLower().Contains(".css"))
|| (URL.ToLower().Contains(".gif"))
|| (URL.ToLower().Contains(".png"))
|| (URL.ToLower().Contains(".jpeg"))
|| (URL.ToLower().Contains(".jpe"))
|| (URL.ToLower().Contains(".jpg"))
|| (URL.ToLower().Contains(".ashx")))
return;
else
{
string mname = URL.Substring(URL.LastIndexOf("/") + 1).ToString();
Merchand ms = merchantDB.GetMerchant(mname);
HttpContext context = application.Context;
if (ms != null)
{
string url = "~/pages/Merchant.aspx?mid=" + ms.MerchandID + "&catid=" + ms.MainCategory + "&subcatid=0";
context.RewritePath(VirtualPathUtility.ToAppRelative(url));
}
else
{
//("");
string url = "~/pages/default.aspx";
context.RewritePath(VirtualPathUtility.ToAppRelative(url));
}
}
}
當我從普通網址打開頁面時,它可以很好地打開,但是當我使用該網址重寫時,它打開卻沒有圖像或樣式。
當我打開螢火蟲時,出現錯誤,找不到CSS和javascript
若要使重寫與IIS一起使用,請執行以下操作:
<modules> <add name="Rewrite" type="Rewrite"/> </modules>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.