开发者

url rewriting - build paths

I have started to work on a site without url rewriting. Now, the request is to use friendly urls so i started to use Intelligencia.UrlRewriter.

Let's take an example:

I have a method:

 public static string getCategoriesIndexLink(string category)
{
    string baseUrl = getBaseUrl() + (String)HttpContext.GetGlobalResourceObject("Paths", "categorii.index");
    return baseUrl.AddQueryParam(CQueryStringParameters.CATEGORY, category);
}

which build this kind of urls

"~/Site/Categorii.aspx?category=$1"

Now i've added the following rule in web.config:

<rewrite url="~/Site/Categorii/(.+)" to="~/Site/Categorii.aspx?category=$1" />

The question is HOW i can make the above method to build that kind of nice url? So no longer return

 "~/Site/Categorii.aspx?category=m1"

but

"~/Site/Categorii/m1"

without beeing needed to modify its structure?

I mean, i have about 30 methods like the one from the above; it would be extremely helpfull if i ca开发者_运维问答n be guided to use a regex at the output of the methods iso modifying the url construction...

Thanks in advance...


you can use something like that

Match mExprStatic = Regex.Match(BaseURL+@"/Site/Categorii/m1", BaseUrl+@"/site/categorii/(?<category>\S*)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
 if (mExprStatic.Success || !string.IsNullOrEmpty(mExprStatic.Value))
 {
    string parameters = "?" + mExprStatic.Groups["category"].Value;
    if ((context.Request.QueryString.AllKeys != null) && (context.Request.QueryString.AllKeys.Length > 0))
    {
       foreach (string key in Request.QueryString.AllKeys)
              parameters += "&" + key + "=" + Request[key];
    }
  Server.Transfer("~/Site/Categorii.aspx" + parameters , false);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