snipt

Ctrl+h for KB shortcuts

C#

C# controllers for WebApi using Action Names and Verbs

1
2
3
4
5
6
7
[ValidateUser, ActionName("subjects"), HttpPost]
public HttpResponseMessage PostSubject(SubjectDto item)
{
	// 	This means if the controller was called say member, you could then
    //	call this function by api/member/subjects and the verb HttpPost or 
	//	whatever defines the type of action being performed
}
https://snipt.net/embed/44999a792692b2d0be01830da5ac1904/
/raw/44999a792692b2d0be01830da5ac1904/
44999a792692b2d0be01830da5ac1904
csharp
C#
7
2019-06-20T14:51:15
True
False
False
Jan 06, 2013 at 09:01 AM
/api/public/snipt/52809/
c-controllers-for-webapi-using-action-names-and-verbs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="na">[ValidateUser, ActionName(&quot;subjects&quot;), HttpPost]</span> </span><span id="L-2"><a name="L-2"></a><span class="k">public</span> <span class="n">HttpResponseMessage</span> <span class="nf">PostSubject</span><span class="p">(</span><span class="n">SubjectDto</span> <span class="n">item</span><span class="p">)</span> </span><span id="L-3"><a name="L-3"></a><span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="c1">// This means if the controller was called say member, you could then</span> </span><span id="L-5"><a name="L-5"></a> <span class="c1">// call this function by api/member/subjects and the verb HttpPost or </span> </span><span id="L-6"><a name="L-6"></a> <span class="c1">// whatever defines the type of action being performed</span> </span><span id="L-7"><a name="L-7"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
c#, rest, webapi