2016-02-16 28 views
0

我有麻煩將圖像網址傳遞給我的API控制器。通過獲取參數asp-net發送網址Api

控制器:

[HttpGet] 
    [Route("cont/getByUrl/{url}")] 
    public string Get(string url) 
    { 
     //code   

    } 

我的Ajax調用

$.ajax({ 
     url: "http://localhost:64444/api/cont/getByUrl/"+ encodeURIComponent("http://www.moooi.com/sites/default/files/styles/large/public/product-images/random_detail.jpg?itok=ErJveZTY"), 
     type: 'GET' 
    }); 

如果我的參數是一個簡單的字符串,我到那裏,但如果我發送一個地址始終有404,我使用IIS 7.5。

我需要對Web.config進行一些更改,或者我無法做到這一點?

回答

-1

而不是路由您可以使用ActionName。

用於用戶控制器中的爲例:

// Get: api/Users/GetPostUser 
[HttpGet, ActionName("GetPostUser")] 

該鏈接將是這樣的:http://localhost:64444/api/Users/GetPostUser(使用正確的端口)