“Client with IP address is not allowed to access the server” when running update-database command through Visual Studio.

If you are deploying your entity framework database changes to your production database through Visual Studio(like we do) for the first time,  you might receive the following error:

Cannot open server '<ServerName>' requested by the login. 
Client with IP address '<MyIPAddress>' is not allowed to access the server.  
To enable access, use the Windows Azure Management Portal or 
run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range.  
It may take up to five minutes for this change to take effect.

To fix this issue, you need to go to your database in the azure portal, click “Set server Firewall” and then add your IP address under “Add Client IP”

2019-04-30 23_10_11-SimplerProductsScrubber_db - Microsoft Azure

image

Continue Reading

List all AWS resources

I was being charged for AWS resources that I had forgotten to delete. Deleting these resources by going to each region is a big hassle.
The best way that I found to list all AWS resources(short of using a github tool) across all regions is to use the Tag Editor. When searching, select all the regions and all the resource types.  You can then use a link to go to each resource and then delete it, if appropriate.

image

Continue Reading

Send emails using SendGrid Email provider and ASP.Net Core

Sending emails using SendGrid email provider and ASP.Net Core is very straightforward.
Firstly install SendGrid package through Package Manager Console using the following command

install-package SendGrid

Now create a account in Sendgrid.com and add an API key to use the SendGrid provider service.  Add this key to your AppSettings.Json or AppSettings.Development.Json under a new SendGridEmailSettings=>SendGridKey node.

image

AppSettings.Json:

{
"SendGridEmailSettings": {
"SendGridKey": <SendGrid Private API Key>
}
}

StartUp.cs:

public void ConfigureServices(IServiceCollection services)
{
……………………..
services.AddTransient<IEmailSender, EmailSender>();
services.Configure<AuthMessageSenderOptions>(options =>
Configuration.GetSection("SendGridEmailSettings").Bind(options));
}

EmailSender .cs

using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.Extensions.Options;
using SendGrid;
using SendGrid.Helpers.Mail;
using System.Threading.Tasks;

public class AuthMessageSenderOptions
{
public string SendGridUser { get; set; }
public string SendGridKey { get; set; }
}
public class EmailSender : IEmailSender
{
public EmailSender(IOptions optionsAccessor)
{
Options = optionsAccessor.Value;
}
public AuthMessageSenderOptions Options { get; } //set only via Secret Manager
public Task SendEmailAsync(string email, string subject, string message)
{
return Execute(Options.SendGridKey, subject, message, email);
}
public Task Execute(string apiKey, string subject, string message, string email)
{
var sendGridClient = new SendGridClient(apiKey);
var sendGridMessage = new SendGridMessage()
{
From = new EmailAddress("ajitgoel@gmail.com", "Simpler Products-Social Media Scrubber"),
Subject = subject,
PlainTextContent = message,
HtmlContent = message
};
sendGridMessage.AddTo(new EmailAddress(email));
// Disable click tracking.See //sendgrid.com/docs/User_Guide/Settings/tracking.html
sendGridMessage.SetClickTracking(false, false);
return sendGridClient.SendEmailAsync(sendGridMessage);
}
}

If you send an email and you do not receive it in your mailbox check the spam folder. My emails landed in the spam folder when I was testing the application.

Continue Reading

NotSupportedException: No IUserTwoFactorTokenProvider named ‘Default’ is registered.

If you have changed the AddDefaultIdentity in the Startup.cs file to AddIdentity and you receive a

An unhandled exception occurred while processing the request.
NotSupportedException: No IUserTwoFactorTokenProvider<TUser> named ‘Default’ is registered.
Microsoft.AspNetCore.Identity.UserManager<TUser>.GenerateUserTokenAsync(TUser user, string tokenProvider, string purpose)

error when registering a user, there is a easy fix. You need to a add a AddDefaultTokenProviders() when adding identity() to services.

