<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Cory Harkins</title>
    <description>The latest articles on DEV Community by Cory Harkins (@charkinsdevelopment).</description>
    <link>https://dev.to/charkinsdevelopment</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F466926%2F19058834-0aa5-4103-aa7c-016e611bae9d.jpg</url>
      <title>DEV Community: Cory Harkins</title>
      <link>https://dev.to/charkinsdevelopment</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/charkinsdevelopment"/>
    <language>en</language>
    <item>
      <title>Cory’s Coding Tips</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Sun, 15 Oct 2023 01:31:27 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/corys-coding-tips-1989</link>
      <guid>https://dev.to/charkinsdevelopment/corys-coding-tips-1989</guid>
      <description>&lt;p&gt;Checking if an element has scrolled into view.&lt;/p&gt;

&lt;p&gt;I’ll keep this short and sweet because it took me a while to get this just right.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s the snippet&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let hasScrolledIntoView = (element) =&amp;gt; {
  const rect = element.getBoundingClientRect();
  return (rect.top &amp;lt; window.innerHeight &amp;amp;&amp;amp; rect.bottom &amp;gt;= 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What’s going on here?&lt;/strong&gt;&lt;br&gt;
We have a function that takes in an html element.&lt;br&gt;
We get the bounding rectangle.&lt;br&gt;
We return if the top position of the element is &amp;lt; the window’s inner height and the bottom position of the element is ≥ 0.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do I do with this?&lt;/strong&gt;&lt;br&gt;
Slap this function inside one of these on scroll babies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;addEventListener("scroll", (event) =&amp;gt; {
  hasScrolledIntoView(el);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure your &lt;code&gt;el&lt;/code&gt; variable is a thing.&lt;/p&gt;

&lt;p&gt;And you’re good to go!&lt;/p&gt;

&lt;p&gt;See ya next time!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do I want to use this?&lt;/strong&gt;&lt;br&gt;
I didn’t want to find a library to tell me this info and I didn’t want to do offset math.&lt;/p&gt;

&lt;p&gt;I originally posted this on medium, you can follow me there: &lt;br&gt;
&lt;a href="https://medium.com/p/8f92dcbd6b05"&gt;https://medium.com/p/8f92dcbd6b05&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Working with Collections in C# and Asp.net: A Comprehensive Guide</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Sun, 16 Jul 2023 18:42:49 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/working-with-collections-in-c-and-aspnet-a-comprehensive-guide-5fgf</link>
      <guid>https://dev.to/charkinsdevelopment/working-with-collections-in-c-and-aspnet-a-comprehensive-guide-5fgf</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RqP6iEqN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qpxjotk1q6e2w7vnzrb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RqP6iEqN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1qpxjotk1q6e2w7vnzrb.png" alt="Your computer’s memory trying to hold all your items in your collection." width="600" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this quick article we will learn how to effectively work with collections in C# and Asp.net.&lt;/p&gt;

&lt;p&gt;By the end of this guide you will discover the power of collection classes in C# and Asp.net. Enhance your programming skills and optimize your code with these versatile tools.&lt;/p&gt;

&lt;p&gt;With this knowledge you can take your Asp.net development to the next level with comprehensive insights into working with collection classes. Improve performance and efficiency.&lt;/p&gt;

&lt;p&gt;Introduction to Collections&lt;br&gt;
Collections play a vital role in C# and Asp.net programming by providing a way to store and manipulate groups of related data. Whether you need to manage a list of items, perform array operations, or maintain key-value pairs, understanding collections is essential. In this blog post, we will explore various collection classes and learn how to effectively work with them.&lt;/p&gt;

&lt;p&gt;Arrays in C#&lt;br&gt;
Arrays are a fundamental collection type in C#. They allow you to store multiple elements of the same type in a contiguous block of memory. To use arrays in C#, follow these steps:&lt;/p&gt;

&lt;p&gt;Declare an array with the desired type and size.&lt;br&gt;
Initialize the array with values if needed.&lt;br&gt;
Access individual elements using their index.&lt;br&gt;
Perform array operations like sorting, searching, or resizing.&lt;br&gt;
List Class in C#&lt;br&gt;
The List class in C# provides a dynamic array-like structure that allows for efficient insertion, deletion, and modification of elements. To utilize the List class, follow these steps:&lt;/p&gt;

&lt;p&gt;Create a new List object by specifying the type parameter.&lt;br&gt;
Add elements using the Add() method.&lt;br&gt;
Access and modify elements using their index.&lt;br&gt;
Utilize various methods like Remove(), Contains(), and Sort() for manipulation.&lt;br&gt;
Benefit from the flexibility and performance of List in a wide range of scenarios.&lt;br&gt;
Dictionary Class in C#&lt;br&gt;
The Dictionary class in C# enables efficient storage and retrieval of key-value pairs. To work with dictionaries in C#, follow these steps:&lt;/p&gt;

&lt;p&gt;Declare a new Dictionary object with the desired key and value types.&lt;br&gt;
Add key-value pairs using the Add() method.&lt;br&gt;
Access values using their corresponding keys.&lt;br&gt;
Update or remove entries using appropriate methods.&lt;br&gt;
Leverage the dictionary’s fast lookup capabilities for efficient data retrieval.&lt;br&gt;
Collection Classes in Asp.net&lt;br&gt;
Asp.net provides a set of collection classes that are specifically designed for web development. These classes include:&lt;/p&gt;

&lt;p&gt;ViewState: Stores state information that is associated with a specific page.&lt;br&gt;
Session: Maintains state information across multiple requests for a particular user.&lt;br&gt;
Cache: Caches data for efficient retrieval in subsequent requests.&lt;br&gt;
Application: Manages application-level data accessible across users and sessions.&lt;br&gt;
Iterating through Collections&lt;br&gt;
To process the elements of a collection in C#, you can use different techniques like loops or iterator methods. Follow these steps to iterate through a collection:&lt;/p&gt;

&lt;p&gt;Determine the appropriate iteration method based on the collection type.&lt;br&gt;
Use a loop (for, foreach) or iterator method (GetEnumerator()) to traverse the collection.&lt;br&gt;
Perform desired operations on each element during iteration.&lt;br&gt;
Handle any exceptions or edge cases that may arise.&lt;br&gt;
Conclusion&lt;br&gt;
Working with collections in C# and Asp.net is essential for efficient and organized programming. By understanding different collection classes, such as arrays, List, and Dictionary, developers can effectively manage data, improve code performance, and create robust applications. Remember to consider the specific requirements of your project when choosing the appropriate collection class. Explore further resources to deepen your knowledge and enhance your skills in working with collections.&lt;/p&gt;

&lt;p&gt;This structured blog post provides a comprehensive guide to working with collections in C# and Asp.net. It covers the concept of collections, array manipulation, List usage, Dictionary implementation, Asp.net collection classes, iterating through collections, and more. Apply the outlined steps to make the most of collections in your C# and Asp.net development journey.&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>aspnetco</category>
      <category>csharp</category>
      <category>programming</category>
    </item>
    <item>
      <title>Are you using the correct rest attributes?</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Fri, 23 Jun 2023 18:43:55 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/are-you-using-the-correct-rest-attributes-532d</link>
      <guid>https://dev.to/charkinsdevelopment/are-you-using-the-correct-rest-attributes-532d</guid>
      <description>&lt;p&gt;Hello 👋,&lt;/p&gt;

&lt;p&gt;Way back when in my early days of being a programmer, when working in full framework MVC, controller endpoints were just a means to an end. &lt;/p&gt;

&lt;p&gt;All the things were handled in house by our own systems so it wasn't necessarily crucial to provide the most accurate endpoints, just so long as the job got done we were all happy. &lt;/p&gt;

&lt;p&gt;That being said, everything was a [HttpGet] or an [HttpPost]. &lt;/p&gt;

&lt;p&gt;Needed data? Use a get.&lt;br&gt;
Creating data? Use a post.&lt;br&gt;
Updating? Post.&lt;br&gt;
Delete? Post.&lt;/p&gt;

&lt;p&gt;You get the picture. Gets and Posts everywhere all day long. &lt;/p&gt;

&lt;p&gt;But as I progressed in my career and curiosity I began to use other controller attributes such as Put and Delete. &lt;/p&gt;

&lt;p&gt;Not only did these help, at a glance, to see which method did what in spite of, good or bad, naming conventions; it also made consumption of these endpoints more understandable to front end engineers and external third parties. &lt;/p&gt;

&lt;p&gt;The added benefit of using these attributes is that no other targeted rest request type will be allowed to hit that endpoint.&lt;/p&gt;

&lt;p&gt;That being said I think it's crucial to know these rest request attributes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Http Get
&lt;/h2&gt;

&lt;p&gt;Attribute Usage: &lt;code&gt;[HttpGet]&lt;/code&gt;&lt;br&gt;
When To Use: When retrieving a collection of data, or a single item of data from some type of storage. &lt;/p&gt;

&lt;h2&gt;
  
  
  Http Post
&lt;/h2&gt;

&lt;p&gt;Attribute Usage: &lt;code&gt;[HttpPost]&lt;/code&gt;&lt;br&gt;
When To Use: When creating a new item to be added to a stored data location.&lt;/p&gt;

&lt;h2&gt;
  
  
  Http Patch
&lt;/h2&gt;

&lt;p&gt;Attribute Usage: &lt;code&gt;[HttpPatch]&lt;/code&gt;&lt;br&gt;
When To Use: When you want to override or update parts of some existing data or object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Http Put
&lt;/h2&gt;

&lt;p&gt;Attribute Usage: &lt;code&gt;[HttpPut]&lt;/code&gt;&lt;br&gt;
When To Use: When you want to completely override or change an entire piece of data or object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Http Delete
&lt;/h2&gt;

&lt;p&gt;Attribute Usage: &lt;code&gt;[HttpDelete]&lt;/code&gt;&lt;br&gt;
When To Use: When you want to delete an object.&lt;/p&gt;

&lt;p&gt;These may seem straight forward, but for me, Put vs Patch has always been one that I need to look up from time to time as they're used less often. &lt;/p&gt;

&lt;p&gt;I see misuse of these attributes (the biggest offender being Post to do all udpates, deletes, and creates.&lt;/p&gt;

&lt;p&gt;And no, the world won't collapse if you use Get and Post over the other options but; we should all strive to build better together and in the evermore connected world, we must make our intentions as clear as we can with our tools. &lt;/p&gt;

&lt;p&gt;Thanks everyone!&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>webdev</category>
      <category>rest</category>
      <category>api</category>
    </item>
    <item>
      <title>I Did My Own Small Benchmark. C# - List of Int vs Array of Int</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Sun, 07 Mar 2021 00:21:41 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/i-did-my-own-small-benchmark-c-list-of-int-vs-array-of-int-2kc</link>
      <guid>https://dev.to/charkinsdevelopment/i-did-my-own-small-benchmark-c-list-of-int-vs-array-of-int-2kc</guid>
      <description>&lt;p&gt;I consider myself an easy going guy. I like coffee, the simple things in life. Lists in my programming. &lt;/p&gt;

&lt;p&gt;But after doing some reading and reading some debates online, I decided to run a small benchmark myself on Lists vs Arrays. &lt;/p&gt;

&lt;p&gt;I did this with an extremely small set of data. I started the C# Stopwatch class and ran the clock over setting up the data structure, populating it, and then looping through those items in it. &lt;/p&gt;

&lt;p&gt;Both sets of data held integers 1 through 10. &lt;/p&gt;

&lt;p&gt;It took 00:00:00.0230056 seconds to process the list.&lt;br&gt;
It took 00:00:00.0008005 seconds to process the array.&lt;/p&gt;

&lt;p&gt;That is a ridiculously smaller amount of time to process the array. &lt;/p&gt;

&lt;p&gt;CRAZY. &lt;/p&gt;

&lt;p&gt;I wrote more on medium if you want to follow the article there. &lt;/p&gt;

&lt;p&gt;Thanks! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://coryharkins.medium.com/c-code-performance-list-vs-array-cf134b603774"&gt;My Medium Account&lt;/a&gt;&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>programming</category>
      <category>benchmarking</category>
    </item>
    <item>
      <title>LeetCode with C# - Reverse A String</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Thu, 14 Jan 2021 00:14:08 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/leetcode-with-c-reverse-a-string-4m50</link>
      <guid>https://dev.to/charkinsdevelopment/leetcode-with-c-reverse-a-string-4m50</guid>
      <description>&lt;p&gt;Welcome to my series on LeetCode and solving problems with C#. The goal of this series is to help those who are trying to solve LeetCode problems without directly giving them a copy paste answer. &lt;/p&gt;

&lt;p&gt;If you like this article, consider following me over at Medium. The article is available on a paid plan there, but gets released earlier than on dev.to. &lt;/p&gt;

&lt;p&gt;You can check that out here: &lt;a href="https://coryharkins.medium.com/leetcode-with-c-reverse-a-string-8ebb2f54f88a"&gt;https://coryharkins.medium.com/leetcode-with-c-reverse-a-string-8ebb2f54f88a&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To help you direct your brain on how to think about the given problem.&lt;/p&gt;

&lt;p&gt;With that let’s get into it. Today’s problem is Reversing a string.&lt;br&gt;
If you just want the solution and skip all the fun, just scroll down to the bottom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Write a function that reverses a string. The input string is given as an array of characters char[].&lt;/p&gt;

&lt;p&gt;Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You may assume all the characters consist of printable ascii characters.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does this mean?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are given an array of characters called s. It is of type char array. We need to reverse this array without allocating additional arrays to hold the data. We need to preform operations on this array and this array alone. The big O notation says that we should solve this with a constant linear time complexity.&lt;/p&gt;

&lt;p&gt;If you’d like additional resources on how to solve this problem you can look here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linq Solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Solution {
    public void ReverseString(char[] s) {
        Array.Reverse( s );
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Thoughts on the Linq Solution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Linq provided a very simple and readable way to solve this. You can simply call the Reverse method on your array. Under the hood this is doing something interesting though. From my research the Linq version is allocating a new array and iterating over the source and returning the new array. So this method is cheating; but LeetCode accepts it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iterative Solution (Two Pointer Technique)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void ReverseString(char[] s) 
    {
       int b = 0;
       int e = s.Length - 1;
       char t;
       while (b &amp;lt;= e)
       {
         t = s[b];
         s[b] = s[e];
         s[e] = t;
         b++;
         e--;
       }        
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Thoughts on the Two Pointer Technique&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The basics of what is going on here is that we have two pointers in the array. One at the beginning (b = 0) and one at the end (e = s.Length -1). We then loop through the array while our starting pointer does not equal our ending pointer.&lt;br&gt;
During this loop we set a variable for our current looking at location to the start of the array (t = s[b];). We then set the first element in the array = to the last, the last equal to the first. Increment our starting index. Decrement our ending index. Then swap it all again until we meet in the middle and break the while loop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does one solution matter over the other?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In short performance. As you can see here in both solutions the Linq solve and the two pointer technique allocate the same amount of memory but the two pointer technique is 60ms faster.&lt;/p&gt;

&lt;p&gt;60ms isn’t much to really worry about in an application where timing is not critical.&lt;br&gt;
Here over a longer set of data you can see the performance gains are different as well. Using 60 characters in an array we get the following results in processing time, roughly:&lt;br&gt;
Linq: 420ms.&lt;br&gt;
Two Pointer: 308ms.&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>datastructures</category>
      <category>leetcode</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Downloading Image Data using ASP.Net</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Wed, 11 Nov 2020 19:01:10 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/downloading-image-data-using-asp-net-5cig</link>
      <guid>https://dev.to/charkinsdevelopment/downloading-image-data-using-asp-net-5cig</guid>
      <description>&lt;p&gt;This article was originally written on my medium account if you'd like to support me and get these articles first, please consider following me over there for the latest articles, tips, tricks, and more!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://coryharkins.medium.com/how-to-download-image-data-bytes-using-asp-net-2322ca4521d7"&gt;source&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello and welcome back to another tip for my ASP.NET programmers!&lt;/p&gt;

&lt;p&gt;So I’ve noticed in my career where data importing is an extremely important and valuable skill to possess as a programmer. Knowledge is power after all! With that power comes the responsibility of downloading and processing images.&lt;/p&gt;

&lt;p&gt;Now if you’re not familiar with this (as I was when I first started) or have forgotten how to do this with dot net. Then a quick stack overflow search will land you on a solution similar to this one.&lt;/p&gt;

&lt;p&gt;We have a string that holds our image URL.&lt;/p&gt;

&lt;p&gt;We have a WebClient object that acts as our web browser.&lt;/p&gt;

&lt;p&gt;We have a byte array to hold our retrieved image data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string imageUrl = "https://placehold.it/300/450";
WebClient client = new WebClient();
byte[] imageBytes = client.DownloadData(imageUrl);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is all well and fine for a sample of “How to do it” but this doesn’t really cover a lot of ground or use cases. Simply copying and pasting this into your codebase really isn’t enough.&lt;/p&gt;

&lt;p&gt;It may work for a while, but as you send more URLs through this code you’ll start to notice its drawbacks and lack of robust data handling abilities.&lt;/p&gt;

&lt;p&gt;First of all with this code as it sits we have to remember to dispose of the web client. We can remedy that by wrapping this code in a pattern based using-declaration. This is doable on anything that implements the IDisposable interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using(WebClient client = new WebClient())
{
    string imageUrl = "https://placehold.it/300/450";
    byte[] imageBytes = client.DownloadData(imageUrl);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is much better because now the client will dispose of itself when the client is done and out of scope (ie. no longer needed).&lt;/p&gt;

&lt;p&gt;But this still doesn’t solve all our problems with this little block of code.&lt;/p&gt;

&lt;p&gt;Some resources will block a direct request like this. Typically in the form of a 503 error. You could try and catch this error and either keep trying to process other images, allow the code to keep going if you’re not worried about getting that image, or you can add a few extra lines of code to make this work.&lt;/p&gt;

&lt;p&gt;First off, you can set your web client to have a TLS12 protocol passed over on the request. This alone solved about 85% of my 503 errors when retrieving image data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using(WebClient client = new WebClient())
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    string imageUrl = "https://placehold.it/300/450";
    byte[] imageBytes = client.DownloadData(imageUrl);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To have this work as written you’ll have to add a using statement at the top of your cs file. This protocol is provided with .Net out of the box.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System.Net;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try this to solve your 503 errors when trying to access images.&lt;br&gt;
Some servers are even more guarded against downloading images, but you can still circumvent this by passing in a user-agent string in the header.&lt;br&gt;
To add a user-agent header to this request you simply do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using(WebClient client = new WebClient())
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    client.Headers.Add("user-agent", "user agent string");
    string imageUrl = "https://placehold.it/300/450";
    byte[] imageBytes = client.DownloadData(imageUrl);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once this was added, weeks later, and hundreds of image sources parsed and downloaded, I’ve yet to have an issue downloading image data.&lt;/p&gt;

&lt;p&gt;So tell me, what are your solves for downloading image data? Did any of these suggestions help you?&lt;/p&gt;

&lt;p&gt;Good luck and keep programming!&lt;br&gt;
-Cory&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>tutorial</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How to build a toastr.js notification system using ASP.NET MVC</title>
      <dc:creator>Cory Harkins</dc:creator>
      <pubDate>Tue, 27 Oct 2020 19:39:16 +0000</pubDate>
      <link>https://dev.to/charkinsdevelopment/how-to-build-a-toastr-js-notification-system-using-asp-net-mvc-1f97</link>
      <guid>https://dev.to/charkinsdevelopment/how-to-build-a-toastr-js-notification-system-using-asp-net-mvc-1f97</guid>
      <description>&lt;p&gt;SRC: &lt;a href="https://coryharkins.medium.com/how-to-implement-a-toastr-js-notifications-system-in-asp-net-mvc-5-d755a387ac5b"&gt;https://coryharkins.medium.com/how-to-implement-a-toastr-js-notifications-system-in-asp-net-mvc-5-d755a387ac5b&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hello and welcome!&lt;/p&gt;

&lt;p&gt;Today we are going to learn how to implement a server side generated notification system using the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MVC 5&lt;/li&gt;
&lt;li&gt;C#&lt;/li&gt;
&lt;li&gt;ASP.NET&lt;/li&gt;
&lt;li&gt;Toastr.js&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;&lt;br&gt;
To get this set up you can do a couple different things. jQuery is a requirement for this set up but a default MVC project comes with that out of the box so I won’t go over how to set that up here.&lt;br&gt;
First you’ll need to add a reference to toastr.js. You can do so by installing the nuget package for toastr or by clicking here and using the cnd versions. I went with the nuget install and added the references where they were needed.&lt;/p&gt;

&lt;p&gt;Your bundle config should look something like this with a reference to toastr:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
bundles.Add(new ScriptBundle("~/bundles/toastr").Include(            "~/Scripts/toastr.js"));&lt;br&gt;
bundles.Add(new StyleBundle("~/Content/css").Include(                     "~/Content/toastr.css"));&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then add the render call for your script and css files in your layout page (or where ever you need this script to be firing):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
@Styles.Render("~/Content/css")&lt;br&gt;
//body code and other stuff pertaining to layout&lt;br&gt;
@Scripts.Render("~/bundles/toastr")&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fun Stuff&lt;/strong&gt;&lt;br&gt;
Ok so now that the boring setup stuff is out of the way. Let’s get down to business.&lt;/p&gt;

&lt;p&gt;I first created a new folder for this helper to live in. I called it “Helpers” ( I know, clever). Inside that I made a class called NotificationsHelper.cs. &lt;/p&gt;

&lt;p&gt;This class is a view method calls and a model. We will utilize ASP.NET session variables to gather up a list of notifications to process as your code runs then process and render them in the layout with another method call. &lt;/p&gt;

&lt;p&gt;Ideally only one or two notifications at most would be toasted to the user but you can go crazy and get a list of 10+ if you want to drive your users mad!&lt;/p&gt;

&lt;p&gt;Alright, back to business. Here is the class I’ve set up.&lt;/p&gt;

&lt;p&gt;I’ll link the source &lt;a href="https://github.com/charkinsdevelopment/DotNetToastr/blob/main/Helpers/NotificationsHelper.cs"&gt;here&lt;/a&gt;.&lt;br&gt;
We can analyze the workflow of things below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Render Notifications&lt;/strong&gt;&lt;br&gt;
The render notifications method does exactly that. You call this on your layout page, and any time the layout page is rendered this system will auto populate any toasts that need to send.&lt;br&gt;
It pulls the data from a Session variable that I’ve chosen to call “Notifications” that takes in a List of type Notification that were collected during any Controller calls. It serializes this list to json and stores that in the session.&lt;br&gt;
If there is anything to render is generates basic toastr.js code to pop up an error or success message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Clear&lt;/strong&gt;&lt;br&gt;
The clear method just empties the session object once it’s been processes by RenderNotifications();&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add Notification&lt;/strong&gt;&lt;br&gt;
The add notification method takes in a Notification object that consists of a string message, a string title, and an enum notification type.&lt;/p&gt;

&lt;p&gt;This method can be called in any controller and it will store the notification in the session object. Which is then serialized and stored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definitions&lt;/strong&gt;&lt;br&gt;
Notification type. This is an enum that lists out four notification types that we have access to for toastr.js.&lt;/p&gt;

&lt;p&gt;Notification. This is a class that holds our properties that we can modify for a notification.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Back to the layout page&lt;/strong&gt;&lt;br&gt;
Adding this snippet to your _Layout.cshtml page will handle the rendering of any pending notifications. I added mine at the very bottom.&lt;br&gt;
&lt;code&gt;&lt;br&gt;
@Html.Raw(NotificationsHelper.RenderNotifications())&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Expanding this example&lt;/strong&gt;&lt;br&gt;
Toastr.js can take in a variety of information for a notification. Use this example as a base and continue onward with their sample docs here (Toastr.js).&lt;/p&gt;

&lt;p&gt;Try building some custom html notifications, storing and rendering that using this guide as a base.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>tutorial</category>
      <category>project</category>
    </item>
  </channel>
</rss>
