2015-06-11 38 views
1

我只是設置了確認電子郵件方式在我的Web API,我發現這個代碼點點:UrlHelper的Web API的角度JS指出

var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = userId, code = code })); 

與查詢沿路徑轉換爲有效的網址字符串參數。 在我編寫自己的版本之前,我想知道是否已經有一種方法可以做同樣的事情,但沒有路由。

例如,上面的代碼位可以返回這樣的事情:

http://localhost:58127/api/users/Confirm?userId=something&code=another

,但這是不行的,我真的需要去我的應用程序URL這將是更像:

http://localhost:58127/#/users/confirm?userId=something&code=another

+0

您是否得到解決方案? –

回答

0

你可以用擴展一個小竅門:

public static class UrlHelperExtensions 
{ 
    public static string AngularLink(this UrlHelper urlHelper, string url, RouteValueDictionary data) 
    { 
     return urlHelper.Link(url, data).Replace("api/", "#/"); 
    } 
}