Why does Visual Studio skip some directories like Controllers, Classes, and App_Start when publishing to Azure?

109 Views Asked by At

I have a classic ASP.Net forms based website where I have added s set of API hits based on the OAuthAuthorizationServerProvider class. It works great locally, now I trying to publish it to an Azure App Service. The ASP.Net portion of the website works great, no problems. But there are 2 obvious issues with the API side of the website. 1) By default the Classes, Controllers and App_Start directories do not get pushed to the App Service when publishing the website. 2) After manually publishing the missing directories the API service does not respond to the hits. POST http://test.azurewebsites.net/api/v1/token responds with a 404 (Not Found) error.

I know someone is going to ask for the contents of the App_Start files so here they are.

RouteConfig.cs

using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;

namespace App_Start
{
    public static class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            var settings = new FriendlyUrlSettings();
            settings.AutoRedirectMode = RedirectMode.Permanent;
            routes.EnableFriendlyUrls(settings);

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

Startup.cs

using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.Security.OAuth;
using Owin;
using System;

[assembly: OwinStartup(typeof(App_Start.Startup))]

namespace App_Start
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder App)
        {
            App.UseCors(CorsOptions.AllowAll);
            OAuthAuthorizationServerOptions options = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/api/v1/token"),
                Provider = new ApiAuthProvider(),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(5),
                //AllowInsecureHttp = true
            };

            App.UseOAuthAuthorizationServer(options);
            App.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
        }
    }
}

WebApiConfig.cs

using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace App_Start
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

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

I don't think I'm missing something in the startup for the API hits, but that is most likely the cause of my 2nd issue.

Thanks, Russ

1

There are 1 best solutions below

1
On BEST ANSWER

By default the Classes, Controllers and App_Start directories do not get pushed to the App Service when publishing the website.

I have deployed the ASP.Net Web API to Azure App Service. Even Iam unable to see the Controllers, classes and Config files folders.

When we deploy the Web App, all the source files are compiled into the dll files.

Deployed Folder Structure enter image description here

enter image description here

No need to push all the files and folders manually.

POST http://test.azurewebsites.net/api/v1/token responds with a 404 (Not Found) error.

We need to enable Routing in Configure() method inStartup.cs file.

In Startup.cs, add the below lines

 app.UseRouting();
 app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });