我已将项目从webapi升级到webapi2,现在正在使用属性路由.我有一个方法,我使用Url helper获取url.哪个是替换Url helper的最佳方法(因为这不适用于属性).
我的旧用法示例代码:
protected Uri GetLocationUri(object route, string routeName = WebApiConfig.RouteDefaultApi)
{
string uri = Url.Link(routeName, route);
return new Uri(uri);
}
Run Code Online (Sandbox Code Playgroud)
路线配置:
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: RouteDefaultApi,
routeTemplate: "{controller}/{id}/{action}",
defaults: new { id = RouteParameter.Optional, action = "Default" }
);
}
Run Code Online (Sandbox Code Playgroud)
用法:
Uri myUrl = GetLocationUri(route: new { action = "images", id = eventId });
Run Code Online (Sandbox Code Playgroud) 在webapi2中使用DataMember和JsonProperty有什么区别?任何性能差异?什么是首选使用?
谢谢!安德烈亚斯