首页 新闻 会员 周边 捐助

.NET如何写Nancy路由

0
悬赏园豆:10 [已解决问题] 解决于 2017-01-12 11:14

xxx/result?indexID=1&dimensionID=2

类似这样的RUL如何在Module类中写他的路由?

Get("/analysis/result?indexID={indexID}&dimensionID={dimentionID}", _ => GetAnalysisResult((string)(_.indexID),((string)_.dimentionID)));

这样写了网页提示:

 

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:9001/api/analysis/result?indexID=1&dimensionID=2&queryCriteria=3'.
</Message>
<MessageDetail>
No route providing a controller name was found to match request URI 'http://localhost:9001/api/analysis/result?indexID=1&dimensionID=2&queryCriteria=3'
</MessageDetail>
</Error
WCode的主页 WCode | 初学一级 | 园豆:103
提问于:2017-01-11 15:15
< >
分享
最佳答案
0

不用这么麻烦的!!

?后面的可以不用在路由上指出的!通过Request.Query来获取就可以了!

1            Get("/analysis/result", args =>
2             {
3                 var indexID = this.Request.Query["indexID"];
4                 var dimentionID = this.Request.Query["dimentionID"];
5                 return indexID + "--" + dimentionID;
6             });

收获园豆:10
Catcher8 | 菜鸟二级 |园豆:364 | 2017-01-11 20:04
1 Get("/analysis/result/{indexID:int}/{dimentionID:int}", args =>
2 {
3         var indexID = args.indexID;
4          var dimentionID = args.dimentionID;
5          return indexID + "--" + dimentionID;
6 });

也可以尝试这样的写法

 

Catcher8 | 园豆:364 (菜鸟二级) | 2017-01-11 20:07

@Catcher8: 嗯,问题找到了,时因为存在一个路由冲突,所以一直访问失败~按你说的确实也是可行的

WCode | 园豆:103 (初学一级) | 2017-01-12 11:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册