URL Rewrite ASP.net

Posted by wandos on Stack Overflow See other posts from Stack Overflow or by wandos
Published on 2012-10-18T08:43:05Z Indexed on 2012/10/29 11:01 UTC
Read the original article Hit count: 149

Filed under:
|

i have an asp.net website where i need to use URL re-write so i have written an HTTP module and i have implemented it and it works correctly the only problem is when the page redirect to its corresponding address the images and the styles are not loaded.

here is the http module:

// Your BeginRequest event handler.

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

}

when i open the page from it normal URL it opens fine, but when i use the url rewrite it open but with out images or styles.

when i open firebug i get an error that the css and the javascript are not found

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about url-rewriting