ASP.NET Core ignoring ASPNETCORE_ENVIRONMENT variable - windows

I know that others have posted this problem, but none of the solutions I've seen appear in my case. I have an ASP.NET WebAPI application. I've been able to publish it to two different development servers, via Visual Studio Publish. On both target servers, I set the ASPNETCORE_ENVIRONMENT environment variable to Development via the Windows GUI and the app picks this up, uses my appSettings.Development.json settings, and works as expected.
Now I'm deploying it to my Test server. On that server I set ASPNETCORE_ENVIRONMENT environment variable to Test via the Windows GUI, but when the application runs, it always says Hosting Environment: Production. I've checked my launchSettings.json file as one post suggested, but nothing in there sets the environment variable to Production. Since Production is the default, I don't have code that sets that value anywhere.
My successful deployment to my Dev server and my failed deployment to my Test server were both done via dotnet publish executed from Bamboo.
I don't know why the application running on my Test server is not picking up the ASPNETCORE_ENVIRONMENT Test setting.
A few other details that I thought of over the weekend, which may or may not be relevant.
VS Publish to Windows Server 2008 R2, debug build, works as expected. Target server has ASPNETCORE_ENVIRONMENT set to Development, application log reports Hosting environment: Development, and appSettings.Development.json settings are in effect.
Both VS Publish and Bamboo deploy (via dotnet publish) to Windows Server 2016, debug build, works as expected. I have two instances of the site on this server. One relies on the ASPNETCORE_ENVIRONMENT variable, which is set to Development, and works as expected. The other overrides the environment variable for its app pool via a setting in applicationHost.config. In both cases, the applications correctly pick up the environment variable and reflect the correct hosting environment.
Bamboo deploy via dotnet publish to Windows Server 2012, release build, does not work as expected. Application reports the hosting environment as Production (the default), suggesting that it failed to pick up the environment variable I set. The application fails because it is missing the app settings from appSettings.Development.json.
So the failing scenario is a different server O/S, but since it works on both 2008 and 2016, I would think it would work on 2012. And the failing scenario is a release build vs. a debug build, but I wouldn't think that would impact the runtime behavior re configuration.
I don't think it's a launchSettings.json issue, because that would presumably affect all of my target deployments, not just my Test server. I have confirmed via command line that the environment variable is correctly set. I don't really want a web.config-based solution, which I don't think I should need and which will require environment-specific transforms.
Some more things I've tried that haven't helped:
Changed the build type from Release to Debug (since it is Debug in the environments that are working). Still doesn't work.
Tried logging other environment variables, but application dies before it gets to my logging code. Still working on this...
Tried setting the environment variable in applicationHost.config as I'd done on my Development server, but Test server is Windows Server 2012 and IIS 8 and does not support the element in applicationHost.config. (Dev server is Windows Server 2016 and IIS 10, which does support the element in applicationHost.config.)
Tried VS Publish vs. Bamboo deploy. Still doesn't work.
I compared .NET Core installations on the Dev and Test servers. Both have host version 2.2.3, same commit. Dev server has SDKs installed; Test server does not. Dev server has multiple runtime versions installed, latest being 2.2.3. Test server has only 2.2.3 runtime installed. The main difference seems to be the SDKs and I assume I shouldn't need the SDK installed in order to read the environment variables.

I think I've hit this and solved it before. I had to set LoadUserProfile to True in my IIS app pool advanced settings. I'm not sure why this is true because things I've read have said that you need this to read user environment variables and my app is failing to read system environment variables. But, whatever the case, when I set LoadUserProfile to true on my IIS app pool, the app correctly reads the ASPNETCORE_ENVIRONMENT system envrionment variable and the app works as expected.

Have you tried setting this value in the web config?
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>

Related

How to Deploy BizTalk Application into production Server?

