C#如何实现网址编码?

label_xl 2008-07-11 12:54:29
https://forum.csdn.net/PointForum/Forum/PostTopic.aspx
一个这样的url 如何让编码让他显示成类型下面这样
https://forum.csdn.net/$%23$%#$%@#34$%#.asp
...全文
339 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
label_xl 2008-07-11
  • 打赏
  • 举报
回复
补充一下。。就是在哪写。。。具体点 写个例子吧 谢谢!
sheng9hhd 2008-07-11
  • 打赏
  • 举报
回复

/// <summary>
/// 加密
/// </summary>
/// <param name="strText">需要加密的数据</param>
/// <param name="strEncrKey">8位公钥</param>
/// <returns>加密后的字符串</returns>
public static string DesEncrypt(string strText, string strEncrKey)
{
byte[] byKey = null;
byte[] IV ={ 0x1A, 0xC0, 0xEE, 0x87, 0x9C, 0x11, 0x5D, 0x76 };
try
{
byKey = Encoding.UTF8.GetBytes(strEncrKey.Substring(0, strEncrKey.Length));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
}

/// <summary>
/// 解密
/// </summary>
/// <param name="strText">需要加密的数据</param>
/// <param name="sDecrKey">8位公钥</param>
/// <returns>解密后的字符串</returns>
public static string DesDecrypt(string strText, string sDecrKey)
{
byte[] byKey = null;
byte[] IV ={ 0x1A, 0xC0, 0xEE, 0x87, 0x9C, 0x11, 0x5D, 0x76 };
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = Encoding.UTF8.GetBytes(sDecrKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
Encoding encoding = new UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{
return ex.Message;
}
}
label_xl 2008-07-11
  • 打赏
  • 举报
回复
字符串怎么加密啊?
billclinton8 2008-07-11
  • 打赏
  • 举报
回复
对了 忘了说了 加密后 在编码 有可能加密后有些字符在URL要遍
billclinton8 2008-07-11
  • 打赏
  • 举报
回复
用字符串加密就可以了
label_xl 2008-07-11
  • 打赏
  • 举报
回复
string url = "/Lessons/Dialogue.aspx?lId=179&id=root_1_35_0";

this.Response.Redirect(Server.UrlEncode(url));
我这样写 页面会出现 错误 "HTTP 閿欒 400 - Bad Request銆?/i> "
label_xl 2008-07-11
  • 打赏
  • 举报
回复
解码和编码有什么区别 解码是不是还是原来的网址 没有变化啊?
编程有钱人了 2008-07-11
  • 打赏
  • 举报
回复

<a href=index.aspx?id=Server.UrlDecode(<%#Eval("id")%>)></a>
<!-- 或者-->
https://forum.csdn.net/Server.UrlDecode(<%#Eval("name")%>.aspx
sheng9hhd 2008-07-11
  • 打赏
  • 举报
回复
类似UrlRewriter,写在httpmodule里面
sheng9hhd 2008-07-11
  • 打赏
  • 举报
回复
加解密的吧,这样不利于seo啊

61,817

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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