ASP.net controller for delete - “No HTTP resource was found that matches the request URI”





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I have a stored proc in SQL called "person_connections_delete". I have written a controller to call the stored proc however, this error message keeps coming up



"message": "No HTTP resource was found that matches the request URI 'http://localhost:3024/api/personconnections/delete'.",
"messageDetail": "No action was found on the controller 'PersonConnections' that matches the request."



Here is the stored proc. I'm passing three parameters into the stored proc for the delete.



ALTER PROC [dbo].[person_connections_delete]
@PersonId INT,
@FriendId INT,
@Status INT
AS
/*
DECLARE
@_personId INT = 1,
@_friendId INT = 200,
@_status INT = 1
EXEC person_connections_delete
@_personId,
@_friendId,
@_status
*/
BEGIN
DELETE
person_connections
WHERE
PersonId = @PersonId and FriendId = @FriendId
IF (@Status = 1)
DELETE
person_connections
WHERE
PersonId = @FriendId and FriendId = @PersonId
END


The service and controller. in C#:



public void Delete(int personId, int friendId, int status)
{
_dataProvider.ExecuteNonQuery(
"person_connections_delete",
inputParamMapper: delegate (SqlParameterCollection paramCol)
{
paramCol.AddWithValue("@PersonId", personId);
paramCol.AddWithValue("@FriendId", friendId);
paramCol.AddWithValue("@Status", status);
}
);
}

[AllowAnonymous]
[RoutePrefix("api/personconnections")]
public class PersonConnectionsController : ApiController
{
private IPersonConnectionsService _personConnectionsService;

[HttpDelete]
[Route("delete")]
public HttpResponseMessage Delete(int personId, int friendId, int status)
{
try {
if (ModelState.IsValid) {
ItemResponse<PersonConnectionsDeleteDomain> resp = new ItemResponse<PersonConnectionsDeleteDomain>();
_personConnectionsService.Delete(personId, friendId, status);
return Request.CreateResponse(HttpStatusCode.OK, resp);
} else {
return Request.CreateResponse(HttpStatusCode.NotModified, ModelState);
}
} catch (Exception ex) {
return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
}
}
}


enter image description here










share|improve this question

























  • I suggest taking a look at nuget.org/packages/routedebugger to see how your route is being resolved.

    – Matthew Evans
    Jan 3 at 6:55


















2















I have a stored proc in SQL called "person_connections_delete". I have written a controller to call the stored proc however, this error message keeps coming up



"message": "No HTTP resource was found that matches the request URI 'http://localhost:3024/api/personconnections/delete'.",
"messageDetail": "No action was found on the controller 'PersonConnections' that matches the request."



Here is the stored proc. I'm passing three parameters into the stored proc for the delete.



ALTER PROC [dbo].[person_connections_delete]
@PersonId INT,
@FriendId INT,
@Status INT
AS
/*
DECLARE
@_personId INT = 1,
@_friendId INT = 200,
@_status INT = 1
EXEC person_connections_delete
@_personId,
@_friendId,
@_status
*/
BEGIN
DELETE
person_connections
WHERE
PersonId = @PersonId and FriendId = @FriendId
IF (@Status = 1)
DELETE
person_connections
WHERE
PersonId = @FriendId and FriendId = @PersonId
END


The service and controller. in C#:



public void Delete(int personId, int friendId, int status)
{
_dataProvider.ExecuteNonQuery(
"person_connections_delete",
inputParamMapper: delegate (SqlParameterCollection paramCol)
{
paramCol.AddWithValue("@PersonId", personId);
paramCol.AddWithValue("@FriendId", friendId);
paramCol.AddWithValue("@Status", status);
}
);
}

[AllowAnonymous]
[RoutePrefix("api/personconnections")]
public class PersonConnectionsController : ApiController
{
private IPersonConnectionsService _personConnectionsService;

[HttpDelete]
[Route("delete")]
public HttpResponseMessage Delete(int personId, int friendId, int status)
{
try {
if (ModelState.IsValid) {
ItemResponse<PersonConnectionsDeleteDomain> resp = new ItemResponse<PersonConnectionsDeleteDomain>();
_personConnectionsService.Delete(personId, friendId, status);
return Request.CreateResponse(HttpStatusCode.OK, resp);
} else {
return Request.CreateResponse(HttpStatusCode.NotModified, ModelState);
}
} catch (Exception ex) {
return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
}
}
}


enter image description here










share|improve this question

























  • I suggest taking a look at nuget.org/packages/routedebugger to see how your route is being resolved.

    – Matthew Evans
    Jan 3 at 6:55














2












2








2


1






I have a stored proc in SQL called "person_connections_delete". I have written a controller to call the stored proc however, this error message keeps coming up



"message": "No HTTP resource was found that matches the request URI 'http://localhost:3024/api/personconnections/delete'.",
"messageDetail": "No action was found on the controller 'PersonConnections' that matches the request."



