Uncategorized

How to update the Entity Framework model, when changing stored procedure in Database

Solution:

All you need to do is to open your entity model diagram window, then click on Model Browser then go through each and delete the desired stored procedure artifacts in below folders and SAVE the file.

  1. Complex Types
  2. Function Imports
  3. Stored Procedures / Functions

Advertisements
Azure App Service, Development

How to serve WOFF fonts from Azure App Service

How to serve WOFF fonts from Azure App Service.

Solution:

1. Locate or create web.config

If you have asp.net application you will find the web.config but if you have hosted any other distrubution such as wordpress you can still create the web.config if this is not presented already.

2. Include/merge below code in web.config


  
    
      <mimeMap fileExtension="woff" mimeType="application/font-woff" />
      <mimeMap fileExtension="woff2" mimeType="application/font-woff" /> 
    
  

How to do it:

Go to Azure portal -> Locate your App Service -> Under Development Tools click on Advanced Tools -> click on Go link

How to serve woff font files from Azure App Service

A new tab will be opened and you will see Kudu logo, select Debug console and then CMD

Kudu click on cmd - How to serve woff font files from Azure App Service .png

Now navigate to the D:homesitewwwroot and find the web.config, if you find it then merge the code, else create it and copy paste the code mentioned in step 2.

In fact you can put any file extension you want to serve Azure App Service to serve as static file.

Merge web.config entreies - How to serve woff font files from Azure App Service.png

For more Details

Azure API Management, Azure App Service

How to Get Started with Azure API Management : Part 1

In this post, we are discussing, how to Get Started with Azure API Management, How we can automate API subscription and management using Azure API Management.

This post is a part of the Azure Services series, in this series, we will discuss about Microsoft Cloud Application Architecture and common cloud computing patterns to make application resilient and scalable. We will be using Asp.net MVC as our framework for applicable examples and Azure as cloud services provider.

You can find all the Microsoft Azure Services; we have covered already at Azure series.

How to Get Started with Azure API Management : Part 1

The first question we get in our mind is, why to use Azure API management, what benefits it would give us, and why should we use it.
Azure API Management provide us the ability to create API gateway and developer portal, which is scalable, secure and can work with any host or API and it gives us insights of our APIs as well. The one thing most of us API developers struggle is, how to better manage on boarding process, documentation and provide easiest integration experience to our API’s end users /consumers/developers. This is the part, where Azure API management shines, it give us developer portal to manage the subscription of the services and provides a first-class developer experience. We will discuss all the functionality that Azure API Management provides and how to get most of it.

Let us create our Azure API management Instance first, usually it take a little bit longer around 30 mins to complete creation process.

Go to Azure portal dashboard, click create a new resource button | Search for API management | select API management | click create.

Now we need to fill the form, choose the pricing tier and click create. Let us look at pricing tier first; we have developer, basic, standard and premium tiers.

For Production, either go for basic or high tier since it will give you 99.9+ SLA uptime and options for scalability as well. Every tier support max request per second limitation, if you have only 1 API and 250 subscribers to the service then Basic tier will be sufficient if all 250 users send 2 request per second. From Developer to standard tier, it will only support single region, you can check which region is nearest to your customers/consumers by latency. If you have requirement to support multiple regions, then your only option is to go with Premium tier, and the price per month will increase drastically. Every tier also give us Redis cache as well and capacity is mentioned per instance, if you go for standard tier and you scale it up to 2 instances then you will have 1GB Redis Cache per instance totaling to 2 GB. Other things to consider is AAD integration and virtual network support, if you have need to connect with ADD then go for specific tier after evaluating price to value ratio and also consider virtual network support if you have API service hosted in VM in virtual network then consider it when you make any decision.

For our purpose, we are going with Developer tier, since we are not using it for production and it is giving us almost all the functionalities that other tiers give us except the scaling.

By default, the API management service will have a public URL yourdomain.azure-api.net but we can configure our own custom domain as well.

Creation process will take about 30+ minutes; it took around 38 mins to create in our case. Once the API Management Service is ready, you can see that

Click on developer portal link, will see the screen like below, currently developer/end users can sign up in this portal, the default sign in is configured by default to accept username and password. You can change this.

Go to your API Management Service in Azure Portal | Security | Identity, as you can see we have all the popular options such as Azure Active Directory, Facebook, Google, Microsoft as Identity provider. You may need to add or remove the Providers according to your business needs.

Go back to the Developer Portal and register with any secondary email, you will get confirmation email with link, click on the link to activate the user. Now login to the portal and navigate to the API tab. By Default, we have Echo API listed.

This window will show all the API that are available to consume, click on Echo API, you will see the window like below. By default, first resource is selected and in order to call this resource we need Ocp-Apim-Subscription-Key, you can get this key by subscribing to the Api. You can also click on Try it button to call the resource in the browser, we also have API Definition button if you want to download the API definition in WADL or Open API format.

