Blazor deploying project in IIS - iis

Hello i have an error said "he Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app."
and i already done some configs like changing it into Development and still nothing error coming out in google chrome console
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"nativeDebugging": false
},
"BlazorLog": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}

You can try to change "ASPNETCORE_ENVIRONMENT": "Development" to "ASPNETCORE_ENVIRONMENT": "Production".
Otherwise, you can update the web.config like this:
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
</environmentVariables>

Related

Azure App Service application settings not overriding application.json array setting for .NET Core 3.1 application

We have a .NET Core 3.1 application deployed to Microsoft Azure.
In the application.json file of the application we have the following contents:
{
"Settings": {
"ServicesURIs": [
{
"Name": "Features",
"URL": "https://abc.azurewebsites.net",
"Port": "443",
"ScopeUri": "api://xxxxxx",
"enabled": "true"
},
{
"Name": "Questions",
"URL": "https://def.azurewebsites.net",
"Port": "443",
"ScopeUri": "api://XXXXX",
"enabled": "true"
}
]
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"pwa": {
"cacheId": "v1.3",
"strategy": "networkFirst",
"registerWebmanifest": true,
"routesToPreCache": "/"
}
}
I wish to override the URL properties from the Application settings section in Configuration of the app service in Azure.
I am currently specifying the following application setting in the configuration blade per documentation and lots of online blogs:
Name= Settings:ServicesURIs:0:URL
Value= https://Somevalidurl.azurewebsites.net
But I find that the application is not using the value from the portal configuration, and always try to use the value in the .json file.
I have tried specifying the name as
Settings__ServicesURIs__0__URL
(where the ":" are replaced with double underscores)
I have restarted the application service after registering the setting in Azure.
I test this using Chrome in Incognito to ensure cache is not playing a role.

SPFX Package always referring content or resources from localhost instead from CDN

Can someone please let me know from where I can change this configuration so that it should refer from the CDN path instead of localhost
Below is my package-solution.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "mega-menu-sp-fx-client-side-solution",
"id": "8f49d75c-5a49-4657-b81b-0290f239350f",
"version": "10.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
"features": [
{
"title": "Application Extension - Deployment of custom action.",
"description": "Deploys a custom action with ClientSideComponentId association",
"id": "0d2345df-2a49-4ce9-ba2d-bee7ad3e7a02",
"version": "10.0.0.0",
"assets": {
"elementManifests": [
"elements.xml",
"clientsideinstance.xml"
]
}
}
]
},
"paths": {
"zippedPackage": "solution/mega-menu-sp-fx.sppkg"
}
}
Below is my write-manifest.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "https://Mytenant.sharepoint.com/sites/MyTechTheme/MenuFiles"
}
I tried to figure out whats the issue. For publishing instead of gulp package-solution --ship I had used gulp package-solution so unless and until we don't mention --ship it wont take the references for CDN
So for deploying the package in SPO we need to use gulp bundle --ship and gulp package-solution --ship
As per this thread, to load SPFx assets from a CDN or SharePoint library, set the value of "includeClientSideAssets" to false.
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
...
"includeClientSideAssets": false,
...
}
}

ASP.NET Core app not working after publish to Azure

