其实是用来做伪静态的。求一段代码,或者算法
要根据相应的html文件名字符串分析出对应带参数的aspx文件的路径来。section-sid_9-t_0-p_1.html 对应 section.aspx?sid=9&t=0&p=1
section-nid_3-t_1.html 对应 section.aspx?nid=3&t=1
section-cid_1-p_3.html 对应 secion.aspx?cid=1&p=3
section-p_16.html 对应 section.aspx?p=16
seciton-cid_1.html 对应 secion.aspx?cid=1要是有好的伪静态文件命名格式,能解决问题,也可以。
要根据相应的html文件名字符串分析出对应带参数的aspx文件的路径来。section-sid_9-t_0-p_1.html 对应 section.aspx?sid=9&t=0&p=1
section-nid_3-t_1.html 对应 section.aspx?nid=3&t=1
section-cid_1-p_3.html 对应 secion.aspx?cid=1&p=3
section-p_16.html 对应 section.aspx?p=16
seciton-cid_1.html 对应 secion.aspx?cid=1要是有好的伪静态文件命名格式,能解决问题,也可以。
解决方案 »
- 非托管资源如何理解?
- C#数据库编程的问题..
- 如何取得sqlserver数据库中各表之间的关系?
- TIMER时间控件,有朋友用过吗,怎么实现每隔一秒钟,执行一次,请详细点
- Label控件
- 急急急急急急急急急我在listView列表(图标中)中如何实现双击事件,请各位大使指点.急急急急急急急急急急
- 【stackoverflow上没有得到关注和解答,回CSDN试试,懒得翻译回中文,凑合看看吧!你们也该练习下英语了!】
- 求:客户端批量添加记录,然后在服务器一次更新的例子!!最好可以直接运行的例子~~
- 怎样在DATAGRID中实现用两个select按钮分别完成不同的功能。(就是如何分辨select按钮的ID或怎样分辨)
- 正在开发ASP.NET网站,诚邀同道!!!
- .Net 分析文章语句代码
- 【online】winform的textbox和statusstip问题
dim i as integer=instr(str,"-")
str=mid(str,1,i-1) & ".aspx?" & mid(str,i+1)
i=instr(str,"_")
str=mid(str,1,i-1) & "=" & mid(str,i+1)
...
...
可以吗?
主要是能找到规则吧
这个代码是可以,不过我的意思是通过一种方法能适应上面几种html文件名的格式。
不是只针对某一种格式单独写一段代码比如我有个方法 string a(string value);
当我调用 a(静态文件名)的时候就能返回相应的动态路径来。
string test = "section.aspx?sid=9&t=0&p=1";
string result = Regex.Replace(test, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; });
{
string result = Regex.Replace(value, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; });
}
大哥,你这个很nb的,帮我写一个反算的,根据html格式算aspx格式的。
很明显,你这是URL重写,几乎每个访问的页面都会用到这个函数,那么性能方面就很重要,宁可写得复杂一点,但是性能要好,不能求简单用正则表达式。
{
return value.Replace(".html", "").Replace("section-", "section.aspx?").Replace("-", "&").Replace("_", "=");
}
怎么不对你贴出例子。
static void Main(string[] args)
{
string[] test = new string[] { "section.aspx?sid=9&t=0&p=1", "section.aspx?nid=3&t=1", "section.aspx?cid=1&p=3", "section.aspx?p=16", "section.aspx?cid=1" };
foreach (string s in test)
{
Console.WriteLine(a(s) + " 对应 " + s);
}
Console.ReadKey();
}static string a(string value)
{
return Regex.Replace(value, @"\.aspx\?|[=&]", delegate(Match m) { return m.Length == 1 ? "_" : "-"; })+".html";
}
结果:
section-sid_9_t_0_p_1.html 对应 section.aspx?sid=9&t=0&p=1
section-nid_3_t_1.html 对应 section.aspx?nid=3&t=1
section-cid_1_p_3.html 对应 section.aspx?cid=1&p=3
section-p_16.html 对应 section.aspx?p=16
section-cid_1.html 对应 section.aspx?cid=1你提问的自己要吧问题描述清楚。而且。你例子是错的。section,有些笔误的,这是笔误还是既定情况?允许secion的?你要说明白。否则写再多都是白写。
public static String ChangeFormat(String str)
{
Int32 i = str.IndexOf('-');
if (i < 0)
{
return str.Substring(0, str.IndexOf('.')) + ".aspx";
}
else
{
String start = str.Substring(0, i) + ".aspx?";
String temp = str.Substring(i + 1, str.IndexOf('.') - i - 1);
return start + temp.Replace('_', '=').Replace('-','&');
} }