Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:52:16+00:00 2026-06-14T19:52:16+00:00

I am setting up an ASP.NET MVC 4 Web API to accept requests from

  • 0

I am setting up an ASP.NET MVC 4 Web API to accept requests from a 3rd party server, and I simply can’t figure out how to set the route mappings.
Assume the 3rd party server expects to get responses for:

  1. http://[my_server]/authorize?user=[user name]&session=[session token]&item=[item]
  2. http://[my_server]/release?user=[user name]&session=[session token]

Alternatively, the requests can use a dedicated path, i.e.:

  1. http://[my_server]/***api***/authorize?user=[user name]&session=[session token]&item=[item]
  2. http://[my_server]/***api***/release?user=[user name]&session=[session token]

I would like to be able to support both alternatives.

Additional requests, following the more traditional /controller/id form, should be implemented too, but I’d like to focus on the above (I’m not even sure that Web API is the way to go here).

I have written the following controller:

public class MyController : ApiController
{
    [HttpGet]
    [ActionName("authorize")]
    public string Authorize(string user, string session, string item)
    {
        ...
        // return "OK" or "DENY";
    }

    [HttpGet]
    [ActionName("release")]
    public string Release(string user, string session)
    {
        ...
        return "OK";
    }
}

and tried everything I could find in SO and elsewhere in WebAppConfig.Register, but I keep getting a 404 error when I try the request in the browser:

http://localhost:22332/api/authorize?user=ury&session=token&item=an_item

My question is, what do I have to do – specifically in WebAppConfig.Register and in the controller – in order to serve the above requests (assuming my test URL is correct…)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:52:18+00:00Added an answer on June 14, 2026 at 7:52 pm

    After a few hours working on this and with a lot of help from the Route Debugger – Thanks Phil Haack! – I’ve found both the problem and the solution.

    The problem: Route mapping matching is ordered, and RouteTable.Routes, from which the app’s route mapping is initialized, contains quite a few of them. The request pattern I was looking for also matched some of these mappings (“authorize” was matched as a controller, for example).

    The solution: add “my” route mappings before the default mappings.

    Yeah, right…

    Since most operations are not supported on HttpRouteCollection, the resulting code is a bit ugly, but it works:

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            routesCopy = new RouteBase[RouteTable.Routes.Count];
    
            RouteTable.Routes.CopyTo(routesCopy, 0);
    
            config.Routes.Clear();
            config.Routes.MapHttpRoute(name: "AuthorizeWebApiRoute", routeTemplate: "authorize", defaults: new { controller = "My", action = "authorize" });
            config.Routes.MapHttpRoute(name: "ReleaseWebApiRoute", routeTemplate: "release", defaults: new { controller = "My", action = "release" });
    
            foreach (var route in routesCopy)
            {
                RouteTable.Routes.Add(route);
            }
        }
    }
    

    As long as “my” route mappings don’t match the default mappings (I made them specific enough not to), I’m all good – I think…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC 4 application with Web API. It's working great. But
I am migrating an application from ASP.NET Web Forms to ASP.NET MVC 3. One
I'm right now setting up a web application based on ASP.NET MVC 3 Razor.
My project is created based on ASP.Net MVC Web API 4 application. If it's
I am trying to launch the nunit gui app from an asp.net mvc web
When setting up a new ASP.NET MVC Web Application, the default connection string inside
Having a JS web application (ASP.NET MVC, talking via REST with the server) I
how should i load the table Setting into an asp.net mvc so that i
Setting the scene: My asp.net web application carries a version number which is incremented
All ASP.Net client validation messages can be shown as an alert by setting the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.