关于url重写

deknight 2010-06-24 03:13:59
某url,比如 index.aspx?id=100
当然,ID是变化的,要求是,当ID为3位数时,重写到
index.aspx?id=1100,也就是加了1000

如果是4位的ID,则重写后ID加1W
index.aspx?id=1000
重写为
index.aspx?id=11000

也就是需要判断ID是位数,该如何写?
...全文
71 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
deknight 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 linmingtao 的回复:]
C# code


string temp = "index.aspx?id=1100";
int int_temp = temp.IndexOf("?id=");
string temp1 = temp.Substring(0,int_temp + 4);
string temp2 = "1" + temp.Substring(int_temp + 4,temp.Length - i……
[/Quote]
................
誰是方長 2010-06-24
  • 打赏
  • 举报
回复
顶下回复内容太短了!
linmingtao 2010-06-24
  • 打赏
  • 举报
回复


string temp = "index.aspx?id=1100";
int int_temp = temp.IndexOf("?id=");
string temp1 = temp.Substring(0,int_temp + 4);
string temp2 = "1" + temp.Substring(int_temp + 4,temp.Length - int_temp - 4);

temp = temp1 + temp2;


hbdsz 2010-06-24
  • 打赏
  • 举报
回复
正则
index.aspx?id=(\d{3,}) index.asp?id=1$1
ID三位数以上,前面加1
UrlRewriter
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>index.aspx?id=(\d{3,})</LookFor>
<SendTo>index.asp?id=1$1</SendTo>
</RewriterRule>
</Rules>
<RewriterConfig>

deknight 2010-06-24
  • 打赏
  • 举报
回复
不固定
ledmhcc 2010-06-24
  • 打赏
  • 举报
回复
id= 这个固定吗?
固定的只要用字符串截断出来判断下就知道=后面是几位数,然后生成比位数多一个的数字相加
deknight 2010-06-24
  • 打赏
  • 举报
回复
没人会吗

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