I have an ASP.NET Core app which is running fine locally.
However, when I publish (Web Deploy) the site to Azure, I get a 403: You do not have permission to view this directory or page.
I have a default controller and a route defined in Startup.cs:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
The folder structure after web deploy to Azure looks like:
|_ home
|_ site
|_ wwwroot (contains DLL's and files specified through 'publishOptions' in project.json)
|_ wwwroot (the contents of the 'wwwroot' folder I have in Visual Studio)
|_ Views (contains MVC views)
|_ refs (contains referenced DLLs, I think?)
Any idea of what I should look for in project.json or the Kudu portal to figure out what's wrong?
My project.json file:
{
"title": "My Web App",
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true,
"compile": {
"exclude": [ "bin/**", "obj/**", "node_modules/" ]
}
},
"publishOptions": {
"include": [ "wwwroot", "Views", "appsettings.json", "appsettings.*.json" ]
},
"scripts": {
"prepublish": [ "jspm install", "gulp build" ]
},
"dependencies": {
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"System.IO.FileSystem": "4.0.1"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
},
"imports": "dnxcore50"
}
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:8000/"
}
}
Edit:
For one, I was missing the Microsoft.AspNetCore.Server.IISIntegration NuGet package. When I added it, I also got a web.config file in the site root (which I included through project.json).
I also added .UseIISIntegration() to my WebHostBuilder in Startup.cs:
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
I can now run it on IIS Express locally (although I guess it's IIS fronting Kestrel?), but when published to Azure I get error:
HTTP Error 502.5 - Process Failure
The event log in Azure states: Failed to start process with commandline '"%LAUNCHER_PATH%" %LAUNCHER_ARGS%', ErrorCode = '0x80070002'.
According to the documentation, the troubleshooting step is:
If the server does not have Internet access while installing the server hosting bundle, this exception will ensue when the installer is prevented from obtaining the Microsoft Visual C++ 2015 Redistributable (x64) packages online. You may obtain an installer for the packages from the Microsoft Download Center.
Not sure how this applies to Azure, though?
The problem came from insufficient IIS integration/configuration.
I had to add the following to project.json:
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
}
I also added a postPublish script for IIS publishing:
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
I also added the Microsoft.AspNetCore.Server.IISIntegration NuGet package:
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0"
}
This created a web.config file, which I had to modify as:
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\My.Web.App.dll" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout" />
</system.webServer>
</configuration>
Finally I added UseIISIntegration to my WebHostBuilder:
public static void Main(string[] args)
{
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseIISIntegration() // This was missing
.Build()
.Run();
}
A standard Publish (Web Deploy) from Visual Studio and the website started just fine on Azure (although in my case I also had to add a prepublish script for some Gulp tasks).

Asp.net core CloudConfigurationManager.GetSetting() is null

I have an asp.net 4 application where it works fine, but I can't get it working for asp.net core. The documentation says that GetSetting looks in either web.config or app.config file.
Storage emulator is turned on.
public void ConfigureServices(IServiceCollection services)
{
AzureConfig.Initialize();
}
public static void Initialize()
{
//Always null
var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
}
root web.config file:
<configuration>
<appSettings>
<add key="StorageConnectionString" value="UseDevelopmentStorage=true;" />
</appSettings>
</configuration>
I have these dependencies in my project.json:
"Microsoft.WindowsAzure.ConfigurationManager": "3.2.1",
"WindowsAzure.Storage": "7.1.2",
"AzureSDK2.2DLLs": "1.0.0"
Edit, this doesn't work either:
{
"ConnectionStrings": {
"DefaultConnection": "..."
"StorageConnectionString": "UseDevelopmentStorage=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"StorageConnectionString": "UseDevelopmentStorage=true"
}
In ASP.NET core, the settings have been moved out of the web.config and in to appsettings.json. Have a look at the documentation for how it has changed:
https://docs.asp.net/en/latest/fundamentals/configuration.html
Also, have a look at this previous answer to a similar question:
https://stackoverflow.com/a/30580006/2823539

Can't deploy ASP.net core RC2 targeting net451 or net46 to Azure Web App

I can't seem to be able to deploy my asp.net core RC2 app to Azure when I target the net451 or net46 framework.
When I try to reach my application I get the following error
The specified CGI application encountered an error and the server terminated the process.
Everything works when I deploy to my local IIS.
The Azure logger gives me
Failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%', Error Code = '0x80070002'.
I tried replacing %LAUNCHER_PATH% for dotnet and %LAUNCHER_ARGS% for myapp.exe in the web.config but still the same error occur.
Here is my project.json
{
"dependencies": {
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"net46": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Thanks
It seems that updating my web.config to specify the processPath did the trick.
I also had to delete the previous publish attempts for it to work properly.
<aspNetCore processPath=".\myapp.exe" arguments="" forwardWindowsAuthToken="false" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout"/>
With the same symptoms I checked the logs as #Pawel suggested.
The logs contained FileNotFoundException which was resolved by adding two dependencies to project.json.
"dependencies": {
...
"System.IO.FileSystem.Watcher": "4.0.0-rc2-24027",
"System.IO.FileSystem": "4.0.1-rc2-24027"
},
The issue is reported here
Azure doesn't support net461 and use better net451.
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
Publishing SkyIsTheLimit for .NETFramework,Version=v4.5.1/win7-x64

Resources