Let us get our subscription ID, click on Products tabs, choose unlimited for now, we will talk about product later on and click subscribe and confirm the subscription.

Once you are done, a thank you email will be sent to you and you will see screen link below. Right now our unlimited product requires confirmation from Administrator side. So let us go to the Azure Portal and activate our subscription.

Back in the Azure Portal, click on Products | select Unlimited | subscriptions

We have two subscribers here, first one the API Management Service owner who have created this service, and second subscription entry is that we have just submitted earlier. Click on … button and choose Activate subscription and then click yes.

Now go back to Developer portal and refresh, you can see that subscription state is active now and you can also see the Primary key and secondary key.

Next step is to test the Echo service, click on APIS tab, select echo API and click on try. You can see now that the subscription key is automatically populated for you, you just need to click on send.

The response will be shown underneath of the send button.

Now let us create our own API and configure it with the Azure API Management, coming up next

Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Remote debugging App Service using visual Studio, monitoring and configuring alerts: Part 3

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

  1. Remote debugging App Service using visual Studio, monitoring and configuring alerts

We have successfully configured the deployment slot in previous post, now we are going for remote debugging. In Azure remote debugging using visual Studio is not enabled by default, you have to enable debugging for specific VS version to debug. Although if you have permissions you can do it by Visual Studio if you do not have enough permissions, please ask your Azure Subscription owner. In our case we are the owner of Azure Subscription so we will proceed for debugging with out requiring any permissions,

If you have not already opened your visual studio, then open it and load the project you had deployed earlier. Now go to Cloud Explorer | your subscription | Select your app | Actions | Click on Attach debugger.

Figure 1 Remote Debugging

Debugger will be attached, it may take some time depending upon your internet connection speed and your location distance to Azure Data center, If you are getting error like below, that means you do not have permissions to debug or you have not enabled Debugging for your App Service, remember by default debugging is not enabled. In my case, it was referring to firewall settings and we found out that there were some ports closed which needed to be opened to communicate with Azure.

Figure 2 Error While connecting to Remote Debugging Session

Go to Azure Portal and then App Service | Settings | Application Settings | Debugging | enable Remote debugging and also choose visual studio version and click save. Now by this step your debugger should be attached successfully.

Figure 3 Enabling Remote Debugging

If you still not able to resolve the problem please consult my recent post which discuss the steps to fix common debugging issues.

Also check Microsoft page

Once you are in debugging mode, you can use all the tools that you use while debugging locally.

App Service Monitoring

Let us move on to monitoring our App Service.

Azure provide you multiple ways to monitor your App Service, Let us explore them, go to Azure Portal and then App Service | Overview, in this view you can see the basic information about http errors, data in, data out, number of requests and Average response time. All though this view will satisfy most users, but you can even drill down and generate custom views for you as well, just click on any of the chart and you will see a new view, in which you can tailor the chart according to your metrics.

Figure 4 Monitoring performance

For demo, We have added CPU Time into the mix, and we can see that display show both Average Response Time and CPU Time as well.

Figure 5 Create Custom chart

You can click on Pin to dashboard to see it on your main dashboard as well.

Figure 6 Pin to dashboard

Alerts

This bring us to our next topic alerts, alerts can be very useful especially when you have a lot of resources and do not have time to manually check the metrics to see what is going on. We can create alert right on a particular metric by clicking on

Or App Service | Monitoring | Alerts

Let us create an alert on CPU Percentage on our App service Plan ( it will include all the apps hosting on same App Service Plan) and choose CPU Percentage and set condition to “greater than” and threshold to 80. You will notice that the chart shows you current CPU percentage in dotted line and the threshold in straight line, do not forget to check email owners check box if you are the owner and want to get the alert email otherwise there is a textbox to add addition emails or call a webhook. Webhook is a restful endpoint, which is publically accessible to Azure and will be called when metric pass the condition we set. Mostly developer use webhook to initiate a workflow, which could for example increase number of running instances through PowerShell script or initiate a business workflow. To learn more about webhook see https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts

Figure 7 Create alert on CPU percentage for App Service Plan

As you, can see that I have created two alerts, one for CPU percentage and another for Memory percentage. Now when ever condition you set will meet you will get an email or a webhook will be called. Alerts truly simplify our monitoring task specially if we have a lot of resources to worry about.

Figure 8 Create Alert on CPU and Memory percentage

Congratulations, you have successfully debugged and monitored your application and configured alerts.

Coming up next Diagnostic logs, live stream, process explorer and KUDU

 

Azure App Service, Azure Cloud, Cloud Computing, Visual Studio

Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK: Part 2

I am putting together a series for people who are excited to bring Azure into their software development life cycle and use Azure cloud’s extensive services to their full potential.

