European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: What Is SSL Or TLS?

clock January 15, 2019 10:10 by author Peter

Many people are using these terms interchangeably. But the correct term is TLS. Well, let us understand what this TLS is and why we really need it.
 
Most of us are already aware that HTTP is a plain text protocol which doesn’t have its own transport security mechanisms. In other words, HTTP is a protocol which sends the data to a server and gets a response without any built-in feature or mechanism to protect the data packet against tampering.
 
To protect our packet which is traveling through HTTP, some sort of secure tunneling is required and that secure tunneling is provided by a protocol called TLS, a.k.a., SSL. Here, HTTP and TLS come together.
 
Usually, people associate SSL/TLS with encryption, but that is not the only feature SSL provides. There are a few more features, such as -
  • Server Authentication – It makes sure that the communication with the right server is made.
  • Veracity Protection – It promotes integrity and makes sure that no one in between is reading our data.
  • Confidentiality – It makes sure that no one should know what data is being transmitted.
Associating the above features with HTTP makes HTTPS more reliable and authentic. Now, the question arises --  how to achieve this or how to implement this SSL. Wait for my next blog to learn more about SSL certificates.

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: How To Serialize Nonstandard Enum Values?

clock January 7, 2019 11:35 by author Peter

Introduction
.NET client libraries that integrate with third-party APIs occasionally need to compromise on how enum values are represented in model classes. For example, an API that requires values to be expressed in all uppercase letters force the creation of an enum similar to:

public enum YesNoMaybeEnum  
 {  
     YES,  
     NO,  
     MAYBE   
 }  


While this will compile, it violates .NET naming conventions. In other cases, the third party may include names that include invalid characters like dashes or periods. For example, Amazon's Alexa messages include a list of potential request types that include a period in the names. These values cannot be expressed as enumation names. While this could be addressed by changing the data type of the serialized property from an enumeration to a string, the property values are no longer constrained and any suggestions from Intellisense are lost.

This article demonstrates how to eat your cake and have it, too. Using attributes and reflection, values can be serialized to and deserialized from JSON.

Serialization with EnumDescription
Let's say we need to serialize values that include periods. Creating an enum like the following generates compile time errors,

public enum RequestTypeEnum  
{  
    LaunchRequest,  
    IntentRequest,  
    SessionEndedRequest,  
    CanFulfillIntentRequest,  
    AlexaSkillEvent.SkillPermissionAccepted,  
    AlexaSkillEvent.SkillAccountLinked,  
    AlexaSkillEvent.SkillEnabled,  
    AlexaSkillEvent.SkillDisabled,  
    AlexaSkillEvent.SkillPermissionChanged,  
    Messaging.MessageReceived  
}  

The EnumMember attribute defines the value to serialize when dealing with data contracts. Samples on Stack Overflow that show enumeration serialization tend to use the Description attribute. Either attribute can be used or you can create your own. The EnumMember attribute is more tightly bound to data contract serialization while the Description attribute is for use with design time and runtime environments, the serialization approach in this article opts for the EnumMember. After applying the EnumMember and Data Contract attributes, the enum now looks like,

[DataContract(Name = "RequestType")]    
public enum RequestTypeEnum    
{    
    [EnumMember(Value = "LaunchRequest")]    
    LaunchRequest,    
    [EnumMember(Value = "IntentRequest")]    
    IntentRequest,    
    [EnumMember(Value = "SessionEndedRequest")]    
    SessionEndedRequest,    
    [EnumMember(Value = "CanFulfillIntentRequest")]    
    CanFulfillIntentRequest,    
    [EnumMember(Value = "AlexaSkillEvent.SkillPermissionAccepted")]    
    SkillPermissionAccepted,    
    [EnumMember(Value = "AlexaSkillEvent.SkillAccountLinked")]    
    SkillAccountLinked,    
    [EnumMember(Value = "AlexaSkillEvent.SkillEnabled")]    
    SkillEnabled,    
    [EnumMember(Value = "AlexaSkillEvent.SkillDisabled")]    
    SkillDisabled,    
    [EnumMember(Value = "AlexaSkillEvent.SkillPermissionChanged")]    
    SkillPermissionChanged,    
    [EnumMember(Value = "Messaging.MessageReceived")]    
    MessageReceived    
}    

