I've got the Redis Session State Provider working fine locally with my ASP.Net site and in Azure with my Azure Website. But I've got a question about configuration...
Is there any way to store the configuration for that in the Azure Website itself using the App Settings (or Configuration Strings) section in the Website Properties screen?
That would be very convenient because it would mean that I don't have to modify the web.config file when I publish. I already do this for connection strings and app settings, but I just don't see a way to do that for anything in the <system.web> node of the web.config file, like the <sessionState> node.
There isn't a way to change the behaviour of the provider-based session state from utilising the web.config file.
You could write your own provider and modify where it finds the connection details from so you can publish those details somewhere other than in the web.config, but this wouldn't be standard behaviour.
This question has the way to make this work.
<appSettings>
<add key="REDIS_CONNECTION_STRING" value="[your dev connection string]" />
</appSettings>
<system.web>
<sessionState mode="Custom" customProvider="RedisProvider">
<providers>
<add name="RedisProvider" type="Microsoft.Web.Redis.RedisSessionStateProvider" connectionString="REDIS_CONNECTION_STRING" />
</providers>
</sessionState>
</system.web>
Then, in the portal, you can create an app setting with the name 'REDIS_CONNECTION_STRING' with the correct connection string. You cannot use connection strings section of web.config or azure portal. It must be app settings. Not sure why, but connection strings just uses whatever is in the web.config and is not replaced with what is in the portal.
Related
I have a Web App that I deploy via YAML pipeline, but would like to see if it can be done via web app's Deployment Center.
I need to transform the IP address and userPrincipalName in the endpoint element, but it does not fall under AppSettings or connectionstring element. Is it possible to transform this kind of element via Web App, or am I stuck with YAML pipeline?
Here is snippet of my config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="API_AUTH_MODE" value="2" />
</appSettings>
<system.serviceModel>
<client>
<endpoint address="net.tcp://10.0.0.0:99/App1/Services/Service1"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Service1"
contract="Service1" name="NetTcpBinding_Service1">
<identity>
<userPrincipalName value="user#domain.local" />
</identity>
</endpoint>
<endpoint address="net.tcp://10.0.0.0:99/App1/Services/Service2"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Service2"
contract="Service2" name="NetTcpBinding_Service2">
<identity>
<userPrincipalName value="user#domain.local" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Is it possible to transform this kind of element via Web App, or am I stuck with YAML pipeline?
AFAIK, I am afraid you could not transform this kind of element via Web App at this mpment.
That because the IP address and userPrincipalName does not fall under AppSettings or connectionstring element.
So, we could not use the Application settings or connection strings to replace it. We have to resolve this issue with YAML pipeline.
BTW, we could use the Replace Tokens in the YAML pipeline to resolve it.
Hope this helps.
While it was answered correctly above - Web App cannot transform anything other than Appsettings or 'connectionstring`, I ended up doing the following:
Use XML Transform files to replace the strings needed, since there is dependency on build type
Use YAML file to access vault to do password replacements.
I could have used Web App to do the password replacements, but it is much easier to manage the pipeline/deployment/release via a single YAML file rather than split YAML and Web App.
Background
I have an Azure 'App Service' resource and a linked 'Application Insights' resource. They're linked via the App Service's Settings -> Applications settings -> Application settings (key-value table) where I have the following settings:
APPINSIGHTS_INSTRUMENTATIONKEY = <my application insights instrumentation key>
APPINSIGHTS_JAVASCRIPT_ENABLED = true
My application is a static file application at the root / (site\wwwroot) but also has 2 Asp.NET applications at 2 different virtual directories:
/app1 (site\app1)
/app2 (site\app2)
Problem
The overview page shows data for something called 'Metrics' with requests, data, etc. (first image) however when I attempt to access Application Insights, no data appears (second image).
Attemps
I've tried to follow these two guides for activating app insight for static page applications:
http://apmtips.com/blog/2014/12/02/tracking-static-content-with-application-insights-httpmodule/
http://blog.tylerdoerksen.ca/posts/2018/03/AppInsights-Static-Content
However I get an error due to the misisng DLLs in the root Bin folder.
I tried variations of:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"> <!-- With and without 'runAllManagedModulesForAllRequests'. -->
<add name="ApplicationInsightsWebTracking"
type="Microsoft.ApplicationInsights.Extensibility.Web.RequestTracking.WebRequestTrackingModule, Microsoft.ApplicationInsights.Extensibility.Web"
preCondition="managedHandler" /> <!-- With and without 'preCondition="managedHandler"'. -->
<!-- And -->
<add name="ApplicationInsightsWebTracking"
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/> <!-- With and without 'preCondition="managedHandler"'. -->
</modules>
</system.webServer>
According to the second article, these missing DLLs should be automatically loaded by Azure once it knows that it's connected to AppInsight.
If you are using Azure Web Apps. Add the Applications Insights Extension to the Web App. This will add the proper DLLs to the Bin directory of your site.
I tried to follow the instructions under 'Monitor a live Azure web app' but the documentation seems incomplete.
Questions
Why is data showing in the overview of the App Service but not AppInsight?
Is it possible to view website telemetry in AppInsight for my static file application at root /?
1.Why is data showing in the overview of the App Service but not AppInsight?
It should be a configure issue. You can configure it as below:
step 1:
In visual studio, right click your project name, and in the context menu, select "Configure Application Insights".
step 2:
In the following screen, click "Get started".
step 3:
In the following screen, configure your own settings(for Resource, you can create a new or use an existing one).
Then click "Register", and wait for it completes.
step 4:
If some error occurs, just fix it by tips on the screen. like below:
When you have done the above steps, you should see data in App insight(it may take a few minutes for data to display).
2.Is it possible to view website telemetry in AppInsight for my static file application at root /?
Yes, you can view website telemetry in AppInsight for static file application at root /.
step 1:
In the Web.config, find the <system.webServer> node, and then in the <modules> node, add runAllManagedModulesForAllRequests="true", like below:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
step 2:
Publish web site to azure.
step 3:
Launch the website to the static file, here I used test4.html for example.
step 4:
Go to azure portal -> your application sights -> Overview section, select a chart like "Server requests"(if no data, please wait for a while).
step 5:
You can see such request "GET /test4.html".
I would like to know about JobHostConfiguration on Azure WebJobs SDK.
Where I can find the config ? is it on app.config ?
How can JobHostConfiguration identified this is IsDevelopment or not ?
I cannot find it on app.config
What config that JobHostConfiguration read ?
Thank You
Where I can find the config ? is it on app.config ?
Yes, it is in app.config file. You also could add some new configs manually in this file.
How can JobHostConfiguration identified this is IsDevelopment or not ?
It depends on whether the JobHost is running in a Development environment. The default value is false. If you want it to be true, you could add the following code in app.config file to let the JobHost run in a
Development environment. And you could read this article to learn more about this configuration.
<appSettings>
<add key="AzureWebJobsEnv" value="Development"/>
</appSettings>
The result is like this:
What config that JobHostConfiguration read ?
It could read many information of config, such as the connection string of Azure Web Jobs. You could click New Project>Cloud>choose Azure WebJob to create a Web Jobs to try.
Read connection string in app.config file:
<connectionStrings>
<!-- The format of the connection string is "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
<!-- For local execution, the value can be set either in this config file or through environment variables -->
<add name="AzureWebJobsDashboard" connectionString="your storage connection string" />
<add name="AzureWebJobsStorage" connectionString=" your storage connection string " />
</connectionStrings>
I was recently having a problem with a site and the stack trace was implying that the connectionstring was null. This is after i moved (i.e. cut the node out of the xml file, pasted it into portal) the connstr from web.config to azure portal, so the connstr wasn't referenced the web config at all
In a video blog, Scott Hanselman talked about the portal settings overriding the web.config ones, but there was never any detail on what whether the key had to be present in the deployed web config for the azure portal value to be applied
This raises a query in my mind - if a setting isn't in the web.config at all (i.e. there is no xml node saying <add key="blah" value="debugblah" />), will the setting in the portal work?
if a setting isn't in the web.config at all (i.e. there is no xml node saying <add key="blah" value="debugblah" />), will the setting in the portal work?
The short answer is Yes. To simple test it, you could using following code.
public ActionResult Index()
{
string appSetting1 = ConfigurationManager.AppSettings["setting1"];
string connectionString1 = ConfigurationManager.ConnectionStrings["connectionString1"]?.ConnectionString;
return Content(string.Format("appSetting1:{0},connectionString1:{1}", appSetting1, connectionString1));
}
After added parameters in Azure portal, we could get the app setting and connection string from ConfigurationManager.
Here is the result from index page.
appSetting1:setting1Value,connectionString1:connectionString1Value
There is an exception when we use connection string for Entity Framework. A connection string for EF will contain a providerName attribute which can't be set in Azure portal. So if we need a connection string setting with providerName, we need to configure the connection string in config file.
<add name="DataContext" connectionString="dummy" providerName="System.Data.EntityClient" />
is it a xdt:Transform=“SetAttributes”, a xdt:Transform=“Insert” or hybrid?
It is a hybrid
or, possibly
Portal does a remove, followed by an insert
Which means:
If the setting is only configured in portal.azure.com then your app will see the value set in portal.azure.com
If the setting is only configured in the web.config file in the wwwroot folder, then your app will see the value set in the web.config file
If the setting is configured in both portal.azure.com AND the web.config file, then the app will see the value set in portal.azure.com
So don't worry if you upload your debug/dev configs to a live site, if the portal settings contain the live settings details :)
Thanks to Amor for the method used to verify this
Yes, it will work.
The setting does not have to be present in the web.config file. If it is present in the Web App's Connection Strings or Application Settings (set in the portal or via AzureRM), then it will be visible to the application.
I've got a web.config that contains my SQL connection string and my Azure Blob storage connection string.
A Web.Config transformation replaces my Local SQL connection string with the Azure one.
When I publish the site to Azure, the Blob storage connection string is deleted and replaced with a duplicate SQL connection string, but with the blob storage string's name.
The only way I've found to fix is to log in via FTP and manually change the erroneous Storage connection string with the correct one from my local machine.
How do I get VS to publish my web config to Azure and leave it alone!!!
Web.Config
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="StorageConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=;AccountKey=" />
</connectionStrings>
Web.Release.Config
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=.database.windows.net,1433;Database=;User ID=#;Password=!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
I had a similar issue to yours. I'm not sure why but when you define the connection strings in the "Configure tab" in the azure portal and associate a "Linked Resource" on the linked resource tab it may override certain properties in the Web.config transform causing unexpected results. One of the options when you set up a new azure website is linking to (or creating a new) database to associate with your website - thereby automatically assigning the related connection string which may try to override your transform operation defined in the Web.Release.config.
Check and see if removing all connection strings and linked resources inside the "Azure Portal" fixes your problem. Just make sure that you have both your production database and storage connections strings defined properly in the Web.Release.config.
I struggled with this problem this morning and I came up with a solution for VS2015/17.
So I have an Azure VM, and to publish my web app on this machine, I used the Web deploy to an Azure VM proposed by VS.
I put my connection strings in an external file, so the useful part of my web.config looks like this :
</entityFramework>
<connectionStrings configSource="ConnectionStrings.config">
</connectionStrings>
</configuration>
in order to prevent VS of adding some connection strings during publication (ADO.Net code first MSSQL database connection string in my case), you can edit the following file in your project :
...\MyProject\Properties\PublishProfiles\YourPublishProfile - WebDeploy.pubxml
In this file look into the ItemGroup part and edit it to delete the connection strings you don't need:
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="MyProject.Models.MSSQL_DB" Order="1" Enabled="False">
<Destination Path="" />
<Object Type="DbCodeFirst">
<Source Path="DBContext" DbContext="MyProject.Models.MSSQL_DB, MyProject" Origin="Convention" />
</Object>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<here are some entries delete the ones you don't need/>
</ItemGroup>
Be careful, if you add a file in this repertory, there is chances that it breaks the publication process on VS. Don't add file, just edit.