public void ConfigureServices(IServiceCollection services)
  {
  ………………
  services.AddIdentity<User, UserRole>()
   .AddEntityFrameworkStores<ApplicationDbContext>()
   .AddDefaultTokenProviders();
…………………….

Continue Reading

Show\Hide results pane in SQL server management studio

To change keyboard shortcut for show/hide results pane, go to Tools Options in SQL Server Management Studio:

Navigate to Environment > Keyboard > Keyboard.
Search for “Window.ShowResultsPane” using “Show commands containing” textbox.
In the “Press shortcut keys” textbox, press Cntrl + R buttons on the keyboard at the same time.
Click the “Assign” button and then click “OK“.

You might need to restart SQL Server Management Studio to apply these changes.

Continue Reading

Configure website on 000WebHost hosting provider and Google Domains.

Google Domains Configuration:

1: Login into Google Domains account.
Go to “Configure DNS” tab and add ns01.000webhost.com, ns02.000webhost.com as “custom name servers” as shown below.
Also add a “custom resource record” as below. The “Data” column should be the url of your website on 000WebHostApp.com

000WebHost Configuration:

Login into your 000WebHost account. In your website 000webhost panel, go to Set web address -> Add domain.
Enter your domain name and click Park domain

If your nameservers are pointed correctly to 000webhost nameservers, domain will show status Ready which means that is ready to link Website.
Click Manage -> Link website.

Website Admin configuration:
Login into your website \wp-admin. Go to Settings=>General. Update the “WordPress Address URL” and “Site Address URL” to your website’s url.

Continue Reading

Filter network requests when debugging.

When you are debugging, you would like to filter out the various requests so you can concentrate on what’s important eg: filter image or css file requests. Google has finally listened to the developer community and has added support for “negative filters” in Google Chrome-version 42.
Here is the text filter I use when debugging where the “-” sign before each file extension keyword filters the requests. The requests then do not show in the “Network” tab:

-png -svg -aspx -axd -jpg -css -ttf -js -gif -ico -woff2

When you are adding the text filter make sure that the “Regex” checkbox is unchecked.

You can further filter the requests by using the following supported keywords

eg:

-mime-type:image/png,-larger-than:20k,-domain:yoursite.com,-status-code:404
Continue Reading

Configure fiddler to not capture requests for certain domains

When you are debugging using fiddler, fiddler generally captures requests from all the domains. An easy way to not capture requests from certain domains is to use the build in “filters” tab in fiddler. Use the “Hide the following hosts” dropdown and key in the list of all the domains that you want to hide.

If you want more granular control then you can override the OnBeforeRequest method in Fiddler’s script using Fiddler’s Script Editor.

static function OnBeforeRequest(oSession: Session) {        
        if (
        	oSession.HostnameIs("www.google.com") || 
        	oSession.HostnameIs("inbox.google.com") || 
        	oSession.HostnameIs("13.client-channel.google.com") || 
        	oSession.HostnameIs("d.docs.live.net") || 
        	oSession.HostnameIs("slack.com") || 
        	oSession.HostnameIs("notifications.google.com") || 
        	oSession.HostnameIs("play.google.com") || 
        	oSession.HostnameIs("cello.client-channel.google.com") || 
        	oSession.HostnameIs("lp-push-server-777.lastpass.com") || 
        	oSession.HostnameIs("ssl.gstatic.com") || 
        	oSession.HostnameIs("clients4.google.com") || 
        	oSession.HostnameIs("clients1.google.com")
        )
        {  
            oSession["ui-hide"] = "hidden";    
        }
        //code omitted for brevity
}
Continue Reading

Access Team Foundation Server Source Control from Windows Explorer

I lot of times when I search for a file in Agent Ransack and I want to check who made the last change in TFS source control, I have to switch to Visual studio and check the history for that file in TFS source control. An easier way to do this is to install Microsoft Visual Studio Team Foundation Server Power tools. Microsoft Visual Studio Team Foundation Server Power tools provides integration between windows explorer and TFS source control. Please see the screenshots below.

 

 

 

 

Continue Reading