V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
whoami9894
V2EX  ›  C#

C# MVC 路由传参的问题

  •  
  •   whoami9894 · 2019-07-25 17:13:03 +08:00 · 6957 次点击
    这是一个创建于 1708 天前的主题,其中的信息可能已经有所发展或是发生改变。

    遇到某 C#项目

    路由配置: RouteConfig:

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    

    这里有个 FileController 中的函数,签名为public AResult Fetch(string url),需要传 URL 参数,我尝试 URL 编码了/:.等字符但好像还是有问题,这里正确方法应该如何调用?

    同样的还有一个 Delete 函数:

    public void Delete(string filePath)
    {
        UploadCls.Delete(filePath);
    }
    
    public static bool UploadCls::Delete(string filePath)
            {
                try
                {
                    File.Delete(filePath);
                    return true;
                }
                catch { }
                return false;
            }
    

    在参数中传..%2F服务器会一直无响应

    1 条回复    2019-07-26 12:34:59 +08:00
    Pursue9
        1
    Pursue9  
       2019-07-26 12:34:59 +08:00
    [HttpDelete("delete/{filePath?}")]
    public IActionResult Delete([FromRoute]string filePath)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3760 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:54 · PVG 08:54 · LAX 17:54 · JFK 20:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.