In this series, I will cover as below:

  1. Getting Started with Azure Development, Create App Service Plan and Publish MVC project using Visual Studio
  2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK
  3. Remote debugging App Service using visual Studio, monitoring and configuring alerts
  4. Diagnostic logs, live stream, process explorer and KUDU
  5. How to use Azure SQL Database in Dot.net Applications
  6. How to use Azure DocumentDB or Azure Cosmos DB in our Dot.net Applications
  7. How to use Visual Studio Team Service to do continuous Integration and continuous delivery
  8. Azure storage data services types and how to store files in azure storage account 1/2
  9. Azure storage data services types and how to store files in azure storage account 2/2
  10. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 1/2
  11. How to use Azure Functions and trigger on new image/blob creation in Azure Storage using BlobTrigger 2/2

If you do not know where to start, please check my blog post, which covers detail about getting subscription and setting up. In this series, we assume that you already have active Azure subscription and Visual Studio 2013 or later installed on your system.

2. Deployment Slots and Slot Swap on Azure App Service using Visual Studio and Azure SDK

At this point, you have successfully created the App Service Plan, App service and published the changes to the Azure using Visual Studio and Azure SDK. Let us move to exciting part of remote debugging and monitoring, fire up your visual studio if you have not opened it before and open the project we created in recently.

Figure 1 App Service Deployment Slot

Let us talk about Deployment Slot, this is feature provided by App service, this basically enable you to deploy your code to different containers i.e. QA, Staging or Production, in this way you will make sure that your code is fully tested and ready to move to production. This approach support setting up different App Settings and connection strings for the Databases for each slot, which will enable us to test and deploy our changing with ease.

I know you are excited about this feature lets, let us open web.config and add a new App Setting

<add
key=WelcomeMsg
value=Welcome to Azure Development!/>

Figure 2 Add new App settings in web.config

Now show this setting in our index page, Views | Home | Index.cshtml and edit it as shown below:

@using System.Web.Configuration;

@{

ViewBag.Title = “Home Page”;

}

<div
class=”jumbotron”>


<h1>ASP.NET</h1>


<p
class=”lead”>@WebConfigurationManager.AppSettings[“WelcomeMsg”]</p>


<p><a
href=”https://asp.net&#8221;
class=”btn btn-primary btn-lg”>Learn more &raquo;</a></p>

</div>

Figure 3 Edit Index file

Now after this change just press F5 to lunch and see the change.

Figure 4 App setting message is showing

Now publish your solution to the Azure App service as we did in our previous post. You can see that new changes publish.

Figure 5 Publishing Changes to Azure App Service

We will override the changes in our App Service Settings; go to Azure Portal and then App Service | Settings | Application Settings, here we will add the key and value to override the default one, please note that we can also use this interface to add new keys as well, this interface is not limited to just overriding key values.

Figure 6 Override Application Settings in Azure Portal

Now refresh to see that message is changed as expected.

Figure 7 Override setting display

Now let us create slots for staging slot. Go to Azure Portal and then App Service, Deployment | Deployment Slots | Click Add Slot and name it as staging, in configuration Source choose the main app and click ok. It could take few minutes depending upon application size.

Figure 8 Add new Staging Deployment Slot

Once deployment slot is added successfully, click on it to see the settings.

Figure 9 Deployment Slot is added successfully.

Change the “WelcomeMsg” to “Welcome message from staging” and tick “slot setting” check box, as when we swap this deployment slot with production this setting will not move and will stay with this slot. This way we will be able to retain the settings that are slot specific.

Figure 10 Change App settings on Staging Deployment Slot

Now question arise how we are going to deploy our source code to staging slot, the answer is very simple Publish Profile, click on Over view and then click on Get Publish Profile and save it to local system.

Figure 11 Get Publish Profile Setting

Go back to visual studio | Publish and click on Create new profile, select Existing check box, click on import profile, click ok, select the staging profile that we got in previous step and click ok.

Figure 12 Import Profile

Figure 13 Import profile and publish

For testing purposes open Index.cshtml file and update it as below

<p
class=”lead”>We have update the project</p>

Figure 14 Update for staging

Publish the changes to staging slot by just clicking on publish; we can see that our recent changes have been published successfully.

Figure 15 Publish changes to staging slot

All these steps lead us to the exciting part of Deployment Slot Swap, Go to Azure Portal and then App Service, click on swap and click ok.

Figure 16 Slot Swap

Figure 17 Choose Swap Slot

Swapping operation will take some time to complete, in side-by-side comparison you can see that staging code is swapped to production and production code is swapped to staging. Remember that user will be experience any downtime in this operation will continue to use the application as they were before swap.

Figure 18 Production and Staging slot swapping

With this congratulation, you have successfully created new staging slot, deployed your code to staging slot, used sticky slot settings, and swapped production with staging.

Coming up next Remote debugging App Service using visual Studio, monitoring and configuring alerts