I have the following doubts in BizTalk deployment:
How to deploy the BizTalk application to the production server?
When I am modify the existing BizTalk application like artifacts, custom pipeline/functions, custom classes, etc., how again do I deploy the BizTalk application to the server?
I know BTDF is the one of the best tools for deploying BizTalk applications and we can deploy BizTalk application to server using it?
1. Deployment
For deployment you can use the built-in MSI generation wizard.
It means you deploy the application on a dev environment using Visual Studio, then on the admin console, export the application a MSI using the wizard.
Finally you can use that MSI to deploy the app to the Production server.
That's a two step process (Run MSI, import MSI in Bizalk Admin console).
Note that only your Biztalk assemblies are installed by the MSI.
If you use .NET assemblies in your solution, they need to be GAC'ed manually.
You will also need to restart the host instances running your Biztalk application.
See details here:
https://msdn.microsoft.com/en-ca/library/aa559168.aspx
That's a few manual steps.
Alternatively you can automate some of these steps by using the BTSTask, a command line tool included with Biztalk.
You can script all the manual steps.
Obviously it takes time to write such script, so it's only worth it if you are going to deploy many times in non-dev environments.
BTSTask reference:
https://msdn.microsoft.com/en-ca/library/aa559686.aspx
2. Redeployment
Usually you completely remove the old version and then install the new one:
Delete the application from the Biztalk Administration Console and ungac the assemblies it uses.
The whole process would look like:
1. Make sure there are no running instances in you application. You can always disable your receive location and let the running instances complete
2. Delete Biztalk application
3. UnGAC associated assemblies
4. Deploy new Biztalk application version and GAC associated assemblies
5. Restart Host Instances used by your Biztalk application
EDIT: To address OP's concern about deleting a running application:
It is indeed possible to deploy resources independently and never delete your application.
But it does not mean you will not interrupt the service.
An orchestration for example, can never be redeployed when it has running instances.
So assuming that you divided your functionality properly into applications, I find it cleaner and easier to delete the whole application than going after each resource.
Otherwise, yes you can go and replace your resources separately.
But to me it seems like an overhead caused by not having defined applications correctly.
3. BTDF
The Biztalk Deployment Framework is a good tool to have some kind of automation in your deployment without having to write the scripts yourself.
Good compromise between customization to your needs and setup time.
I have used it on a freelance project. It was very helpful because I was able to deliver a package with a only a couple of deployment instructions, and the non-techie client was able to deploy painlessly.

Remotely debugging application on a server with no administrator privileges

My application runs fine on my machine (Windows laptop) but not on production machine (Windows Server 2012). I don't have administrator rights on production machine, so installing Visual Studio remote tools is not possible. Prod machine does not have Visual Studio installed. What is the best way to debug the application running on remote machine in this case?
To get some idea of what is breaking, I looked at EventViewer on prod machine and I see Exception and got to know which function is causing issue. However, as I am new to C#, I need to be able to set breakpoints and step through the code to understand better and fix the issue.
Without remote debugging configured you will not be able tp step trough your code.
Please look at another options like log4Net - when enabled in your application can be very useful to pinpoint a production issue
(very easy to use and configure) installs from VS package manager

Error debugging worker role in Azure

All the sudden started getting the following error while trying to debug a worker role:
"Windows Azure Tools for Microsoft Visual Studio
There was an error attaching the debugger to the role instance 'deployment16(360)blah blah' with Process Id: '8780'. Unable to attach. The Microsoft Visual Studio Remote Debugging Monitor has been closed on the remote machine."
Restarting Visual Studio and the machine do not help.
As you start getting this problem all of sudden in your development machine something must have changed and it is mostly due to some of the OS auto-update and/or some application update you installed in your machine. There could be any random reason for this problem however if I would have hit the exact same problem here is what I would do to troubleshoot such issue:
To start, first thing is to just check it is not an application specific problem by creating a base app from web/worker template and see if that exhibit the problem.
If you have installed new release Windows Azure SDK 1.7 check with both SDK 1.6 and 1.7 to verify if both exhibit the problem.
Check if your could debug IIS based application as well outside Compute Emulator. This will isolate if the problem is specific to Windows Azure development Fabric or bind to your IIS itself.
If this is IIS specific issue, Check IIS configuration for all enabled functionalities, try resetting Application Pool configuration, running "ASPnet_regiis -i" etc to fix the issue.
If it is Windows Azure Computer Emulator specific, I know sometime OS updates may make application unstable so in that case, I will re-install .net 4.0 and VS2010 SP1 again respectively. (This does help so many time) then re-install Azure SDK 1.7 completely.
Such random problem mostly occur due to some change in your machine configuration, so restoring the VS2010 and the re-installing all other application does help to solve problems.
If you have an exception in the role's OnStart() or in Application_Start() that the debugger doesn't pick up, you may also receive this message. Application_Start() errors are especially pernicious because the debugger doesn't attach to the web process until after this method returns.
If you are wedded to cloud specific classes such as RoleEnvironment and cannot make the web role a startup project, you can use Ctrl-F5 to run the cloud project without debugging. With some luck you'll get a yellow screen of death to show you the true error.
Avkash covers the points.
I had the same issue recently. I set my web project as start-up rather than Azure and I discovered that that web project didn't actually run. Turned out somehow when of my projects was compiling for X64. I changed that and it worked.

