查询字符串参数中的斜杠?

时间:2016-05-09 15:33:26

标签: c# asp.net-mvc url-routing

如何将文件路径作为查询字符串参数发送?

这是我的字符串参数:

  

//域/文件/ PDF / 1234.pdf

我试过了:

    [HttpPost]
    [Route("documents/print/{filePath*}")]
    public string PrintDocuments([FromBody] string[] docs,string filePath)
    {
       .....
    }

但这不起作用,我猜是因为参数开头的双斜杠。

有什么想法吗?

2 个答案:

答案 0 :(得分:8)

如果像您说的那样,整个字符串是参数,而不是路由,则需要对其进行URL编码。无论如何你应该总是这样做:

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?){

        let touch = touches.anyObject() as UITouch!
        let touchLocation = touch.locationInNode(self)
        let previousLocation = touch.previousLocationInNode(self)
        let distanceX = touchLocation.x - previousLocation.x
        let distanceY = touchLocation.y - previousLocation.y

        circle.position = CGPointMake(circle.position.x + distanceX, circle.position.y + distanceY)
}
  

更新

由于这不起作用,我建议你使用Base64编码而不是URL编码:

System.Net.WebUtility.UrlEncode(<your string>);
// %2F%2Fdomain%2Fdocuments%2FPdf%2F1234.pdf

..并在你的控制器解码它:

var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(<your string>);
var encodedFilePath = System.Convert.ToBase64String(plainTextBytes);

答案 1 :(得分:0)

System.Web.HTTPUtility.UrlEncode(@"//domain/documents/Pdf/1234.pdf")