如何避免ASP.Net(或IIS?)解码我的URL编码密文(导致404)而不是将它传递给批准脚本?

问题描述:

我正在使用ASP.Net MVC中的一个Web应用程序,其中用户使用sql成员资格提供程序注册成员身份。当他们注册时,他们被放入系统但未被批准。代码然后通过给定的电子邮件向用户发送批准电子邮件。如何避免ASP.Net(或IIS?)解码我的URL编码密文(导致404)而不是将它传递给批准脚本?

BfEncrypt refid = new BfEncrypt(); 
refid.Encrypt(user.ReferenceID); 
string code = HttpContext.Current.Server.UrlEncode(refid.CipherText); 
    ... 
Body += "<a href=\"http://localhost:1091/approve/" + code + "\">Approval Link</a>\n\r\n\r"; 

但是,当用户点击他们收到以下错误链接:

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Approve/k/9IHrY43os=

的问题是,如果我编码链接的URL之前,我送它,为什么之前解码它会尝试调用该操作?当我收到错误信息时,浏览器中的网址实际上是'http://localhost:1091/Approve/k%2f9IHrY43os%3d'。我的路由设置正确,但它没有考虑URL中加密字符串中额外的'/'(因为它不应该在那里)

您可以将它编码为base64而不是使用URLEncode。

+0

工作就像一个魅力,非常感谢 – 2009-02-23 18:54:14