The EnumMember attribute is also applied to enum members without periods. Otherwise, the DataContractSerilizer would serializes the numeric representation of the enumeration value. Now we can define a DataContract with,
[DataContract]  
public class SamplePoco  
{  
    [DataMember]  
    public RequestTypeEnum RequestType { get; set; }  
}
 

And serialize it to XML with,
SamplePoco enumPoco = new SamplePoco();  
enumPoco.RequestType = RequestTypeEnum.SkillDisabled;  
DataContractSerializer serializer = new DataContractSerializer(typeof(SamplePoco));  
 
var output = new StringBuilder();  
using (var xmlWriter = XmlWriter.Create(output))  
{  
    serializer.WriteObject(xmlWriter, enumPoco);  
    xmlWriter.Close();  
}  
string xmlOut = output.ToString();   


This generates the following XML,
<?xml version="1.0" encoding="utf-16"?><SamplePoco xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/EnumSerializationSample"><RequestType>AlexaSkillEvent.SkillDisabled</RequestType>  
</SamplePoco>  


DataContract serialization is sorted out, but doesn't yet address JSON serialization.

JSON Serialization

If you need to work with any REST API endpoints, then you'll need to support JSON. The NewtonSoft JSON has its own serialization strategy, and so the EnumMember attribute needs to be leveraged to integrate with it using a custom JsonConverter, but before taking that step, the enumation value must be read from the attribute.

This method accepts an enum value and returns the string value in the EnumMember attribute.
private string GetDescriptionFromEnumValue(Enum value)  
        {  
 
#if NETSTANDARD2_0  
            EnumMemberAttribute attribute = value.GetType()  
                .GetField(value.ToString())  
                .GetCustomAttributes(typeof(EnumMemberAttribute), false)  
                .SingleOrDefault() as EnumMemberAttribute;  
 
            return attribute == null ? value.ToString() : attribute.Value;  
#endif  
 
#if NETSTANDARD1_6 || NETSTANDARD1_3 || NET45 || NET47  
 
            EnumMemberAttribute attribute = value.GetType()  
                .GetRuntimeField(value.ToString())  
                .GetCustomAttributes(typeof(EnumMemberAttribute), false)  
                .SingleOrDefault() as EnumMemberAttribute;  
 
            return attribute == null ? value.ToString() : attribute.Value;  
            
#endif  
              throw new NotImplementedException("Unsupported version of .NET in use");  
        }  


There's a subtle difference between the .NET Standard 2.0 implementation and the others. In .NET Standard 1.6 and prior versions, use the GetRuntimeField method to get a property from a type. In .NET Standard 2.0, use the GetField method to return the property of a type. The compile-time constants and checks in the GetDescriptionFromEnumValue abstract away that complexity.  

Coming the other way, a method needs to take a string and convert it to the associated enumeration.
public T GetEnumValue(string enumMemberText)   
{  
 
    T retVal = default(T);  
 
    if (Enum.TryParse<T>(enumMemberText, out retVal))  
        return retVal;  
 
      var enumVals = Enum.GetValues(typeof(T)).Cast<T>();  
 
    Dictionary<string, T> enumMemberNameMappings = new Dictionary<string, T>();  
 
    foreach (T enumVal in enumVals)  
    {  
        string enumMember = enumVal.GetDescriptionFromEnumValue();  
        enumMemberNameMappings.Add(enumMember, enumVal);  
    }  
 
    if (enumMemberNameMappings.ContainsKey(enumMemberText))  
    {  
        retVal = enumMemberNameMappings[enumMemberText];  
    }  
    else  
        throw new SerializationException($"Could not resolve value {enumMemberText} in enum {typeof(T).FullName}");  
 
    return retVal;  
}  

