Web API routing 404 not found - asp.net-web-api

I'm getting a 404 not found error when trying to access one of my Web API actions:
I have in my WebAPIConfig:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I have a controller named OnSourceAPIController and a GET action ValidateServiceRequestAuto.
I get a 404 error when I try to go to:
http://localhost/api/OnSourceAPI/ValidateServiceRequestAuto
My first guess was I had some kind of routing error, but I created an mvc controller and an index page for it and was able to browse there normally via this routing (api/controller/action). The builtin api/help page even shows /api/OnSourceAPI/ValidateServiceRequestAuto as the route to my api call.
I also tried using the WebAPIRouteDebugger tool. It gives me a 000 404 not found error when I use
http://localhost/api/OnSourceAPI/ValidateServiceRequestAuto
, but actually give me the normal route information if I take localhost off of the front and just use
api/OnSourceAPI/ValidateServiceRequestAuto as the URL...
Any pointers would be appreciated.

I figured it out and feel a little bit silly now.
I have my webapi project running inside of my normal website project with a path of .../api, so because I set up my api routing to be api/controller/action, the path I really need to use is localhost/api/api/controller/action. So it turns out that the 404 was there because it really couldn't find anything at that location. I hate it when computers do exactly what you tell them to.

In my case it was address of created service: WebApp.Start(address)
Should be like: http://localhost:9000/
NOT: http://localhost:9000/api/

Related

slash command "dispatch_failed"

I have went through creating the custom slash command configuration via slack and installed it on workspace. However when I run it I get this
/testing failed with the error "dispatch_failed"
I tried multiple workspaces but same issue. Anyone experienced this?
So after a few tests, I found out that this is just a generic message of anything that fails at slack at this point. I have first my endpoint that was unreachable. So it was returning this message. I fixed that, used ngrok for tunnel so that I could debug and that is how I found this issue.
Also, this error can occur due to the following reasons as well.
Errors in code
Unreachable backend or Invalidly configured slash command in the app
While the documentation tells you:
"use the Request URL is your base server link + "/slashcommand" after it"
This is incorrect. The request URL should be: "/slack/events"
Of course the command needs to match whats in the 'edit command' window and in the method '.command' in your app.js:
app.command('/flash-card', async ({ ack, body, client })
If you're using ngrok http <port> to test in your localhost, be aware that a new ngrok public URL is created every time you run this command. So in https://api.slack.com/apps, in your app's Features, you may have to update your Slash Command' request URL with the current ngrok URL generated for you.
You need to set the Method in the Integration Settings to GET, is default to POST
This is also the error for a 404 Not Found.
If you're developing offline with ngrok, the 404 error can be seen in the terminal.
If you're deploying with serverless, ensure that you're handling the new endpoint /slack/command. One solution is to create a separate handler, i.e. /command.js
functions:
slack:
handler: app.handler
events:
- http:
path: slack/events
method: post
command:
handler: command.handler
events:
- http:
path: slack/command
method: post
[If your code is executing and u still have this error]
In my case using Slackbolt with js I forgot to add
await ack();
in called function so Slack api throw error.

MVC routing not working on godaddy but on azure subscription

I have an mvc site deployed at godaddy server. The mvc routing is working fine on my system and i tried to deploy it on my free azure subscription to test. Its working there. My route.config file has nothing new:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
On server, i have a virtual directory named "httpdocs". None of the controller is receiving my call and giving error 404 page not found. Can you please assist as to wat other changes do i need to check as it seems related to deployment on godaddy server. Please feel free to let me know if any other information seems missing here so that i can provide additional details.
Ok, After spending almost 2-3 days on it, i finally figured it out. My application is using MVC 5.2 Version and goDaddy provides support for max MVC 5 version.
So after downgrading MVC FROM 5.2 to 5 version, it worked.
This may help someone else who might face this issue.

CodeIgniter returns 404 for all routes but works

I have strange problem with CodeIgniter and routing system and can't find solution for it, so: I have several routes such as
'forum/(:num)'
=> 'forum/category/$1',
'forum/(:num)/(page:any)'
=> 'forum/category/$1/$2',
and them works, but return 404 code in header.
I mean I don't get 404 page, correct HTML returns and page's content displays correctly for my forum's categories. But I'm getting 404 in header (Network tab in Firebug), so I can't work with POST data correctly.
If I request /forum/ - 200 Ok returns, but when I trying to get routed page, I get right page, but with 404 Not Found.
I'm using PHP5.4+Apache2 on Linux host, if it will help You to give me solution.
I've found solution! Maybe it will save someone's time.
Problem wasn't in CodeIgniter, I've found solution in activation mod_rewrite. Yes, that worked, but wan't activated in Apache.
Just try to do
sudo a2enmod rewrite
and restart apache service after
sudo service apache restart
And all routed pages will return 200 Ok
None of these worked, but I did this instead:
At the end of my controller I put this:
$this->output->set_status_header('200');
and actually though that worked, the problem turned out to be a controller name that conflicted with a real directory name...

Exception while passing JSON string(multiple parameters) to method in WebAPI service

While trying to pass a JSON data from script side to the method inside WebAPI service we are getting the following exception.
{
"Message":"No HTTP resource was found that matches the request URI '.../api/Values/Sample'.",
"MessageDetail":"No type was found that matches the controller named 'Values'."
}
IMPORTANT NOTE:
While using WebAPI in .net 4.0 and VS2010 we didn’t experience any such issue but when we use WebAPI in .net 4.5 and VS2012 we saw the issue. So kindly diagnosis this with 4.5 framework.
We have attached the sample in the following link. If you could review and post the correct sample with comments it would be really helpful as we are new to WebAPI concepts. Event posting code snippet with proper comments would be fine.
SAMPLE LINK: http://www.fileconvoy.com/dfl.php?id=gb197faeca5017d489993001280c7f122f64fc06a7
Thanks in advance.
I have looked at your sample. Couple of things to fix it:
1.Change the controller name from ValuesController1 to ValuesController. Web API by default looks for controller classes with suffix 'Controller'.
2.Change your route to the following:
System.Web.Routing.RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional});

ASP.NET MVC 3 Access Denied in just one server and one folder

I'm with the following issue: when I try to access a certain page (http://mysite.com/Client/) I get an Access Denied error (403 - Forbidden: Access is denied), but if I try to access the same URL using "Index" in the end (http://mysite.com/Client/Index), it works! And I have a lot of another folders that work without the "Index" in the URL.
The wierdest part is that in the test server (http://mysite.com:8080) I can access in both ways (/Client/ and /Client/Index/). By this time I don't know if it's an IIS 7 problem, or in the Client Folder for some reason, if it's in Web.config or if I'm just losing my mind!
The routes are the following:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
One more thing: the test server app and the main server app are the same!
Can someone give me a hand? Thank you!
P.S.: There isn't any authorization setting in web.config.
From your question it seems like you don't have a Client controller, just folder. So, I guess the route is looking for a controller that It can't find. Or you have a controller but no actions in it. I am not sure, anyway, try adding this to your routes:
routes.IgnoreRoute("Client/{*path]");
EDIT:
Try adding this route:
routes.MapRoute(
"Default", // Route name
"{controller}/Index", // URL with parameters
new { controller = "Home", action = "Index"}
);
resolved in a mysterious way: although I tried to resolve things editing the routes, I realized that the error was occurring before the application_start event. So, the problem was in IIS.
I tried to find the reason for the problem, but I couldn't, so I installed the URL Rewrite 2.0 and made the request of "/Client" redirect to "/Client/Index".
Wierd, isn't it? But this workaround resolved!
Thaks for all the answers!

Resources