Imageresizer across multiple containers in azure storage - azure

Im uploading images to azure blob storage in a project. For logic reason I'm creating a new container for each upload, to group the content. This park works fine. Now I'm trying to setup ImageResizer to enable resizing :) and som other stuff. In all the examples they point to a container as the endpoint, but in my case I have multiple dynamic container, so this is not an option. My question is if someone knows if it should work in my case or if I need to rethink something about the way I store images.

According to your requirement, you could try to leverage AzureReader2 to work with Azure blobs, in order to dynamic resize your images from Azure Blob. Since you have miltiple dynamic containers, you could follow the steps below to configure AzureReader2:
Install Package via NuGet
ImageResizer.WebConfig
ImageResizer.Plugins.AzureReader2
Web.config
<configSections>
<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />
</configSections>
<resizer>
<plugins>
<add name="MvcRoutingShim" />
<add name="AzureReader2"
connectionString="{your-storage-connectionstring}"
prefix="~/cloud/" />
</plugins>
</resizer>
<system.web>
<httpModules>
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</httpModules>
</system.web>
<system.webServer>
<modules>
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</modules>
</system.webServer>
Result
Here is my test, you could refer to it.
1.Upload images to my Azure Blob
https://brucechen.blob.core.windows.net/images01/test.jpg
https://brucechen.blob.core.windows.net/images01/landscape/test.jpg
https://brucechen.blob.core.windows.net/images02/test.jpg
2.Browser images in my web site as follows:
http://bruce-chen.azurewebsites.net/cloud/images01/test.jpg?width=400
http://bruce-chen.azurewebsites.net/cloud/images01/landscape/test.jpg?width=400
http://bruce-chen.azurewebsites.net/cloud/images02/test.jpg?width=400
Note: your images links should look like:
http(s)://<host-name>:<port>/<prefix-you-configured>/<blob-container-name>/<blob-file-name>?width=200&height=200
Additionally, for pre-resizing your images via ImageResizer, you could follow the answer in this thread. Also, there is anther similar library called Simple.ImageResizer which is free, you could refer to it.

Related

Azure web app: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable

For a university project we are using Azure to function as an API backend to a website hosted on Github Pages. The Azure server has recently stopped functioning, giving the error "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable".
The web.conf file was not changed, other than a couple of new php files nothing was, and the server was functioning for a while after these files were uploaded.
We have tried restarting and redeploying the server, which fixes the problem but only for a couple of minutes.
The web.conf file is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="allToIndex" stopProcessing="true">
<match url="^((?!css).)*$"/>
<action type="Rewrite" url="index.php" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Any help would be greatly appreciated.
Please check if below steps helps to:
Make sure the web.config is placed in the root folder of the website.
Make Sure you allow your IP address in the web.config file like below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<security>
<ipSecurity allowUnlisted="false" denyAction="NotFound">
<add allowed="true" ipAddress="XXX.XXX.XXX.XXX" />
</ipSecurity>
</security>
</system.webServer>
</configuration>
Sometimes, the web.config is missed in the Azure Portal Web application Folder. If missed, In the Kudu (the backend for Web Apps) will create a Web.config for you. So you go to <your_site>.scm.azurewebsites.net and use the file browser, you'll find the web.config that's automatically generated if you don't specify one.
Check the Configuration Settings once by traversing to Azure Portal > App Service > Settings > Configuration > General Settings > <check the stack and PHP version - update as per requirement> and then Click Save, Restart the applied changes in Configuration and also the App Service.
If you're uploading any files to the existing PHP Web Application Azure, then please check this reference related to updating web.config file.
Also Please check the below references related to the specific error of PHP Web App in Azure called The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
MSFT Q& A related thread to resource temporarily unavailable/removed/name changed
Article 1
A GitHub Page of the above specified error resolution

Azure AppInsight not working for static file application

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".

Configure Redis Session State on Azure

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.

Azure shows directory content

After I published my azure cloud service to azure, I got as result the following:
Do you know what the problem is? I am using asp.net 4.0 mvc razor. I think, it doesn't load the webconfig.
You don't have a Default.aspx. You can either add a Default.aspx, or you can modify the web.config's <defaultDocument> property.
You can have following configuration in web.Config -
<configuration>
<system.webServer>
<defaultDocument>
<files>
<add value="HtmlPage1.html" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
</system.webServer>
</configuration>
And in RoutesConfig.cs -
routes.IgnoreRoute("");
Having IgnoreRoute() will make ASP.Net to fetch the default document specified in the web.config, instead of Routes engine to process route. And defaultDocument tag will make that file to be served for default URL "/".
I took the solution to take a Azure Website and not a Web Role and it works :)

Publishing Web.Config to Azure removes Azure storage connection string

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.

Resources