Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host a mvc web api application in the sub-folder of a website

I already have a web application in the root folder of my website. (e.g. http://cassapi.gear.host). Now I want to add one MVC web API application in a subfolder inside the 'wwwroot' folder, so that I can access my home controller something like "http://cassapi.gear.host/DOTAPI/api/values" without troubling the website in the 'wwwroot' folder.

Note: It's working fine when I publish this MVC application in the root folder.

My web.config is like this :-

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

My root config:-

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "DOTAPI/{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

i am a windows application developer and new in MVC. so, please look into this and help me.

Currently , when i am calling the url "http://cassapi.gear.host/DOTAPI/" it shows "You do not have permission to view this directory or page."

like image 869
vivek Avatar asked Sep 15 '25 03:09

vivek


1 Answers

If you are getting a access denied error, then you must give permissions to iis_users group for your directory. And there is another way for achieving what you need. You can add your api as an application to your main website. Below are the steps.

  1. Go to IIS.
  2. Right click your main website and choose Add Application.
  3. Give an alias for your api.
  4. Set the path to your API folder.

Then you can just browse your API with the alias you provided.

like image 100
Sunny Verma Avatar answered Sep 17 '25 18:09

Sunny Verma