Monday, 1 June 2020

C# Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task'

 C# Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'



Hello Friends,


In this article, I will explain how to solve Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'


 C# Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>


In this week, I was working with one C# class where  I want to return a string from Task<string> but I was facing one error like "Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'".

Please find below solution 


Solution

We need to use Task.FromResult to return string from C#.

Please find below example

public async Task<string> GetString()
{ 
   return await Task.FromResult("Hello");
}

Hope this helped you to solve your error
Happy Programming!!
Don’t forget to leave your feedback and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com     
Happy programming!!
Don’t forget to leave your feedback and comments below!
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
------------------------------------------------------------------------------


Sunday, 31 May 2020

How to read a HTTP only cookie using JavaScript

Hello Friends,


In this article, I will explain how to read an HTTP only cookie using JavaScript

In the last week, I was working with one issue where we need to access HTTP only cookie using JavaScript. 




So the answer is No We can not access HTTP only cookies using javascript. HttpOnly cookie is that it's not accessible to client-side scripting,


What I did find on a website was:

"The big security hole, as alluded to above, is that Firefox (and presumably Opera) allow access to the headers through XMLHttpObject. So you could make a trivial JavaScript call back to the local server, get the headers out of the string, and then post that back to an external domain. Not as easy as document.cookie, but hardly a feat of software engineering.


 You could set a hidden variable or inline code with the cookie value when the server processes it



Don’t forget to leave your feedback and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com     
Happy programming!!
Don’t forget to leave your feedback and comments below!
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
------------------------------------------------------------------------------

Wednesday, 20 May 2020

Angular - CSS style not applying on angular directive

Hello Friends,


In this article, I will explain how to solve CSS style not applying on the angular directive 

In the last week, I was working with one directive where  CSS style was not applying on the angular directive 





Solution 1. Please add /deep/ to your CSS class 

Solution 2 We should use::ng-deep instead of /deep/ which seems to be deprecated.

Usually /deep/ “shadow-piercing” combinator can be used to force a style down to child components. We have another option called::ng-deep.

since /deep/ combinator has been deprecated, it is recommended to use::ng-deep

Please find the below example. This class will be applied to child component


Example
.overview {
    ::ng-deep {
        p {
            &:last-child {
                margin-bottom: 0;
            }
        }
    }
}

Hope this helped you to solve your error
Happy Programming!!
Don’t forget to leave your feedback and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com     
Happy programming!!
Don’t forget to leave your feedback and comments below!
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
------------------------------------------------------------------------------


Thursday, 23 April 2020

RxJs Pipe Operator


Introduction

RxJS is a framework for reactive programming that makes use of Observables, making it really easy to write asynchronous code.

Sujeet Bhujbal Angular




What is Pipe Operator

RxJS pipe is used to combine functional operators into a chain. 
pipe is an instance method of Observable as well as a standalone RxJS function.
 pipe can be used as Observable.pipe or we can use standalone pipe to combine functional operators.

 pipe accepts operators as arguments such as filtermapmergeScan etc. with comma separated and execute them in a sequence they are passed in as arguments and finally returns Observable instance.

 To get the result we need to subscribe the final Observable response. 


Please find the sample code below



of(1, 2, 3, 4, 5, 6, 7).pipe(
    filter(n => n % 2 === 1),
    map(n => n + 10)
)
.subscribe(result => console.log(result)); 

Output will be 11, 13, 15, 17.




Happy programming!!
Don’t forget to leave your feedback and comments below!



Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
------------------------------------------------------------------------------