Attention: We are retiring the ASP.NET Community Blogs. Learn more >


"Knowledge has to be improved, challenged, and increased constantly, or it vanishes."

Contents tagged with ASP.Net

  • Resolving 'System.Drawing.Image' Errors After Upgrading to .NET 9

    Microsoft recently released .NET 9, the latest version of its popular development platform. This release brings several enhancements, including improved performance, enhanced developer productivity tools, and updated runtime features. With a focus on streamlining application development and introducing new capabilities, .NET 9 continues to solidify its position as a powerful framework for modern software development.

  • Level Up Your Skills at Microsoft Build: Attend and Earn a Free Microsoft Certification Exam through the Cloud Skills Challenge

    Microsoft Build is an annual conference designed for developers, software engineers and tech professionals. This year, Microsoft Build will take place from Tuesday, May 23 to Thursday, May 25, offering attendees the choice to participate either in-person or online.  The conference serves as a platform for Microsoft to unveil new tools, technologies, and updates while providing valuable educational sessions and workshops to help developers enhance their skills.

  • System.Net.Mail.SmtpClient is not recommended anymore; what is the alternative?

    For years, I have been using System.Net.Mail namespace to send email from my ASP.Net applications. Recently one of my friend asked my assistance in troubleshooting the email delivery issues from a newly deployed application. It was interesting that the same deployed code was sending email with the same configuration settings. However, I noticed, the test environment is Windows and the Production is Ubuntu. I wanted to understand is there any difference, do we need to add any extra parameters when using Linux, So I went into the SmtpClient documentation, that was used by the developer to send the Email.

  • Taking Your ASP.NET Core 7 Localization to the Next Level: Localizing Layout

    This post is a continuation of my previous post, Globalization & Localization in ASP.Net Core 7,  (https://weblogs.asp.net/sreejukg/globalization-localization-in-asp-net-core-7), where I explained the importance of Globalization and Localization and how to apply them to your Razor Pages. However, the previous post only covered localizing Razor Pages and did not discuss localizing the layout files of an ASP.Net Core Razor Pages application. In this post, we will be exploring how to localize the text in the layout files, so I encourage you to read the previous post to gain a better understanding of the localization topics covered in this post.

  • Distributed Cache with SQL Server in ASP.Net Core application

    Performance is a key factor for any application, especially for web & mobile applications. Based on various research studies, it has been identified that high performing sites retain users than low performing sites. This means a poor performing site will have impact on the company’s business goals. So, Developers, be aware to make sure your applications are designed for faster response times.

    One of the aspects that affect the performance of an application is Caching. With caching, you store the frequently accessed data and store in some temporary storage, As a developer, you should carefully consider the various caching mechanisms and implement them in your applications.

    Caching in ASP.Net Application

    ASP.Net supports both In-Memory Cache and Distributed Cache. Let me illustrate the basic differences.

    In-Memory Cache

    In-Memory Cache, your application uses Server memory to store the cached data. This works perfectly if you have only one server. In today’s world, where you use cloud services and automatically scale your applications, all your servers need to access the cached data from a single source, and In-Memory cache will not help you here,

    Distributed Cache

    In distributed cache, the cached data is stored and shared across all servers. ASP.Net supports several types of distributed cache implementations such as SQL Server, Redis, NCache etc.

    In this article, I am going to demonstrate how to implement distributed cache with SQL Server. For the purpose of this demo, I created a .Net application using the template “ASP.Net Core Web App”. The screenshot of the app in solution explorer is given below.

    clip_image002

  • Running background tasks in ASP.Net applications

    While developing applications, you may come across various occasions where you create background services to achieve automation in your applications. Such services include sending notification, update a user’s subscription expiration or may be changing the state of a workflow activity and so on.

    Developers use Windows Service, Cron jobs or Executables that works in a separate thread than your web applications that works based on a schedule. In .Net, for creating a background task, developers mainly use the Console Application or Windows Service template. While this will do the job, it adds some complexity. Few of the issues developers face with background services are below

    • You may use configuration files in the web application such as connection string, logs file path etc, however for the console application, you need to redefine them under its application settings, something your operation team will not prefer, of course this adds operations complexity.
    • Migrating the application may lead to troubles as I have seen several times, the migration happens without migrating the background service and then developers troubleshoot and identifies they forgot some of the services.
    • Modifying the code in the application and database structure may impact the background service.
    • And many more


    Though it had limitations, developers used it a lot especially when they need to implement background services. Now with the ASP.Net framework has built in capability to run background tasks from the web application itself. Cool, for many of you, it must be music to your ears, now from the same project you can manage your pages, application logic and background services.

    Background Service in Asp.Net application

    In ASP.Net background tasks can be implemented as hosted services. In this article, I am going to demonstrate how you can develop a background service in ASP.Net

    For the purpose of this demo, I used the following environment.

      • ASP.Net 6
      • Visual Studio 2022 Preview
      • ASP.Net Web application


    Also, I have a class in my application called Task that has a due date and Is Completed flag. I have a page that create a task by setting a due date. Now I am going to create a background service in ASP.Net application itself that set IsCompleted to true for tasks when it reaches the due date.

    See the Task class below.

    public class Task { public int Id { get; set; } public string Title { get; set; } public DateTime DueDate { get; set; } public bool IsCompleted { get; set; } public DateTime ActionDate { get; set; } }

  • Geolocation in ASP.Net Core using Azure Maps

    With the advancement in technologies, the world has become a global village. The people all over the world are interconnected. It is quite common that the companies publish their contents in multiple languages. With trade laws differ from country to country the developers need to make their website address the users who visit their web application by identifying the user’s country.

  • Integrate Amazon SNS with Asp.Net Core Application

    Amazon SNS is a notification service that offer message delivery. SNS basically supports messaging between a variety of publishers and consumers. Publishers shall send notifications to Topics and Subscribers can consume the messages. Amazon SNS supports Application to Application messaging and Application to Person messaging.

    In this article I am going to demonstrate the Application to Person subscription in Amazon SNS. In Application to Person messaging, SNS supports the following.

    • SMS Messaging
    • Mobile Push Notifications
    • Email Notifications


  • Index is not an attribute class – Error while migrating from ASP.Net MVC 5 to .Net Core

    Recently one of my friends was migrating a project from ASP.Net MVC 5 to ASP.Net core 3.1. One of the challenges he faced is with the Index Attribute in data annotations. The .Net Core is not recognizing the Index attribute. When he copied his class from his MVC 5 project, he got the following error message.

  • Sending Push Notifications from ASP.Net Core using Google Firebase

    Recently I was engaged in a project where by the customer wanted to push messages to the mobile application from their website. For e.g. when a page is published in the website, a new product added or price changed for a product, customer wanted to send push notifications to the mobile applications in these events.

  • C# 7 - Return multiple values from methods


    It was a long-awaited feature to return multiple values from a method. Developers used collection variables such as Array, ArrayList or Generic List to return multiple values from methods. Now with Visual Studio 2017 and C# 7, you can easily return multiple values with the help of Tuples.

    In this article, I am going to explain how tuples can be used in C# 7 onwards to return multiple values.

    Consider the following code from the console application. The method GetDivisionResults accepts two parameters namely number and divisor and returns two integers that are quotient and remainder.

             static void Main(string[] args)
             {
                 int number = 17;
                 int devisor = 5;
                 var result = GetDivisionResults(17, 5);
                 Console.WriteLine("Quotient is " + result.Item1);
                 Console.WriteLine("Remainder is " + result.Item2);
             }

  • Send email using Office 365 account and C#

    Microsoft Cloud offering “Office 365” is becoming popular day by day. One of the mostly used feature in Office 365 is the exchange online. Lots of customers are moving their emails to exchange online.

    The developers now needs to send email notifications using Exchange online as their SMTP Server. Office 365 offers various integration options that allows your devices/applications to connect and send email. Refer the below technet article for more details.

    https://technet.microsoft.com/en-us/library/dn554323(v=exchg.150).aspx

  • Securing sections in Web.Config

    For ASP.Net applications, developers usually store lots of configuration data in the Web.Config, some of such settings can contain secured information such as connection strings, email settings, proxy settings etc. Storing credential information in Web.Config as plain text is a threat as this could lead to leak the information. Though the web server will not render web.config files to the visitors, you need to see there could be users, such as system administrators, back  up operators, etc who have access to your server’s file system. Exposing secured information for such users is a threat and you need to protect your configuration data. The solution is to encrypt the sections in Web.Config and thankfully ASP.Net offers out of the box support for encrypting and decrypting the connection string placed inside Web.Config.

    In this article I am going to demonstrate, how to encrypt/decrypt the connection string section in Web.Config, you can follow the same concepts to encrypt any other section in web.config. For the purpose of the article, I created an ASP.Net empty web application and added a default.aspx file. The project in solution explorer looks as follows.

    image

  • Integrate Microsoft Translator into your ASP.Net application

    In this article I am going to explain how easily you can integrate the Microsoft translator API to your ASP.Net application. Why we need a translation API? Once you published a website, you are opening a channel to the global audience. So making the web content available only in one language doesn’t cover all your audience. Especially when you are offering products/services it is important to provide contents in multiple languages. Users will be more comfortable when they see the content in their native language. How to achieve this, hiring translators and translate the content to all your user’s languages will cost you lot of money, and it is not a one time job, you need to translate the contents on the go. What is the alternative, we need to look for machine translation. Thankfully there are some translator engines available that gives you API level access, so that automatically you can translate the content and display to the user. Microsoft Translator API is an excellent set of web service APIs that allows developers to use the machine translation technology in their own applications.