In previous articles Get enumeration items as a list in C# and Populate dropdown with enumeration items in ASP.NET Core we that saw how to get enumeration items as a collection to bind it to data controls like dropdown etc.
In this article we will see that how can we get the description given as an attribute with an item. We may need this information on various places, say we have listing of users and we need to show each user’s status but in a descriptive way.

Here is our example enumeration:

  enum UserStatus
    {
        [Description("Pending Verification")]
        PendingVerification = 1,
        [Description("Pending Admin Approval")]
        PendingAdminApproval = 2,
        [Description("Active")]
     
 ...  read more

We can bind a dropdown with enumeration items without creating a look up table.

In Get enumeration items as a list in C# article we saw that how we can get enumeration items as a list to bind it to a data control.

Here is the enumeration we have been working with:

 enum UserStatus
    {
        [Description("Pending Verification")]
        PendingVerification = 1,
        [Description("Pending Admin Approval")]
        PendingAdminApproval = 2,
        [Description("Active")]
      
 ...  read more

Sometime we need to get enumeration items as a list to bind it to some data controls like drop downs.

Here is how we can do that. Suppose we have following enumeration:

 enum UserStatus
    {
        PendingVerification = 1,
        PendingAdminApproval = 2,
        Active = 3,
        BlockedByAdmin = 4
    }

We want to bind a dropdown on manage users page with these items. As you know dropdown have two properties for each item, one to handle display value and the other to handle backend value.

Using the current definition of enumeration we can use the name of enumeration item as display property and underlying integer value as backend value but it will not look good as there will be no space between words like PendingVerification. It will be more readable if it is Pending Verification.

So let’s add Description attribute to the enumeration items. Updated enumeration will look like this:

    enum UserStatus
    {
        [Description("Pending Verification")]
        PendingVerification
 ...  read more

While developing Angular applications in Visual Studio 2019 & Visual Studio Code following compile time error is shown:

TS1219 Experimental support for decorators is a feature that is subject to change in a future release. Specify ‘–experimentalDecorators’ to remove this warning.

Visual Studio Fix:

I am using Visual Studio 2019 and fixed the issue in it, it might work in other versions as well.

Add the following lines in .csproj file:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">    
    <TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
    <TypeScriptEmitDecoratorMetadata>True</TypeScriptEmitDecoratorMetadata>
 ...  read more

Microsoft Office 365 will no more support to connect using TLS1.0 and TLS1.1, please read it here.

All the browser-server or client-server applications must use TLS1.2 or later to be able communicate with Office 365 services.

Here is how we can implement it in C# to connect using TLS1.2, put the following line of code either in the constructor of the class which you are using to communicate with the Office 365 services or in the method directly:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;          

As more and more service providers like PayPal and others or switching to support TLS1.2 only, you can put above line of code before calling any web service or API which supports TLS1.2 only.

If your service provider supports more than one security protocol you can mention it like below:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

If you are using .NET Framework version older than 4.5 then use the following code:

System.Net.ServicePointManager.SecurityProtocol
 ...  read more

ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of adding real-time web functionality to applications. Real-time web functionality is the ability to have server code push content to connected clients instantly as it becomes available, rather than having the server wait for a client to request new data – Microsoft

Normally server sends notifications to clients when communication is initiated by some client but there are situations when we want server to push data to clients even there is no request from any clients.
Here is step by step procedure to do so.

[the_ad id=”181″]

Step 1
Add hub class, right click (on the App_Code in case of website project or appropriate folder in case of web application project), select Add and then Add New Item. Select the SignalR Hub Class template, give it a name say BroadcasterHub and click Add.
Your class should look like below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

[HubName("mainBroadcasterHub")]
public class BroadcasterHub : Hub {
 ...  read more