Here is the stored proc. I'm passing three parameters into the stored proc for the delete.



ALTER PROC [dbo].[person_connections_delete]
@PersonId INT,
@FriendId INT,
@Status INT
AS
/*
DECLARE
@_personId INT = 1,
@_friendId INT = 200,
@_status INT = 1
EXEC person_connections_delete
@_personId,
@_friendId,
@_status
*/
BEGIN
DELETE
person_connections
WHERE
PersonId = @PersonId and FriendId = @FriendId
IF (@Status = 1)
DELETE
person_connections
WHERE
PersonId = @FriendId and FriendId = @PersonId
END


The service and controller. in C#:



public void Delete(int personId, int friendId, int status)
{
_dataProvider.ExecuteNonQuery(
"person_connections_delete",
inputParamMapper: delegate (SqlParameterCollection paramCol)
{
paramCol.AddWithValue("@PersonId", personId);
paramCol.AddWithValue("@FriendId", friendId);
paramCol.AddWithValue("@Status", status);
}
);
}

[AllowAnonymous]
[RoutePrefix("api/personconnections")]
public class PersonConnectionsController : ApiController
{
private IPersonConnectionsService _personConnectionsService;

[HttpDelete]
[Route("delete")]
public HttpResponseMessage Delete(int personId, int friendId, int status)
{
try {
if (ModelState.IsValid) {
ItemResponse<PersonConnectionsDeleteDomain> resp = new ItemResponse<PersonConnectionsDeleteDomain>();
_personConnectionsService.Delete(personId, friendId, status);
return Request.CreateResponse(HttpStatusCode.OK, resp);
} else {
return Request.CreateResponse(HttpStatusCode.NotModified, ModelState);
}
} catch (Exception ex) {
return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
}
}
}


enter image description here










share|improve this question
















I have a stored proc in SQL called "person_connections_delete". I have written a controller to call the stored proc however, this error message keeps coming up



"message": "No HTTP resource was found that matches the request URI 'http://localhost:3024/api/personconnections/delete'.",
"messageDetail": "No action was found on the controller 'PersonConnections' that matches the request."



Here is the stored proc. I'm passing three parameters into the stored proc for the delete.



ALTER PROC [dbo].[person_connections_delete]
@PersonId INT,
@FriendId INT,
@Status INT
AS
/*
DECLARE
@_personId INT = 1,
@_friendId INT = 200,
@_status INT = 1
EXEC person_connections_delete
@_personId,
@_friendId,
@_status
*/
BEGIN
DELETE
person_connections
WHERE
PersonId = @PersonId and FriendId = @FriendId
IF (@Status = 1)
DELETE
person_connections
WHERE
PersonId = @FriendId and FriendId = @PersonId
END


The service and controller. in C#:



public void Delete(int personId, int friendId, int status)
{
_dataProvider.ExecuteNonQuery(
"person_connections_delete",
inputParamMapper: delegate (SqlParameterCollection paramCol)
{
paramCol.AddWithValue("@PersonId", personId);
paramCol.AddWithValue("@FriendId", friendId);
paramCol.AddWithValue("@Status", status);
}
);
}

[AllowAnonymous]
[RoutePrefix("api/personconnections")]
public class PersonConnectionsController : ApiController
{
private IPersonConnectionsService _personConnectionsService;

[HttpDelete]
[Route("delete")]
public HttpResponseMessage Delete(int personId, int friendId, int status)
{
try {
if (ModelState.IsValid) {
ItemResponse<PersonConnectionsDeleteDomain> resp = new ItemResponse<PersonConnectionsDeleteDomain>();
_personConnectionsService.Delete(personId, friendId, status);
return Request.CreateResponse(HttpStatusCode.OK, resp);
} else {
return Request.CreateResponse(HttpStatusCode.NotModified, ModelState);
}
} catch (Exception ex) {
return Request.CreateResponse(HttpStatusCode.BadRequest, ex);
}
}
}


enter image description here







asp.net sql-server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 7:22









jarlh

30k52138




30k52138










asked Jan 3 at 6:40









twofertwofer

324




324













  • I suggest taking a look at nuget.org/packages/routedebugger to see how your route is being resolved.

    – Matthew Evans
    Jan 3 at 6:55



















  • I suggest taking a look at nuget.org/packages/routedebugger to see how your route is being resolved.

    – Matthew Evans
    Jan 3 at 6:55

















I suggest taking a look at nuget.org/packages/routedebugger to see how your route is being resolved.

– Matthew Evans
Jan 3 at 6:55





I suggest taking a look at nuget.org/packages/routedebugger to see how your route is being resolved.

– Matthew Evans
Jan 3 at 6:55












1 Answer
1






active

oldest

votes


















0














See Parameter Binding in ASP.NET Web API. WebAPI can't bind multiple parameters from body natively.




