I'm new to c# and asp.net web api.
I'm working with Microsoft Visual Studios 2015 Community Edition.
A few days back i got an old Code. It used the old NuGet-Packages of Microsoft.AspNet.WebAPi(Client/Core/WebHost)(~v4.2).
Then i installed/updated the new Versions (~v5.2.3).
I did that in order to use the Attribute Routing of Web API v2.
I changed some stuff in order to accommodate the version changes.
How to Upgrade an ASP.NET Project
I did most of the Steps described in the Link. I didn't do the Steps to change the config Files in the View Folder, because this project doesn't have a View.
The I added 1 simple Methode with Route Attribute and added Route Attribute to an existing Methode
Sample 1:
[HttpGet]
[Route("Hello/world/{num:int}")]
public IHttpActionResult GetSimple(int num)
{
return Ok(num);
}
Sample 2:
[HttpGet]
//[AktionName("Confidential Stuff")]
[Route("Hello/world/stuff/{Id:int}/{Id2:int}")]
public HttpResponse Message GetConfidentialStuff(int Id, int Id2)
{
//do some stuff
//return stuff
}
Build the Project --> Worked ( Warnings about stuff beeing obsolete, but thats a small matter )
Run the Project --> Worked
Used Postman to perfrom the Request. --> partially worked
It did work with calling ' localhost/Hello/world/123 'and returned the 123.
But
It didnt work with calling ' localhost/Hello/world/Stuff/1/2. It returned: HTTP resource was found that matches the request URI (link to adress)
Edit
Well now here are some of my questions:
* What is the Problem ?
My URI i used in Postman was wrong.(misspelled & wrong parameters)
* How do i fix it?
Use right URI and parameters
* Why does Sample 1 work but Sample 2 doesn't?
Because i was stupid & didn't check
* If the Code is messed up, why does it compile? Should it not throw an Error?
Still don't know specific answer, but yes it should throw an Error if code is wrong
* If there are problems with the code used in Sample 2, should it not still find the adress/resource but then return false Information
Yes, it should