Publish WebAPI and MVC projects to same Azure Web Site?

前端 未结 2 1478
南笙
南笙 2020-12-04 18:21

I have two seperate projects in Visual Studio - one with a WebAPI and one with a MVC Web Site...

Can I publish both of these to the same Azure Web Site, so that requ

相关标签:
2条回答
  • 2020-12-04 19:04

    Go to Azure portal and create an AzureWebsite -

    enter image description here

    Then setup an additional application in the settings as follows -

    enter image description here

    Now create two projects in the Visual studio solution -> 1) MVC and 2) WebApi

    enter image description here

    Download publishsettings file of above created azure website. Import the publishsettings file to the Visual studio MVC project publish as shown below -

    enter image description here

    And for WebApi project, import the same publish settings, but create a new path as website/webapi.

    enter image description here

    Publish both the projects.

    Now navigate to http://{yoursite}.azurewebsites.net for the MVC site. And navigate to http://{yoursite}.azurewebsites.net/webapi/api for your WebApi.

    0 讨论(0)
  • 2020-12-04 19:11

    Basically this needs following steps to be done to make it working.

    Solution contains

    i) sampleApp.API(.Net Core Web API) will be deployed in subfolder

    ii)sampleApp.UI( Angular App)

    Setting up Azure portal for two applications

    1) Go to your web app in azure portal -> Settings->configurations

    2) Select Path Mappings and here create new mapping entry for subsite .While adding this entry don't select directory checkbox to keep this as virtual application type.Click save

     **Virtual Path:** /{folderName}            **physicalPath:**  /site/wwwroot/{folderName} 
    

    3) Now go to VS2017 right click your API project and click publish

    4) In publish settings window make paths as

    site name : existing + "/{folderName} "
    DestinationUrl : existing + "/{folderName} "
    

    5) Now ng-build --prod your angular app and deploy dist/clientApp folder and publish with root paths.

    so now both should work as

    angular app https://{AzureAppName}.azurewebsites.net
    

    Web API https://{AzureAppName}.azurewebsites.net/{folderName}/api/{controllerName}/{action}

    If still user face "cant read configuration data from web.config" issue while accessing api project or getting error code 502 then

    For this in your API project go to startup.cs and change configure function to have following line of code

    app.Map('/{folderName}', app1 => Configure1(app1, loggerFactory);
    

    and create in blank copy of configure function with name configure1 and redeploy your API project as mentioned above.

    public void Configure1(IApplicationBuilder app, ILoggerFactory loggerFactory)
            {
                //keep it blank
            }
    
    0 讨论(0)
提交回复
热议问题