301 Redirect Non WWW to WWW Using Web.config in ASP.Net

Friends,

Whenever we host a domain on server, we are able to access the webpage from http://www.mydomain.com as well as http://domain.com. For SEO purposes, this is not good as Google and other search engines penalises the website as duplicate content. To resolve this, we can redirect the non-www domain to www domain.  In this post, we will see how can we do a “301 Redirect of a non WWW domain to WWW domain using web.config file in ASP.Net”.

To redirect mydomain.com to www.mydomain.com, edit your web.config file and add the below segment under the <system.webserver> section. Ensure you modify the words “mydomain.com” with your appropriate domain name.

<rewrite>
      <rules>
            <rule name="Redirect http://mydomain.com to http://www.mydomain.com HTTP" patternSyntax="ECMAScript" stopProcessing="true">
          <match url=".*"></match>
          <conditions>
            <add input="{HTTP_HOST}" pattern="^mydomain.com$"></add>
            <add input="{HTTPS}" pattern="off"></add>
          </conditions>
          <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" appendQueryString="true"></action>
        </rule>
      </rules>
    </rewrite>

Hope you like this. Keep learning and sharing. :)

Keyboard Shortcuts in Windows 10

Friends,

Windows 10 has been launched and it is running on over 70 million devices as when the post is being written. This post lists many new keyboard shortcuts that have been included in Windows 10 and also the ones that pre-exist on Windows devices.

New Keyboard Shortcuts in Windows 10

  • WIN + A : Open Action Center
  • WIN + G : Open Game Bar
  • WIN + I : Open Settings “Trusted Windows Store” App
  • WIN + Q : Search using voice in Cortana
  • WIN + S : Search using text in Cortana
  • WIN + X : Open Context menu associated with Start button
  • WIN + Print Screen : Capture Screenshot of current window and save it in Pictures folder
  • WIN + Ctrl + D : Create new Virtual Desktop
  • WIN + Ctrl + Left / WIN + Ctrl + Right : Switch between Virtual Desktops
  • WIN + Ctrl + F4 : Close Current Virtual Desktop
  • WIN + TAB : Open Task View
  • WIN + Left Key / WIN + Right Key : Snap Windows to Left/Right
  • WIN + Up Key / WIN + Down Key : Snap Windows to Up/Down

Existing Keyboard shortcuts in Windows 10

  • WIN + B : Show Hidden Icons in Taskbar
  • WIN + D : Show Desktop
  • WIN + E : File Explorer
  • WIN + H : Open Share Bar
  • WIN + K : Open Connect Bar
  • WIN + L : Lock User
  • WIN + P : Project Screen
  • WIN + R : Open Run Box

Hope the shortcuts help you 😉 Keep learning and sharing.

Solution: No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’

Friends,

In this post we will see the solution to a common problem when we use Entity Framework in our project. The error message is as below –

Schema specified is not valid. Errors:
XYZ.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’. Make sure the provider is registered in the ‘entityFramework’ section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

This error occurs because the project code tries to use Entity Framework while no reference has been made to Entity Framework in the project. To resolve this error, we need to add reference to “Entity Framework” to the project. You can install EF using Nuget package manager. In order to check how this can be done, check this article.

Hope this post helps you. Keep learning and sharing. :)

Get .Net Framework version of a DLL it was created with

Friends,

Microsoft has been updating .Net Framework versions from a long time and we’ve updated from .Net 1.0 to 4.6. We all love writing small wrappers and convert them into DLLs so that we can reuse the same code in different projects. In this post, we will see how can we get the .Net Framework version from which a specific DLL was created on.

To know this, we will make use of PowerShell. So, start PowerShell and write the following command on the prompt

[Reflection.Assembly]::ReflectionOnlyLoadFrom("C:\SomeTest.dll").ImageRuntimeVersion

The above snippet will display the .Net framework version. You can see it in the display below –

powershell

Have fun finding the .Net framework versions your DLL were built on.

Hope you like this. Keep learning and sharing :)

 

Show or Hide Favorites bar in Microsoft Edge

Friends,

Windows 10 is here and undoubtedly, it is one of the best Windows launched so far. Windows 10 comes with a brand new browser name “Microsoft Edge” and in this post, we will see how to show/hide Favorites bar in Microsoft Edge. I have already made Edge as my default browser.

By default Edge browser does not show the “Favorites” bar and we always like to access our mostly used websites in single click from the Bookmarks bar. To display the Favorites bar, we need to perform the following actions –

  • Under More actions on the Address bar, click Settingsedge-favorites-1
  • Turn on the “Show the favorites bar” optionedge-favorites-2

Hope this tip helps you. Keep learning and sharing.

List Videos From a Channel using YouTube API V3 in C#

Friends,

Google has retired YouTube API V2 and trying to fetch videos using the API V2 returns an error as “410 Gone Away“. In this post, we will see how can we retrieve all videos from a specific YouTube Channel using the latest YouTube API V3.

Let’s get started creating the application.

  • We create a new Stand alone application named “YouTubeVideos” and install the Nuget package named “Google.Apis.YouTube.V3” to the application. In case you’re unaware of installing Nuget packages to your application, check it out here.

youtube-1

youtube-2

  • Once the project gets created, “Select the project” and go to “APIs & Auth” > “Credentials” from the left sidebar.

youtube-3

  • If you just want to retrieve videos, you can go ahead and click on “Create new Key” under Public API access. However, if you want to use oAuth to validate user credentials before showing them videos, you need to create Client ID. For this example, we will be using “Public API access”.
  • After the key is created, copy the key in a notepad file.
  • Coming back to the application, below is the complete code —
using System;
using Google.Apis.YouTube.v3;
using Google.Apis.Services;

namespace YoutubeVideos
{
    class Program
    {
        static void Main(string[] args)
        {
            YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "YOUR_API_KEY" });


            var searchListRequest = yt.Search.List("snippet");
            searchListRequest.ChannelId = "YOUR_CHANNEL_ID";
            var searchListResult = searchListRequest.Execute();
            foreach (var item in searchListResult.Items)
            {
                Console.WriteLine("ID:" + item.Id.VideoId);
                Console.WriteLine("snippet:" + item.Snippet.Title);
            }
        }
    }
}

The above code will list the VideoID and Title of the videos present in your channel.

I hope this article helped you in retrieving YouTube videos from your channel. Let me know in case you have any other way of doing so or need any help.

Presented on Azure Websites in C# Corner Kolkata Chapter

This Sunday on 28th June, 2015 I presented on “Azure Websites” for C# Corner Kolkata Chapter’s event -“A Day With Azure” at Microsoft Office, Kolkata. In spite of heavy rain, the audience made it to the venue to learn about Azure. IN this session, I discussed about the following topics –

  • Hosting your application in Azure – Different Offerings by Microsoft
  • Azure Websites
  • Understanding Authentication
  • Web Hosting Plans
  • Deploy to Websites via Various options
  • Configuring Azure Websites

Here are the slides for the presentation –

azure-certificate

It was an amazing experience interacting with the attendees and I personally had a lot of fun presenting. I hope to speak more in the upcoming events.

azure-group