How do I run (debug) WCF REST Service application on local IIS7 server

As the question says, I have a problem running the web app on local IIS.
Here is my situation:
WIndows over Oracle VM VirtualBox running on Linux Ubuntu.
Bridged Adapter so that Windows box gets local IP from my router.
Visual Studio 2010 + sp
WCF REST Service application plugin for project template
The application runs when using visual studio development server (on localhost).
Target framework is v4.0
What I need is that the application runs on IP instead on localhost (so I can consume it on remote computer in LAN), so I configured IIS7.
Here is IIS configuration:
I created a website with target framework v.4.0
I binded the site to my local IP on port 80
Path to the site is /inetpub/wwwroot iisstart.htm as default document
IIS runs ok. If I open "http://my_local_ip" I get the welcome logo.
The problem is in visual studio.
When I go to project properties "Web" section and select local IIS over vsd server is where I get lost. If I set "Project URL" to "http://my_local_ip/some_name" visual studio complains that it cannot find IIS server and so it was unable to create the virtual directory. I tried manually adding virtual directory in IIS manager, but no effect. If I use "http://localhost/some_name" as the "Project URL" the virtual directory gets created, but it makes no sense does it?
Could some one please enlighten me?
If I use "http://localhost/some_name" as the "Project URL" the virtual directory gets created, but it makes no sense does it?
I think you are mixing two different things here. When you ask VS to use localhost as the IIS Server for your project, it will connect to the local IIS to perform configuration tasks. If you ask VS to use "my_local_ip" you are telling VS that you IIS Server is remote, and therefore VS will use remote administration to configure IIS (VS can't know that my_local_ip is the local computer).
But remote IIS admin isn't enabled on a default WinServer box. Furthermore, it would require some additionnal network config. You should therefore tell vs to use the local server.
In fact, IIS site bindings and VS deployment parameters are too completely different things. So, deploy your site on http://localhost/your_site.
However, I don't really like the prospect of using VS debugging deploy to deploy a real app. The directory will contain all your project files... You should:
create your site on IIS manager and setup a virtual directory.
Either
ask VS to publish the site to a directory (your virtual directory)
ask VS to publish a WebDeploy package, then ask IIS manager to import the package.

How can I test my code against different environments with Visual Studio 2010?

I am working on a project that carries out actions against different versions of IIS depending on what is locally installed. I thought I had read that you could debug in different Virtual machine environments through Visual Studio 2010 if you have the VM's available.
I am working in a Windows 7 environment but need to test my code against a Windows 2003 / IIS 6 environment. Am only limited to creating that environment (VM and all necessary development tools) and testing my code locally?
My question wasn't as clear - I want all the benefits of running in debug mode that I would get if I was developing directly in that environment.
I think I found my own answer:
Remote Debugging of a Project Built Locally
http://msdn.microsoft.com/en-us/library/8x6by8d2.aspx
I'm not sure if you can automate it, but you can remotely debug from visual studio to code running on another machine. If I remember correctly, the trick is (if you're on a domain network) to log into both machines with the same user account (I did this in an active directory networked type environment).
It may have changed in 2010 (I'm on 2008 today), but start the debug instance on the remote machine, then from the VS debug menu, choose "Attach to Process", change the transport to "Remote" and enter in the machine name.
You should then be able to attach to the process, and set breakpoints and debug as you would any other session.

Resources