-
Apr 4th, 2022, 04:11 AM
#1
[RESOLVED] redirect httpget
Hi.
Struggling for an hour.
I have 2 httpGet
Code:
[HttpGet]
public IsAlive IsAlive()
{
and
Code:
[HttpGet]
[Route("api/[controller]/IsAlive2")]
public IsAlive IsAlive2([FromUri]int id, [FromBody]IsAlive model)
...
or
[HttpGet]
[Route("api/Vconnect/IsAlive2")]
public IsAlive IsAlive2([FromUri]int id, [FromBody]IsAlive model)
or any other variation I can think of.
The first get, I can use the Route and everything will work ok. I can rename it to test, john whatever i will just work.
The second route, whatever I do it will not hit the breakpoint.
What is the issue?
Thanks.
<Error>
<Message>No HTTP resource was found that matches the request URI 'http://localhost:39466/api/vConnect/IsAlive2'.</Message>
<MessageDetail>No action was found on the controller 'VConnect' that matches the name 'IsAlive2'.</MessageDetail>
</Error>
P.S. Webapiconfig is set like so:
Code:
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
Last edited by sapator; Apr 4th, 2022 at 07:26 AM.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 4th, 2022, 08:07 AM
#2
Re: redirect httpget
Even if pass an optional the @#$#@@$##$ sht MVC will need the id.
So I need to do this?
Code:
[Route("api/Vconnect/IsAlive2")]
[HttpGet]
public IsAlive IsAlive2([FromUri] int? id , [FromBody]IsAlive model)
And send it like:
http://localhost:39466/api/vconnect/Isalive2?id=4
or do this:
public IsAlive IsAlive2([FromUri] int? id , [FromBody]IsAlive model = null) -- that does not seem to work..Anyhow.
Last edited by sapator; Apr 4th, 2022 at 08:12 AM.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 4th, 2022, 11:28 AM
#3
Re: [RESOLVED] redirect httpget
Originally Posted by sapator
Hi.
Struggling for an hour.
I have 2 httpGet
Code:
[HttpGet]
public IsAlive IsAlive()
{
and
Code:
[HttpGet]
[Route("api/[controller]/IsAlive2")]
public IsAlive IsAlive2([FromUri]int id, [FromBody]IsAlive model)
...
or
[HttpGet]
[Route("api/Vconnect/IsAlive2")]
public IsAlive IsAlive2([FromUri]int id, [FromBody]IsAlive model)
or any other variation I can think of.
The first get, I can use the Route and everything will work ok. I can rename it to test, john whatever i will just work.
The second route, whatever I do it will not hit the breakpoint.
What is the issue?
Thanks.
<Error>
<Message>No HTTP resource was found that matches the request URI 'http://localhost:39466/api/vConnect/IsAlive2'.</Message>
<MessageDetail>No action was found on the controller 'VConnect' that matches the name 'IsAlive2'.</MessageDetail>
</Error>
P.S. Webapiconfig is set like so:
Code:
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
Does a route template of
Code:
routeTemplate: "api/{controller}/{action}/{id?}",
work?
-
Apr 5th, 2022, 04:24 AM
#4
Re: [RESOLVED] redirect httpget
That actually breaks the code with:
The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl
It kinda works with a hard coded optional param like : "api/Vconnect/IsAlive2/{id:int=0}"
So, meah.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 5th, 2022, 06:03 AM
#5
Re: [RESOLVED] redirect httpget
Originally Posted by sapator
That actually breaks the code with:
The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Parameter name: routeUrl
It kinda works with a hard coded optional param like : "api/Vconnect/IsAlive2/{id:int=0}"
So, meah.
I have always tended towards attribute routing when I need to do anything even vaguely useful. The convention based routes are fine for simple things, such as the default routes, but never seem good enough when you need to do something sensible.
-
Apr 5th, 2022, 06:53 AM
#6
Re: [RESOLVED] redirect httpget
It's a simple HttpGet that check something if opted and return an OK or Error. I wouldn't go about doing much to it but I will check attribute routing if I'm able as missing from the office and getting back after a long time has pack a pile of Accounting dept papers in my desk higher than mount Everest.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 5th, 2022, 04:45 PM
#7
Re: [RESOLVED] redirect httpget
Originally Posted by sapator
It's a simple HttpGet that check something if opted and return an OK or Error. I wouldn't go about doing much to it but I will check attribute routing if I'm able as missing from the office and getting back after a long time has pack a pile of Accounting dept papers in my desk higher than mount Everest.
Also, if the route allows a parameter to be optional then the underlying action will require the parameter to either have a default or be nullable.
-
Apr 5th, 2022, 04:57 PM
#8
Re: [RESOLVED] redirect httpget
Originally Posted by PlausiblyDamp
Also, if the route allows a parameter to be optional then the underlying action will require the parameter to either have a default or be nullable.
sapator is using VS2015 so some of the new C# and ASPNET features may not exist there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|