From this MSDN article it says that the connection string for connecting to the storage account must be HTTP and not HTTPS.
When I use this constructor:
public CloudDrive (
Uri uri,
StorageCredentials credentials
)
Does that mean the Uri to the page blob must also be HTTP and not HTTPS? I am a bit confused regarding which parameter (or both together) fits the 'connection string' description.
This scenario does not seem to be easily testable in dev emulator.
The URI (think of as the server-portion of the connection string) to the page blob represents the namespace + container + blob of your storage account. The credentials represent the user/pass which together with the URI comprise the connection string to the Azure cloud storage service.
The URI will always be HTTP assuming you are using the local emulator.
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
When deploying to Azure, the URI scheme will be whatever you assign it in the service configuration (ServiceDefinition.csdef / ServiceConfiguration.Cloud.cscfg).
CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("CloudDrive.DataConnectionString");
You would just want to assign CloudDrive.DataConnectionString to have DefaultEndpointsProtocol=http (the default if omitted, but you could be explicit).
ServiceDefinition.csdef
<ServiceDefinition>
<WebRole>
<!-- .... -->
<ConfigurationSettings>
<Setting name="CloudDrive.DataConnectionString" />
</ConfigurationSettings>
</WebRole>
</ServiceDefinition>
ServiceConfiguration.Cloud.cscfg
<ServiceConfiguration>
<Role>
<ConfigurationSettings>
<Setting name="CloudDrive.DataConnectionString" value="DefaultEndpointsProtocol=http;AccountName=YOURNAMESPACE;AccountKey=YOURKEY" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
Related
I need to create access to the Azure storage from application. Application requires storage, where to put file. This code below, I am trying to put where application requires path to store file. Am I doing right? How can I implement this into XML of Application, so then it starts to write files to cloud storage.
<connectionStrings>
<add name= "DefaultConnection" connectionString="DefaultEndpointsProtocol=https;AccountName=;AccountKey=;/>
</connectionStrings>
Please take a look at this doc for example.
In your app.config, please add:
<appSettings>
<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key" />
</appSettings>
And in your code, please use:
// Parse the connection string and return a reference to the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
Then you can take use of azure storage.
if you login to the Blob image storage on Azure. it should populate the connection string by default. PFB Reference
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.
I've got an app that I've deployed with Azure, and I am trying to get plain vanilla Tracing working
I've gone through all of these articles:
https://stackoverflow.com/search?q=diagnosticmonitortracelistener
Here's my role entry point:
public class WebRole :RoleEntryPoint {
public override bool OnStart() {
if (RoleEnvironment.IsAvailable) {
LocalResource localResource = RoleEnvironment.GetLocalResource("MyCustomLogs");
DirectoryConfiguration dirConfig = new DirectoryConfiguration();
dirConfig.Container = "diagnostics-mycustomlogs-container";
dirConfig.DirectoryQuotaInMB = localResource.MaximumSizeInMegabytes;
dirConfig.Path = localResource.RootPath;
DiagnosticMonitorConfiguration diagMonitorConfig = DiagnosticMonitor.GetDefaultInitialConfiguration();
diagMonitorConfig.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
diagMonitorConfig.Directories.DataSources.Add(dirConfig);
DiagnosticMonitor diagMonitor = DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", diagMonitorConfig);
Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
Trace.AutoFlush = true;
Trace.WriteLine("Role Starting");
}
return base.OnStart();
}
}
Also put the trace listener in global.asax.cs:
if (RoleEnvironment.IsAvailable) {
Trace.Listeners.Add(new Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener());
Trace.AutoFlush = true;
}
I've also tried just pasting it directly into web.config
<trace>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener,
Microsoft.WindowsAzure.Diagnostics,
Version=1.8.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
This directory gets created in my Azure VM
C:\Resources\Directory\d63aeab4198d458a9c0b1d0f818e4054.CorpQna.Web.MyCustomLogs
This is in my ServiceDefinition.csdef file:
<LocalResources>
<LocalStorage name="MyCustomLogs" cleanOnRoleRecycle="false" sizeInMB="10" />
</LocalResources>
When I add a TextWriterTraceListener in my local Compute Emulator, it works:
<trace autoflush="true">
<listeners>
<add type="System.Diagnostics.TextWriterTraceListener" name="TextWriter"
initializeData="c:\trace.log" />
</listeners>
</trace>
However, this does not work on Azure. (I suspect permissions?)
I'm at a standstill at this point. No errors anywhere, but no logs either. There's no record of the Blob being created in my Blob Store.
Doug, you are confusing a few different concepts here:
Diagnostics Tracing to a file
Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener
WAD DirectoryConfiguration
In .NET, diagnostics tracing will write to all of the registered listeners. The Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener is a trace listener which essentially writes to the WADLogsTable table in Azure Storage. Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener does not write to a local file such as your MyCustomLogs folder. The WAD DirectoryConfiguration will upload files, but this really doesn't have anything to do with .NET diagnostics tracing, unless you are also adding a TextWriterTraceListener.
So your code as-is probably works fine, but you are looking in the wrong place for the data. It won't be in a blob coming from the MyCustomLogs folder, but rather in the WADLogsTable table. If you want the tracing to also be in the MyCustomLogs folder then you can add another listener of type TextWriterTraceListener pointing to a file in your MyCustomLogs folder.
Have you checked that in your service configuration, you are using correct storage account for diagnostic.
By default, it is pointing to local dev storage. you may have to change with valid storage account.
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
I develop a website on Windows Azure, MVC4. I try to upload and get photos from blobs.
My related code (that I got from other examples on web):
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString);
var blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference("abc");
container.CreateIfNotExists();
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
My related web.config code:
<add name="StorageConnection" connectionString="DefaultEndPointsProtocol=https;AccountName=abc;AccountKey=*******"/>
When I run I got a format exception. Please note that it is web site.
As per some posts, when I put my connection string to app.config, no solution.
Thank you very much for any assistance.
You shall not use connectionStrings section to store Azure Storage Connection string!
Use appSettings instead and you will have no issues. It is confusion that the Storage credentials is also named "Connection string", but it has nothing to do with the connectionStrings section in your configuration file. connectionStrings section is intended solely for use DataBase connection strings.
I have an application currently in Azure and whenever we push it into the Staging segment, we cannot truly test since the connection string is pointing to the prod database.
Someone mentioned to me that you should be able to set the connection string in the ServiceConfiguration.cscfg file instead (or with) the web.config file. That way you can change the connection string in the Azure portal instead of republishing a who app.
Does anyone know how to do this?
In your ServiceConfiguration.cscfg file add:
<ServiceConfiguration ... />
<Role ... />
<ConfigurationSettings>
<Setting name="DatabaseConnectionString" value="put your connection string here" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
Now you have a connection string you can change by editing the configuration inside the azure portal.
Then anytime you need to retrieve the connection string you can do it using:
using Microsoft.WindowsAzure.ServiceRuntime;
...
String connString = RoleEnvironment.GetConfigurationSettingValue("DatabaseConnectionString")
You may need to add Microsoft.WindowsAzure.ServiceRuntime.dll to your references.
RoleEnviroment.IsAvailable can be used to test if your are running in Azure, and if not to fall back to your web.config settings.
using System.Configuration;
using Microsoft.WindowsAzure.ServiceRuntime;
...
if (RoleEnvironment.IsAvailable)
{
return RoleEnvironment.GetConfigurationSettingValue("DatabaseConnectionString");
}
else
{
return ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
}
This article has a more verbose explanation of the above.
For Entity Framework, you do not need to provide a providerName, it's already inside in the connectionstring. The reason why it does not work when it's in azure settings is, it contains " symbol which needs to be transalated back to " before creating a new EntityConnection. You can do it using HttpUtility.HtmlDecode in System.Web.
Basically you need to define these setting in Azure service configuration file. Check here. Once defined these can be changed from Azure portal.