The values expressed in the EnumMember attributes are loaded into a dictionary. The value of the attribute serves as the key and the associated enum is the value. The dictionary keys are compared to the string value passed to the parameter and if a matching EnumMember value is found, then the related enum is returned and so "AlexaSkillEvent.Enabled" returns RequestTypeEnum.SkillEnabled.
Using this method in a JSON Converter, the WriteJson method looks like the following,
public class JsonEnumConverter<T> : JsonConverter where T : struct, Enum, IComparable, IConvertible, IFormattable
{  
 
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)  
    {  
        if (value != null)  
        {  
            Enum sourceEnum = value as Enum;  
 
            if (sourceEnum != null)    
            {  

                string enumText = GetDescriptionFromEnumValue(sourceEnum);  
                writer.WriteValue(enumText);  
            }  
        }  
    }  


Please note that an enum constraint is applied to the generic type class declaration. This wasn't possible until C# version 7.3. If you cannot upgrade to use C# version 7.3, just remove this constraint.

The corresponding ReadJson method is,
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)  
{  
      object val = reader.Value;  
      if (val != null)  
    {  
        var enumString = (string)reader.Value;  
          return GetEnumValue(enumString);  
    }  
      return null;  
}  


Now the class definition needs to apply the JsonConverter class to the RequestType property,
[DataContract]  
public class SamplePoco  
{  
    [DataMember]  
    [JsonConverter(typeof(JsonEnumConverter<RequestTypeEnum>))]  
    public RequestTypeEnum RequestType { get; set; }  
 
 

Finally, the SamplePoco class is serialized to JSON,
SamplePoco enumPoco = new SamplePoco();  
enumPoco.RequestType = RequestTypeEnum.SkillEnabled;  
string samplePocoText = JsonConvert.SerializeObject(enumPoco);  
This generates the following JSON,
{  
"RequestType":"AlexaSkillEvent.SkillEnabled"  
}  

And deserialing the JSON yields the RequestTypeEnum.SkillEnabled value on the sample class.

string jsonText = "{\"RequestType\":\"AlexaSkillEvent.SkillEnabled\"}";  
SamplePoco sample = JsonConvert.DeserializeObject<SamplePoco>(jsonText); 

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: Handling Multiple Instances Of Caching Providers Using EasyCaching

clock December 18, 2018 10:09 by author Peter

Most of the time, we may use one type of caching in our projects, such as Redis or InMemory etc. However, we may often need two or three types of caching depending on the requirement of our project. In this article, I will show you how to solve this problem of multiple caching needs by using EasyCahing with ASP.NET Core. For more information about EasyCaching, you can follow my past articles about it or visit its GitHub page. Now, let's begin.

Solution
We are using IEasyCachingProviderFactory to get the caching providers that you want to use. We shall install the latest version (this time, it is v0.4.0) of EasyCaching here because it incorporates the new features of EasyCaching. Add InMemory and Redis - the two providers into your project.
    dotnet add package EasyCaching.Redis --version 0.4.0 
    dotnet add package EasyCaching.InMemory --version 0.4.0 


Before we use it, we need to configure it in the Startup class. Here, we will use two types of caching providers with three instances - one in-memory caching provider and two Redis caching providers.
    public void ConfigureServices(IServiceCollection services) 
    { 
        //other ..     
        //configure the in-memory caching provider 
        services.AddDefaultInMemoryCacheWithFactory("inmemory"); 
     
        //configure the first redis caching provider 
        services.AddDefaultRedisCacheWithFactory("redis1",option => 
        { 
            option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379)); 
        }); 
     
        //configure the second redis caching provider 
        services.AddDefaultRedisCacheWithFactory("redis2", option => 
        { 
            option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6380)); 
        }); 
    } 


