Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Here's my url
https://localhost:00000/api/Details?Id=1


how to make it not start with local host https://localhost:00000
i want it to be exactly like this /api/Details?Id=1

What I have tried:

Here's my register Method:
public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }


and here's my controller method

[HttpGet]
    [Route("api/Details", Name = "GetDetails")]
    public IHttpActionResult GetDetails([FromUri] IdReq _request)
    {
        return Ok("test")
    }
Posted
Updated 26-Apr-20 1:47am
v4

1 solution

You don't.

Those are necessary portions of the URL to tell the browser what protocol to use (HTTPs, FTP, Gopher), the domain go to (localhost), as well as what port number (00000) to use

Once it gets to localhost:0000, then it is your web applications reponsibility to handle the request for "/api/Details?Id=1"

Once you publish the website, whatever domain name you are using will replace the localhost portion of the URL and as long as you go to the standard port for the protocol (http:80 / 443: https) then the port information (0000) will not be in the URL.

Reference:
What is a URL? - Learn web development | MDN[^]
 
Share this answer
 
Comments
Member 14800672 26-Apr-20 7:59am    
i mean i don't want to call it using https/url/api i only want to call it directly like this /api/..
this is not doable?
MadMyche 26-Apr-20 9:01am    
If you don't have a base URL then the browser wont know what domain to look for /API/

When was the last time you went to a website where the URL did not start with a base URL such as HTTPs://www.domain.com/?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900