c# - adding Route Attribute to ApiController -


i'm developing asp.net web api app .net framework 4.0 , c#.

i have this:

using system; using system.collections.generic; using system.linq; using system.net; using system.net.http; using system.web.http;  namespace myproject.web.api.controllers {     public class useradcontroller : apicontroller     {         [httpget]         [route("api/userad/getallusers")]         public httpresponsemessage getallusers()         {             httpresponsemessage response = null;               return response;         }      } } 

but there isn't routeattribute on system.web.http.dll (this in \packages\microsoft.aspnet.webapi.core.4.0.30506.0\lib\net40\system.web.http.dll).

attribute routing native in asp.net mvc 5, or later, , asp.net web api 2.

what equivalent route attribute in asp.net version?

if want attribute based routing in asp.net webapi 1, install nuget -

install-package attributerouting.webapi 

then decorate controller action -

[get("api/value")] public ienumerable<string> get() {     return new string[] { "value1", "value2" }; } 

then run solution -

enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -