Вопрос

I have a simple main web project. I also have a second project that is related to the main project but is meant to be a bare bones web service. I want to place the web service project inside of a version folder inside of regular folder in my main project. For example, a folder in my main project called "WebService" with a subfolder for version 1 called "v1" would result in the following urls:

Url to access the main project's index action in the home controller: http://myMainProjectUrl.com/Home/Index
Url to access the web service v1's index action in the home controller: http://myMainProjectUrl.com/WebService/v1/Home/Index

After setting up the projects like this, I'm getting a 404 when trying to access the web service. What can I do in my Global.asax in the main project, or IIS (or anywhere) to get this URL mapping approach to work? Thanks in advance.

Это было полезно?

Решение 2

After trying things here and there, the answer was in IIS.

In IIS you can add "applications" inside of your sites.

  1. Right click the folder in your site where your "second project" is (in my case the folder is "WebService") and select "Add Application..." .
  2. In alias type the ending path to the URL that you want (in my case my alias would be "v1").
  3. Point the "Physical path" to the folder where your second project resides (in my case my web service project resides in "WebService/v1/webservice_v1").
  4. Click OK and you're done.

Другие советы

You should be able to achieve this by modifying the default route located in App_Start/WebApiConfig.cs

e.g.

public static void Register(HttpConfiguration config)
{
    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { Action = "Get", id = RouteParameter.Optional }
    );
}

change "api/{controller}/{action}/{id} to "/WebService/{controller}/{action}/{id}"

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top