在MapRoute上使用破折号或网址

问题描述

我尝试从用户那里获取URL并提供如下所示的MapRoute:

var xhr = new XMLHttpRequest();
xhr.open("POST","http://127.0.0.1:6969/plzWork",true);
xhr.send(null);
xhr.onreadystatechange = function() {
     if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
          console.log(xhr.responseText);
     }
}

在这种情况下,它适用于以下网址:“ / tools / www.domain.com /”

但是我该如何管理这样的网址:“ / tools / www.domain.com / view / child / child /?id = 4”

路线找不到这样的地址。

解决方法

您可以在nexy maproute中使用catchall或使用它代替id。

,

您不能直接将URL作为参数传递。您必须传递查询字符串。

在传递URL之前,您必须对URL进行编码。

请在下面输入我的URL,以获取通行证“ /tools/www.domain.com/view/child/child/?id=4 ”。

http:// localhost:54964 / Home / Index?id = www.domain.com%2Fview%2Fchild%2Fchild%2F%3Fid%3D4

我在方法的id参数中得到了值。

public ActionResult Index(string id)
{
            return View();
}