我在重写网址时遇到问题 [英] I have problem in Rewrite url

查看:57
本文介绍了我在重写网址时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动态菜单,动态元标题,meta descritption。我通过stringbuilder动态绑定所有数据,它们的格式是default.aspx?ID = 1.我需要查询字符串,因为每个页面都会动态绑定。现在,我在Rewrite中遇到问题url.i在下面编写了所有这些代码。 br />


注意:对于菜单绑定我有用户控制,对于元标题和说明我有主页。

i更改网络配置以进行所需的更改。



*****问题是在代码下方绑定以便正确更改网址。******

I have dynamic menu, dynamic meta title,meta descritption. I am binding all the data dynamically through stringbuilder and their format is default.aspx?ID=1.here I need querystring because each page will be bind dynamically.Now, i have problem in Rewrite url.i wrote all these code below.

Note:for menu bind i have user control and for meta title and desciption i have masterpage.
i changes web config for required changes.

*****problem is where to bind below code for proper change in url.******

public static string GenerateURL(object Title)
        {
            string strTitle = Title.ToString();

            strTitle = strTitle.Trim();
            strTitle = strTitle.Trim('-');

            strTitle = strTitle.ToLower();
            char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
            strTitle = strTitle.Replace("c#", "C-Sharp");
            strTitle = strTitle.Replace("vb.net", "VB-Net");
            strTitle = strTitle.Replace("asp.net", "Asp-Net");
            strTitle = strTitle.Replace(".", "-");
            for (int i = 0; i < chars.Length; i++)
            {
                string strChar = chars.GetValue(i).ToString();
                if (strTitle.Contains(strChar))
                {
                    strTitle = strTitle.Replace(strChar, string.Empty);
                }
            }
            strTitle = strTitle.Replace(" ", "-");

            strTitle = strTitle.Replace("--", "-");
            strTitle = strTitle.Replace("---", "-");
            strTitle = strTitle.Replace("----", "-");
            strTitle = strTitle.Replace("-----", "-");
            strTitle = strTitle.Replace("----", "-");
            strTitle = strTitle.Replace("---", "-");
            strTitle = strTitle.Replace("--", "-");
            strTitle = strTitle.Trim();
            strTitle = strTitle.Trim('-');
            strTitle = "~" + strTitle;

            return strTitle;
        }

推荐答案

%#@!*?;:~` + =()[] {} | \ '<>,/ ^&。。ToCharArray();
strTitle = strTitle.Replace(c#,C-Sharp);
strTitle = strTitle.Replace( vb.net,VB-Net);
strTitle = strTitle.Replace(asp.net,Asp-Net);
strTitle = strTitle.Replace(。, - );
for(int i = 0; i< chars.Length; i ++)
{
string strChar = chars.GetValue(i).ToString();
if(strTitle.Contains(strChar))
{
strTitle = strTitle.Replace(strChar,string.Empty);
}
}
strTitle = strTitle .Replace(, - );

strTitle = strTitle.Replace( - , - );
strTitle = strTitle.Replace(--- , - );
strTitle = strTitle.Replace(----, - );
strTitle = strTi tle.Replace(-----, - );
strTitle = strTitle.Replace(----, - );
strTitle = strTitle.Replace(---, - );
strTitle = strTitle.Replace( - , - );
strTitle = strTitle.Trim();
strTitle = strTitle.Trim(' - ');
strTitle =〜+ strTitle;

返回strTitle;
}
%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray(); strTitle = strTitle.Replace("c#", "C-Sharp"); strTitle = strTitle.Replace("vb.net", "VB-Net"); strTitle = strTitle.Replace("asp.net", "Asp-Net"); strTitle = strTitle.Replace(".", "-"); for (int i = 0; i < chars.Length; i++) { string strChar = chars.GetValue(i).ToString(); if (strTitle.Contains(strChar)) { strTitle = strTitle.Replace(strChar, string.Empty); } } strTitle = strTitle.Replace(" ", "-"); strTitle = strTitle.Replace("--", "-"); strTitle = strTitle.Replace("---", "-"); strTitle = strTitle.Replace("----", "-"); strTitle = strTitle.Replace("-----", "-"); strTitle = strTitle.Replace("----", "-"); strTitle = strTitle.Replace("---", "-"); strTitle = strTitle.Replace("--", "-"); strTitle = strTitle.Trim(); strTitle = strTitle.Trim('-'); strTitle = "~" + strTitle; return strTitle; }


这篇关于我在重写网址时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