When a parameter has [FromBody], Web API uses the Content-Type header
to select a formatter. In this example, the content type is
"application/json" and the request body is a raw JSON string (not a
JSON object).



At most one parameter is allowed to read from the
message body. So this will not work:



// Caution: Will not work!    
public HttpResponseMessage Post([FromBody] int id, [FromBody] string name) { ... }


The reason for this rule is that the request body might be stored in a
non-buffered stream that can only be read once.




There are other SO questions that ask how to achieve this, like this one. But unless you have a real reason to do so, I think you are better off using attribute routing or query string parameters.






share|improve this answer


























  • You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

    – twofer
    Jan 3 at 7:13











  • Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

    – Muscicapa Striata
    Jan 3 at 7:47












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017465%2fasp-net-controller-for-delete-no-http-resource-was-found-that-matches-the-req%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














See Parameter Binding in ASP.NET Web API. WebAPI can't bind multiple parameters from body natively.




When a parameter has [FromBody], Web API uses the Content-Type header
to select a formatter. In this example, the content type is
"application/json" and the request body is a raw JSON string (not a
JSON object).



At most one parameter is allowed to read from the
message body. So this will not work:



// Caution: Will not work!    
public HttpResponseMessage Post([FromBody] int id, [FromBody] string name) { ... }


The reason for this rule is that the request body might be stored in a
non-buffered stream that can only be read once.




There are other SO questions that ask how to achieve this, like this one. But unless you have a real reason to do so, I think you are better off using attribute routing or query string parameters.






share|improve this answer


























  • You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

    – twofer
    Jan 3 at 7:13











  • Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

    – Muscicapa Striata
    Jan 3 at 7:47
















0














See Parameter Binding in ASP.NET Web API. WebAPI can't bind multiple parameters from body natively.




When a parameter has [FromBody], Web API uses the Content-Type header
to select a formatter. In this example, the content type is
"application/json" and the request body is a raw JSON string (not a
JSON object).



At most one parameter is allowed to read from the
message body. So this will not work:



// Caution: Will not work!    
public HttpResponseMessage Post([FromBody] int id, [FromBody] string name) { ... }


The reason for this rule is that the request body might be stored in a
non-buffered stream that can only be read once.




There are other SO questions that ask how to achieve this, like this one. But unless you have a real reason to do so, I think you are better off using attribute routing or query string parameters.






share|improve this answer


























  • You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

    – twofer
    Jan 3 at 7:13











  • Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

    – Muscicapa Striata
    Jan 3 at 7:47














0












0








0







See Parameter Binding in ASP.NET Web API. WebAPI can't bind multiple parameters from body natively.




When a parameter has [FromBody], Web API uses the Content-Type header
to select a formatter. In this example, the content type is
"application/json" and the request body is a raw JSON string (not a
JSON object).



At most one parameter is allowed to read from the
message body. So this will not work:



// Caution: Will not work!    
public HttpResponseMessage Post([FromBody] int id, [FromBody] string name) { ... }


The reason for this rule is that the request body might be stored in a
non-buffered stream that can only be read once.




There are other SO questions that ask how to achieve this, like this one. But unless you have a real reason to do so, I think you are better off using attribute routing or query string parameters.






share|improve this answer















See Parameter Binding in ASP.NET Web API. WebAPI can't bind multiple parameters from body natively.




When a parameter has [FromBody], Web API uses the Content-Type header
to select a formatter. In this example, the content type is
"application/json" and the request body is a raw JSON string (not a
JSON object).



At most one parameter is allowed to read from the
message body. So this will not work:



// Caution: Will not work!    
public HttpResponseMessage Post([FromBody] int id, [FromBody] string name) { ... }


The reason for this rule is that the request body might be stored in a
non-buffered stream that can only be read once.




There are other SO questions that ask how to achieve this, like this one. But unless you have a real reason to do so, I think you are better off using attribute routing or query string parameters.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 7:42

























answered Jan 3 at 7:08









Muscicapa StriataMuscicapa Striata

368414




368414













  • You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

    – twofer
    Jan 3 at 7:13











  • Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

    – Muscicapa Striata
    Jan 3 at 7:47



















  • You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

    – twofer
    Jan 3 at 7:13











  • Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

    – Muscicapa Striata
    Jan 3 at 7:47

















You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

– twofer
Jan 3 at 7:13





You mentioned that WebAPI can't bind multiple POST parameters, but I'm assuming DELETE is the same?

– twofer
Jan 3 at 7:13













Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

– Muscicapa Striata
Jan 3 at 7:47





Sorry, my bad I did not notice it was a delete method. But yes, it should be the same as a post method. The documentation does not say anything about binding from body limitations not applying to delete method or applying only to post methods. I have edited my answer.

– Muscicapa Striata
Jan 3 at 7:47




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017465%2fasp-net-controller-for-delete-no-http-resource-was-found-that-matches-the-req%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

Npm cannot find a required file even through it is in the searched directory