[英]url rewriting - build paths
I have started to work on a site without url rewriting. 我已经开始在没有url重写的网站上工作。 Now, the request is to use friendly urls so i started to use Intelligencia.UrlRewriter. 现在,请求是使用友好的URL,因此我开始使用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: 现在,我在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? 问题是我如何可以使用上述方法来构建那种漂亮的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; 我的意思是,我有大约30种上述方法。 it would be extremely helpfull if i can be guided to use a regex at the output of the methods iso modifying the url construction... 如果可以指导我在修改url结构的方法的输出端使用正则表达式,那将非常有帮助...
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.