Note
Here, we used AddDefaultInMemoryCacheWithFactory and AddDefaultRedisCacheWithFactory to replace the AddDefaultInMemoryCache and AddDefaultRedisCache respectively.This is an important step to deal with factory.
 
After configuring the factory, we can use it via dependency injection where we need to use. For example, the following code shows how to use IEasyCachingProviderFactory in the controller.
    [Route("api/[controller]")] 
    public class ValuesController : Controller 
    { 
        private readonly IEasyCachingProviderFactory _factory; 
     
        public ValuesController(IEasyCachingProviderFactory factory) 
        { 
            this._factory = factory; 
        } 
     
        // GET api/values/inmem 
        [HttpGet] 
        [Route("inmem")] 
        public string GetInMemory() 
        { 
            var provider = _factory.GetCachingProvider("inmemory"); 
            var val = $"memory-{Guid.NewGuid()}"; 
            var res = provider.Get("named-provider", () => val, TimeSpan.FromMinutes(1)); 
            Console.WriteLine($"Type=InMemory,Key=named-provider,Value={res},Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); 
            return $"cached value : {res}";                
        } 
     
        // GET api/values/redis1 
        [HttpGet] 
        [Route("redis1")] 
        public string GetRedis1() 
        { 
            var provider = _factory.GetCachingProvider("redis1"); 
            var val =  $"redis1-{Guid.NewGuid()}"; 
            var res = provider.Get("named-provider", () => val, TimeSpan.FromMinutes(1)); 
            Console.WriteLine($"Type=redis1,Key=named-provider,Value={res},Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); 
            return $"cached value : {res}"; 
        } 
         
        // GET api/values/redis2 
        [HttpGet] 
        [Route("redis2")] 
        public string GetRedis2() 
        { 
            var provider = _factory.GetCachingProvider("redis2"); 
            var val =  $"redis2-{Guid.NewGuid()}"; 
            var res = provider.Get("named-provider", () => val, TimeSpan.FromMinutes(1)); 
            Console.WriteLine($"Type=redis2,Key=named-provider,Value={res},Time:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); 
            return $"cached value : {res}"; 
        } 
    } 

GetCachingProvider is the key method to get the registered caching providers via their name. This name must be the same as what we registered in the configuration. If we pass a not registered or not existed caching provider name to this method, it will throw an exception with a message to tell us that it can not find a matching caching provider!
 
Now, let's take a look at the result when we visit those three APIs.

Using EasyCaching To Handle Multiple Instance Of Caching Providers. We visited http://localhost:9999/api/values/inmem, http://localhost:9999/api/values/redis1, and http://localhost:9999/api/values/redis2 one by one. The first time, all the cached values will be initialized.
The second time, all the cached values were the same as the first time because they're still valid. The third time, after the expiration, all the cached values were changed!
 
The result tells us that all the caching providers will not affect others. In this article, I showed you how to handle multiple instances of caching providers when using EasyCaching in your ASP.NET Core project! The way to get a caching provider is similar to creating a new instance of HttpClient via HttpClientFactory.

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

 



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: The Common Language Runtime Of Microsoft’s .Net Framework

clock December 5, 2018 10:02 by author Peter

The CLR is a runtime environment of .NET to execute applications. The major function of the CLR is converting the Managed Code to native code and executing the program. Furthermore, it acts as a layer between operating systems and apps that are written in .NET languages. The common language runtime handles execution of code as well as provides useful services for implementing the program. Aside from code execution, the CLR also provides services like memory management, security management, thread management, compilation, code verification, and other system services.

CLR is due for a makeover
The common language runtime of Microsoft is due for a makeover with Microsoft announcing plans to make it more scalable and efficient. The key to the modernization would be enhancements on the intermediate language underlying the CRL, called IL, that has not been upgraded in a decade. Microsoft wants to boost the IL as well as make the CLR a richer target for programming languages. The aim of the common language runtime is to run .NET programs in an efficient manner.

One imminent enhancement includes Span<T>, pronounced ‘span of tee’. It’s a new kind that would offer framework and language features to achieve more performing, safer, low-level code. The T in Span<T> means type parameter. It would be used by C# as well as other languages to build more efficient code, which does not require copying big amounts of data or pause for garbage collection. New CRL versions would have ‘inside knowledge’ regarding Span<T> to boost speed. It will be rolled out in the next few releases of .NET.

Serving as the counterpart of Microsoft to the JVM of the world of Java, the common language runtime provides management of code of .NET languages, which include Visual Basic, C# and F#. The source code is compiled by the language compilers to the IL code. The CLR tunes the program through the execution of the IL and translating output into a machine code while the program runs. Other services are provided by the common language runtime include automatic management of memory and type safety, saving .NET programmers from providing the services.

THE ROLE OF THE COMMON LANGUAGE RUNTIME IN THE DOT NET FRAMEWORK
  1. Base Class libraries
    Provides class libraries support to an app when required.
  2. Thread support
    Threads are managed under the CLR. Threading means the parallel execution of code. Basically, threads are lightweight processes that are responsible for multi-tasking in a single app.
  3. MSIL code to native code
    The CLR is an engine that compiles the source code to an intermediate language. The intermediate language’s called the Microsoft Intermediate Language. During program execution, the MSIL’s converted to the native code of the machine code. The conversion is possible via the Just-In-Time compiler. At compilation, the end result is the PE or the Portable Executable file.
  4. Code Manager
    The common language runtime manages code. When compiling a .NET app, one does not generate code that could actually execute on the machine. The MSIL or the Microsoft Intermediate Language or IL could actually be generated. All code of .NET is IL code. The IL code is also called the Managed Code since the CLR of.NET manages it.
  5. COM Marshaler
    It enables communication between the app and COM objects.
  6. CLS or Common Language Specification
    It is used to communicate objects that are written in various .NET languages. It defines the standards and rules to which languages should adhere to in order to be compatible with the other languages of .NET. This lets C# developers to inherit from classes, which are defined in VB.NET or other compatible languages of .NET.
  7. Debug Engine
    The CLR enables performing debugging an app during runtime.
  8. Type Checker
    It verifies the types used in the app with CLS or CTS standards that are supported by the common language runtime and provides type safety.
  9. CTS or the Common Type System
    It specifies types of data that are created in a couple of different languages compiled into the base common data type system.
  10. Security Engine
    This enforces security permission at code level security, machine level security and folder level security with the use of .NET framework setting and tools provided by .NET.
  11. Exception Manager
    It handles exceptions thrown by an app while executing Try-catch block that is provided by an exception. In ‘Try’ block used where a code part expects an error. In ‘Catch’ block throws exception caught from the ‘try’ block. If there’s no catch block, it would terminate an app.
  12. Garbage Collector
    The Garbage Collectors handles automatic memory management. Furthermore, it releases memory of unused objects in an app that provides automatic memory management.
Hire ASP.NET developers from India for maximum results and solutions. With the improvements set to boost the .NET’s CLR, applications, and solutions are more effective and streamlined.

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: Assembly Attributes

clock November 27, 2018 10:01 by author Peter

I have listed down some of the assembly attributes.

    [assembly: AssemblyKeyFile(@"key.snk")] 
    [assembly: InternalsVisibleTo("System.Numerics, PublicKey=00000000000000000400000000000000", AllInternalsVisible=false)] 
    [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] 
    [assembly: AssemblyDelaySign(true)] 
    [assembly: InternalsVisibleTo("System, PublicKey=00000000000000000400000000000000", AllInternalsVisible=false)] 
    [assembly: InternalsVisibleTo("System.Core, PublicKey=00000000000000000400000000000000", AllInternalsVisible=false)] 
    [assembly: AllowPartiallyTrustedCallers] 
    [assembly: NeutralResourcesLanguage("en-US")] 
    [assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)] 
    [assembly: Guid("BED7F4EA-1A96-11d2-8F08-00A0C9A6186D")] 
    [assembly: ComCompatibleVersion(1, 0, 0xce4, 0)] 
    [assembly: TypeLibVersion(2, 4)] 
    [assembly: DefaultDependency(LoadHint.Always)] 
    [assembly: StringFreezing] 
    [assembly: ComVisible(false)] 
    [assembly: CLSCompliant(true)] 
    [assembly: CompilationRelaxations(8)] 
    [assembly: SecurityRules(SecurityRuleSet.Level2, SkipVerificationInFullTrust=true)] 
    [assembly: AssemblyTitle("sample.dll")] 
    [assembly: AssemblyDescription("sample.dll")] 
    [assembly: AssemblyDefaultAlias("sample.dll")] 
    [assembly: AssemblyCompany("Microsoft Corporation")] 
    [assembly: AssemblyProduct("Microsoft\x00ae .NET Framework")] 
    [assembly: AssemblyCopyright("\x00a9 Microsoft Corporation.  All rights reserved.")] 
    [assembly: AssemblyFileVersion("4.0.30319.225")] 
    [assembly: AssemblyInformationalVersion("4.0.30319.225")] 
    [assembly: SatelliteContractVersion("4.0.0.0")] 
    [assembly: AssemblyTargetedPatchBand("1.0.21-102")] 
    [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification=true)] 

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: Firebase Cloud Messaging From .Net

clock November 22, 2018 10:05 by author Peter

In developing mobile web backends you might need users to broadcast messages such as push notifications to single or all  mobile subscribers from the cloud using services like Firebase Cloud Messaging (FCM).
 
In this article we will focus on sending push notifications from a .Net application using Firebase.Notification library. This library makes it very easy to send push notifications from Firebase using C#
 
To begin, download the library from Nuget:
    Install-Package Firebase.Notification -Version 1.0.0 

Using the library:
    using (var firebase = new Firebase()) 
    { 
        firebase.ServerKey = "{Your Server Key}"; 
        var id = "{Your Device Id}"; 
        firebase.PushNotifyAsync(id,"Hello","World").Wait(); 
        Console.ReadLine(); 
    }        


Error Handling and Debugging
Trace errors in your output window, all errors from this library will be captured under the category Firebase.Notification for easy debugging,

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

 



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: How .NET Is A Multilingual Framework?

clock November 13, 2018 08:18 by author Peter

An application is said to be multilingual if it can be deployed in many different languages. With .NET, all of the languages including Visual Basic, .NET, C#, and J# compile to a common Intermediate language (IL). This makes all languages interoperable. Microsoft has created Java bytecode, which is a low-level language with a simple syntax, which can be very quickly translated into native machine code.

CLR
.NET Framework is a multilingual application because of CLR.CLR is the key of .NET Framework. The code running under the control of the CLR is often termed as managed code.The main task of CLR is to convert compiled code into the native code. .NET Framework has one or more compilers; for e.g., VB .NET, C#, C++, JScript or any third party compiler such as COBOL.

Anyone of these compilers will convert your source code into Microsoft Intermediate Language (MSIL). The main reason for .NET to be multilingual is that you can compile your code from IL and this compiled code will be interoperable with the code that has been compiled to IL from another language.

It simply means that you can create pages in different languages (like C#, VB .NET, J# etc.) and once all of these pages are compiled they all can be used in a single application. Let us understand this point clearly with an example.

Let us consider a situation where a customer needs an application to be ready in 20 days. For completing the application in 20 days we want 30 developers who all know the specific language but we have 15 developers who know C# and 15 developers who know VB .NET. In this situation, if we don’t use .NET then we need to hire 15 more developers of C# or VB .NET which is a difficult and costly solution. Now, if we use .NET then we can use C# and VB .NET language in the same application. This is possible because once C# code is compiled from IL it becomes interoperable with VB .NET code which is compiled from IL.


Then JIT (Just In Time) of CLR converts this MSIL code into native code using metadata which is then executed by OS.

CLR stands for common language runtime. Common language runtime provides other services like memory management, thread management, remoting, and other security such as CTS and CLS. CLR is a layer between an operating system and .NET language, which uses CTS and CLS to create code.

CTS
CTS stands for the common type system. CTS defines rules that common language runtime follows when we are declaring, using and managing type. CTS deals with the data type. .NET supports many languages and every language has its own data type. One language cannot understand data types of another language. For example: When we are creating an application in C#, we have int and when we are creating an application in VB .NET, we have an integer. Here CTS comes into play --  after the compilation, CTS converts int and integer into the int32 structure.

CLS
CLS stands for common language specification. CLS is a subset of CTS and it declares all the rules and restrictions that all languages under .NET Framework must follow. The language which follows these rules is known as CLS compliant. For example, we can use multiple inheritances in c++ but when we use the same code in C# it creates a problem because C# does not support multiple inheritances. Therefore, CLS restricts multiple inheritances for all language. One other rule is that you cannot have a member with the same name and a different case.

In C# add() and Add() are different because it is case sensitive but a problem arises when we use this code in VB .NET because it is not case-sensitive and it considers add() and Add() as the same.

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

 



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: QRCode with Footer Text

clock November 6, 2018 11:09 by author Peter

Recently, I was working with a library which helps to generate barcode within images, the open source library is called ZXing (http://zxingnet.codeplex.com/). Its a free library with lots of great features and even supports QRCode generation. The only missing feature I came across was of writing a Barcode Text below the generated image. I reached out ZXing support team, here they replied to my thread.
http://zxingnet.codeplex.com/discussions/452290

Implementing such functionality in an html page was not that a big task.

Anyway here I came up with a solution. Hope this helps you..
<div style="border: 1px double black;width:50%;text-align:center;" id="PrintBarcode"> 
<div><asp:Image ID="imgBarcode" runat="server" /></div> 
<div style="margin-top:-10px;"><asp:Label ID="lblTexttoDisplay" runat="server"></asp:Label></div> 
</div><br /> 
<a ID="PrintMe" runat="server" Text="Print" onclick=""></a> 
<script type="text/javascript"> 
function PrintMe() 
{    
var popupWin = window.open('', '_blank', 'width=0,height=0,directories=0,fullscreen=0,location=0,menubar=0, 
 
                     resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0'); 
popupWin.document.open(); 
var divToPrint = document.getElementById('PrintBarcode'); 
popupWin.document.write('<html><body onload="window.print();this.close();"> 
 
          <div style="border: 0px double black;width:50%;text-align:center;">' + divToPrint.innerHTML + '</div></html>'); 

</script> 

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

 



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: ASP.NET Core Sample Website - Calculator

clock November 1, 2018 08:36 by author Peter

In this article, I will be explaining how to create a simple Web Calculator using .NET Core.

What is ASP.NET Core and why do we use it?

  • Easy to develop Web Pages as well as Web APIs.
  • Integration of modern frameworks and development workflows.
  • Easy to integrate with Azure.
  • Natural dependency injection support.
  • Large hosting variety, like on IIS, Apache, Docker, or self-host in your own process.
  • A wide range of tools that simplifies web development.
  • Multi-platform, so you may build and run on Windows, macOS, and Linux.
  • Open-source and with a powerful community.

We are using a single controller with two Action Results - one for the first HttpGet and another to calculate the operation on the server side. Here is the code.
public class HomeController : Controller 

    [HttpGet] 
    public IActionResult Index() 
    { 
        return View(); 
    } 
 
    [HttpPost] 
    public IActionResult Index( Operation model ) 
    { 
        if ( model.OperationType == OperationType.Addition ) 
            model.Result = model.NumberA + model.NumberB; 
        return View( model ); 
    } 


This is the View,
@model Operation 
<form asp-controller="Home" asp-action="Index" method="post" > 
    <div class="form-group"> 
        <div class="row"> 
            <label asp-for="NumberA" class="col-lg-2"></label> 
            <input type="number" asp-for="NumberA" class="col-lg-2" /> 
        </div> 
        <div class="row"> 
            <label asp-for="NumberB" class="col-lg-2"></label> 
            <input type="number" asp-for="NumberB" class="col-lg-2" /> 
        </div> 
        <div class="row"> 
            <label asp-for="OperationType" class="col-lg-2"></label> 
            <select asp-for="OperationType" class="col-lg-2" asp-items="Html.GetEnumSelectList<OperationType>()"> 
                <option selected="selected" value="">Select</option> 
            </select> 
        </div> 
        <div class="row"> 
            <label asp-for="Result" class="col-lg-2"></label> 
            <input type="number" disabled="disabled" class="col-lg-2" asp-for="Result" /> 
        </div> 
        <div class="row"> 
            <input type="submit" value="Submit" asp-action="Index" /> 
        </div> 
    </div> 
</form> 


View Result in the browser.


This is the model used in here.

public class Operation 

    [Display( Name = "First Number" )] 
    public double NumberA { get; set; } 
 
    [Display( Name = "Second Number" )] 
    public double NumberB { get; set; } 
 
    [Display( Name = "Result" )] 
    public double Result { get; set; } 
 
    [Display( Name = "Operation" )] 
    public OperationType OperationType { get; set; } 


public enum OperationType 

    Addition, 
    Multiplication, 
    Division, 
    Subtraction 


Right now, only addition is implemented.

You can implement multiplication, division, and subtraction as well. I will publish these methods in my next article.

Congratulations, you have successfully created your Web Calculator using .NET Core.

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

 



ASP.NET Core 2.2.1 Hosting - HostForLIFE.eu :: Google Custom Searching In ASP.NET

clock October 23, 2018 11:28 by author Peter
In many huge contented websites it is very difficult to find some information like any link, page, text etc. So, they use a textbox where visitor types his keyword to search. There are couple of ways to create it like, to search the content from database, crawler. But if you don't have such things then we use Google Custom Search. In Google Custom Search, we create account in Google and provide the domain information to Google and then Google generates some codes which are used inside our web application. If we use the Google Custom Search codes in our application, then Google searches the content from your website. It is available in cost-free and paid also. In cost-free there will be some advertisement of Google.

Let's take a look how to create it.
 
Creating Account in Google Custom Search
 
To create Google Custom Search account use the following link
http://www.google.com/cse/

Click above link to create Google Custom Search.

At the end of this process you will receive some codes generated by Google and you have to keep it for use inside web application. Here is code given Google for my own domain hostforlife.eu.
<scriptsrc="http://www.gmodules.com/ig/ifr?url=http://www.google.com/cse/api/014464787619631746113/cse/67a_iw-duna/gadget&synd=open&w=250&h=100&title=hostforlife.eu+Search&border=%23ffffff%7C0px%2C1px+solid+%23998899%7C0px%2C1px+solid+%23aa99aa%7C0px%2C2px+solid+%23bbaabb%7C0px%2C2px+solid+%23ccbbcc&output=js"></script>  

And I have used it inside the <div> tag in web page, as shown below
<div>    
     <scriptsrcscriptsrc="http://www.gmodules.com/ig/ifr?url=http://www.google.com/cse/api/014464787619631746113/cse/67a_iw-duna/gadget&synd=open&w=250&h=100&title=hostforlife.eu+Search&border=%23ffffff%7C0px%2C1px+solid+%23998899%7C0px%2C1px+solid+%23aa99aa%7C0px%2C2px+solid+%23bbaabb%7C0px%2C2px+solid+%23ccbbcc&output=js"></script>    
  </div>   

HostForLIFE.eu ASP.NET Core 2.2.1 Hosting
European best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.

 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in