Articles contributed by the community, curated for your enjoyment and reading.

Filters

Reset
Categories
Tags
This easy vegetarian pasta bake gives you all the flavor of classic spinach and cheese cannelloni without the fuss. This vegetarian pasta bake is a quick and easy riff on classic spinach and ricotta cannelloni. Instead of stuffing traditional pasta shells, I toss penne pasta in a creamy sauce made with spinach, basil, and ricotta. After topping the dish with two flavorful cheeses, I bake it until golden and bubbly. To ensure a smooth and creamy texture, I add mascarpone (or cream cheese) to the sauce, which eliminates any potential graininess that can sometimes occur with ricotta-based sauces. While the pasta bakes, I usually toss a big salad to complete the meal. You’ll need to make Baked penne with spinach, ricotta & fontina How to make Baked penne with spinach, ricotta & fontina To begin, bring a large pot of salted water to a boil and add the penne. Cook until al dente, about 9 minutes. The pasta will continue to cook in the oven, so you want it a bit underdone. Drain the pasta, then place it back in the pan and set aside. Meanwhile, drain the spinach and squeeze as dry as possible. In the bowl of a food processor fitted with the steel blade, combine the dry spinach, basil, ricotta, mascarpone (or cream cheese), half-and-half cream, 1 cup fontina, 3 tablespoons Parmigiano Reggiano, salt, pepper, and nutmeg. Process until puréed. Add the spinach mixture to the pasta. Stir to combine. Transfer to a baking dish. Top with the remaining fontina and Pecorino Romano cheese. Bake until the pasta is bubbling and the top is golden in spots, about 20 minutes. Let cool for a few minutes, then serve.   Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Baked Penne with Spinach, Ricotta & Fontina.
2 min read   • Dec 1, 2023
In a dynamic web application, the session is crucial to hold the information of current logged in user identity/data. So someone without authentication cannot have access to some Page or any ActionResult, to implement this kind of functionality, we need to check session exists (is not null) in every action which required authentication. So, the general method is as follows: [HttpGet] public ActionResult Home() { if(Session["ID"] == null) return RedirectToAction("Login","Home"); } We have to check the above 2 statements each time and in each ActionResult, but it may cause 2 problems. Repeat Things: As per the good programming stranded, we don't have to repeat the things. Create a module of common code and access it multiple times/repeatedly Code missing: We have to write code multiple times so it might happen some time we forget to write code in some method or we missed it. How To Avoid? The ASP.NET MVC provides a very great mechanism i.e., Action Filters. An action filter is an attribute. You can apply most action filters to either an individual controller action or an entire controller. If you want to know more about action filter, please click here. So we will create a custom Action Filter that handles session expiration and if session is null, redirect to Login Action. Create a new class in your project and copy the following code: namespace Mayur.Web.Attributes { public class SessionTimeoutAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpContext ctx = HttpContext.Current; if (HttpContext.Current.Session["ID"] == null) { filterContext.Result = new RedirectResult("~/Home/Login"); return; } base.OnActionExecuting(filterContext); } } } Now our Action Filter is created and we are ready to use it. The following code will show you how we can apply attribute to Action or to complete controller. 1. Apply to Action [HttpGet] [SessionTimeout] public ActionResult MyProfile() { return View(); } 2. Apply to Controller [SessionTimeout] public class HomeController : Controller { [HttpGet] public async ActionResult MyProfile() { return View(); } [HttpGet] public async ActionResult MyQuestions() { return View(); } [HttpGet] public async ActionResult MyArticles() { return View(); } } Now all actions of Home Controller will check for session when hit with the help of Action Filter. So we have reduced the code and repetitive things. This is the benefits of Action Filters. Happy coding !!!
3 min read   • Nov 23, 2023
In almost 90% of projects, we need to upload images to server and store them. In most cases, hackers try to exploit an image upload system and try to upload exploitable materials like web-shells, some harmful scripts, table deletions scripts, etc. To prevent this, I have written one helper function which validates file in many conditions and makes sure the file is in correct image format. The code is not fully written by me, I researched many articles and filtered the conditions which helps us to validate the required output. /// <summary> /// Verifies that a uploading file is in valid Image format /// </summary> /// <param name="postedFile">File which is selected for upload</param> /// <param name="imageMinBytes">Minimum file size in byte</param> /// <param name="imageMaxBytes">Maximum file size in byte</param> /// <returns>true if the file is a valid image format and false if it's not</returns> public static bool IsValidImageFormat(HttpPostedFileBase postedFile, int imageMinBytes, long imageMaxBytes) { //------------------------------------------- // Check the image extension //------------------------------------------- if (Path.GetExtension(postedFile.FileName).ToLower() != ".jpg" && Path.GetExtension(postedFile.FileName).ToLower() != ".png" && Path.GetExtension(postedFile.FileName).ToLower() != ".gif" && Path.GetExtension(postedFile.FileName).ToLower() != ".jpeg") { return false; } //------------------------------------------- // Check the image MIME types //------------------------------------------- if (postedFile.ContentType.ToLower() != "image/jpg" && postedFile.ContentType.ToLower() != "image/jpeg" && postedFile.ContentType.ToLower() != "image/pjpeg" && postedFile.ContentType.ToLower() != "image/gif" && postedFile.ContentType.ToLower() != "image/x-png" && postedFile.ContentType.ToLower() != "image/png") { return false; } //------------------------------------------- // Attempt to read the file and check the first bytes //------------------------------------------- try { if (!postedFile.InputStream.CanRead) { return false; } if (postedFile.ContentLength < imageMinBytes) { return false; } byte[] buffer = new byte[512]; postedFile.InputStream.Read(buffer, 0, 512); string content = System.Text.Encoding.UTF8.GetString(buffer); if (Regex.IsMatch(content, @"<script|<html|<head|<title|<body| <pre|<table|<a\s+href|<img|<plaintext|<cross\-domain\-policy", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Multiline)) { return false; } } catch (Exception) { return false; } //------------------------------------------- // Try to instantiate new Bitmap, if .NET will throw exception // we can assume that it's not a valid image //------------------------------------------- try { using (var bitmap = new System.Drawing.Bitmap(postedFile.InputStream)) { } } catch (Exception) { return false; } return true; } Hope it will help you. Let me know your thoughts!  
4 min read   • Nov 23, 2023
A Simple Cookie Wrapper Class for MVC: Easily Manage Cookies in Your Web Application In web development, managing cookies efficiently is a crucial part of building user-friendly applications. In this post, I will show you how to create a simple and reusable cookie helper class in MVC, which allows you to easily create, read, update, and delete cookies. This approach simplifies cookie management and ensures your code is clean and easy to maintain. Introduction to Cookie Management in MVC Cookies are small pieces of data stored in the user's browser. They are typically used for sessions, preferences, and other user-specific data. In MVC applications, handling cookies manually can be cumbersome. That's where a helper class comes in handy. Let’s build a CookieHelper.cs class to abstract the common operations like creating, reading, updating, and deleting cookies. CookieHelper Class Code Create a new file named CookieHelper.cs and paste the following code into it. This class defines the basic functionality you need for working with cookies in your MVC application. using System; using System.Web; public class CookieHelper { #region Constants // The name of the cookie to be used public const string CookieName = "UserName"; #endregion #region Enums public enum CookieInterval { SECOND = 0, MINUTE = 1, HOUR = 2, DAY = 3, MONTH = 4, YEAR = 5 }; #endregion #region Utility Methods // Calculates the expiration date for the cookie based on the given duration and unit private static DateTime CalculateCookieExpiry(int duration, CookieInterval durationUnit) { DateTime cookieExpire = DateTime.Now; switch (durationUnit) { case CookieInterval.SECOND: cookieExpire = DateTime.Now.AddSeconds(duration); break; case CookieInterval.MINUTE: cookieExpire = DateTime.Now.AddMinutes(duration); break; case CookieInterval.HOUR: cookieExpire = DateTime.Now.AddHours(duration); break; case CookieInterval.DAY: cookieExpire = DateTime.Now.AddDays(duration); break; case CookieInterval.MONTH: cookieExpire = DateTime.Now.AddMonths(duration); break; case CookieInterval.YEAR: cookieExpire = DateTime.Now.AddYears(duration); break; default: cookieExpire = DateTime.Now.AddDays(duration); break; } return cookieExpire; } #endregion #region Public Methods // Creates a cookie with a specific name, value, and expiration time public static string CreateCookie(string cookieName, string cookieValue, CookieInterval durationUnit, int duration) { HttpCookie cookie = new HttpCookie(cookieName) { Value = cookieValue, Expires = CalculateCookieExpiry(duration, durationUnit) }; HttpContext.Current.Response.Cookies.Add(cookie); return cookieValue; } // Reads the value of an existing cookie by its name public static string ReadCookie(string cookieName) { HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName]; return cookie?.Value ?? string.Empty; } // Updates the value and expiration of an existing cookie public static string UpdateCookie(string cookieName, string newCookieValue, CookieInterval durationUnit, int duration) { HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName]; if (cookie != null) { cookie.Value = newCookieValue; cookie.Expires = CalculateCookieExpiry(duration, durationUnit); HttpContext.Current.Response.Cookies.Add(cookie); } return newCookieValue; } // Deletes a cookie by setting its expiration date to the past public static void DeleteCookie(string cookieName) { HttpCookie cookie = new HttpCookie(cookieName) { Expires = DateTime.Now.AddDays(-1) }; HttpContext.Current.Response.Cookies.Add(cookie); } #endregion } How to Use the CookieHelper Class Now that you have the CookieHelper class, let's walk through some common scenarios: creating, reading, updating, and deleting cookies. 1. Create a Cookie To create a cookie, you simply call the CreateCookie method with the cookie's name, value, duration unit (such as days or months), and duration: string cookieValue = CookieHelper.CreateCookie(CookieHelper.CookieName, "This is a test cookie", CookieHelper.CookieInterval.DAY, 7); This will create a cookie that expires in 7 days. 2. Read a Cookie To read the value of an existing cookie, use the ReadCookie method: string cookieValue = CookieHelper.ReadCookie(CookieHelper.CookieName); If the cookie exists, this will return its value. If it doesn't, it will return an empty string. 3. Update a Cookie To update the value of an existing cookie, call the UpdateCookie method: string updatedCookieValue = CookieHelper.UpdateCookie(CookieHelper.CookieName, "Updated cookie value", CookieHelper.CookieInterval.DAY, 14); This will update the cookie's value and reset its expiration date to 14 days from now. 4. Delete a Cookie To delete a cookie, use the DeleteCookie method: CookieHelper.DeleteCookie(CookieHelper.CookieName); This will remove the cookie by setting its expiration date to a past date, effectively deleting it from the user's browser. Conclusion With this simple CookieHelper class, you can easily manage cookies in your MVC applications. Whether you're creating, reading, updating, or deleting cookies, the code is clean and easy to use. Feel free to use this class in your project, and let me know your thoughts or any improvements you might suggest!
7 min read   • Nov 23, 2023
A delicious (and make-ahead!) alternative to traditional holiday turkey. Whether you’re cooking for a smaller crowd for the holidays or looking for an alternative to traditional turkey, this stuffed turkey breast is the answer. Adapted from Patrick and Gina Neely, it is much more flavorful and juicy than your typical roast turkey and cooks in just 1¼ hours. What’s more, it can be made entirely ahead of time and is a cinch to carve. The hardest part of the recipe is pounding the turkey breast thin, so I suggest asking your butcher to do it for you. This recipe has become part of my family’s Thanksgiving tradition — everyone prefers it to traditional roast turkey, even the dark-meat lovers. Sometimes I even make it in addition to roasting a large bird to guarantee we have plenty of leftovers. What You’ll Need To Make Rolled Turkey Breast with Sausage & Herb Stuffing Step-by-Step Instructions To begin, make the stuffing. Melt the butter in a large skillet over medium heat. Add the onions and celery and cook, stirring frequently, until soft. Add the garlic and sausage. Continue to cook, breaking up the meat with a wooden spoon, until the sausage is cooked and slightly browned, about 5 minutes. Add the wine, rosemary and thyme. Cook for two minutes more, using your wooden spoon to scrape up any browned bits from the bottom of the pan. Remove from the heat. n a large mixing bowl, combine the egg, stuffing cubes, chicken broth, parsley, 1/2 teaspoon kosher salt, 1/4 teaspoon pepper, and sausage mixture. Stir until all the bread is moistened. Place the butterflied turkey breast skin-side down on a countertop or work surface. Pound to an even 1/2-inch thickness. Spoon about half of the stuffing in an even 1/2-inch layer over the breast, leaving a 1-inch border all around. (You’ll cook the remaining stuffing separately.) Starting at the long end, roll the turkey into a long cylinder. Tie the roll with kitchen string with about 2 inches between each knot, and then trim the strings. Line a baking sheet with aluminum foil and place an oven-proof rack over top. Place the turkey seam-side down on the rack, drizzle with olive oil and season with salt and pepper.   Remove the turkey from the oven and let rest, loosely tented with foil for 15 minutes. The turkey will rise in temperature as it rests to 165°F. Snip the kitchen twine. Transfer the roll to a cutting board and slice into 1/2-inch thick slices. Arrange on a platter and serve with gravy.   Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Rolled Turkey Breast with Sausage & Herb Stuffing.  
3 min read   • Jun 29, 2023
Good and good for you! You’ll love these protein-packed chicken and quinoa burrito bowls with a spicy green sauce.   These burrito bowls are really three stand-alone dishes in one: an easy grilled chicken recipe you’ll put on repeat throughout grilling season; a spicy green sauce you’ll want to put on everything; and foolproof quinoa. The toppings are up to you – fresh corn, beans, tomatoes, cucumbers, avocado, or whatever your heart desires. These bowls are totally doable for a dinner party since you can make most of the recipe ahead, and everyone will love assembling their own bowls. They’re healthy and gluten-free to boot. What you’ll need to make Burrito Bowls How to make burrito bowls Begin by making the marinade for the chicken. To make life easy, I combine everything in a ziplock bag (no dirty bowls!). Lime gives the chicken wonderful flavor but note that I only use the zest. Lime juice, or any acidic ingredient, will turn lean boneless skinless chicken breasts into shoe leather before they ever hit the grill. To zest the limes, it’s best to use a rasp grater like the one above. Marinate the chicken in the refrigerator for at least six hours or overnight. Next make the sauce. Simply combine all of the ingredients in a blender or food processor and blend until smooth. You’ll notice that I add some of the seeds of the jalapeño to make it spicy — go easy at first and add more to your liking. Finally, make the quinoa by combining the quinoa, salt, and water in a medium saucepan. You’ll notice that my recipe calls for a little less water than the instructions on the package. I find it comes out better (read: less mushy) this way, and you can always add a little more water at the end if need be. Cover and simmer until the quinoa is cooked. Up to this point, the entire recipe can be made ahead. Come dinnertime, preheat the grill. Place the chicken on the grill and cook, covered, for 2-3 minutes per side, turning only once. Cut the chicken into bite-sized pieces and serve with the quinoa, green sauce, and toppings of your choosing. Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Chicken & Quinoa Burrito Bowls with Spicy Green Sauce.
3 min read   • Jun 28, 2023
Made with a rotisserie chicken, this salad is easy to whip up and full of bright, spicy Southeast Asian flavor. As much as I love salad as a meal, it’s not usually enough for my husband, who is more of a protein/two sides kind of a guy. But this is one salad that I can get away with serving for dinner — it’s satisfying and full of bright, spicy Southeast Asian flavor. It’s easy, too! You simply shred a rotisserie chicken, chop some veggies, whisk the dressing, and dinner is done. The recipe makes enough for 2 to 3 main course salads; if you want to stretch it, serve some store-bought crispy spring rolls on the side. What you’ll need to make Vietnamese Shredded Chicken Salad Step-by-Step Instructions To begin, combine all of the salad ingredients, except for the peanuts, in a large bowl. Next, make the dressing. You’ll need to juice a few limes; an inexpensive juicer like this one is helpful but not necessary. Whisk together the freshly squeezed lime juice, Sriracha, garlic, sugar, fish sauce, and vegetable oil.   Pour the dressing over the salad and toss well. Top with peanuts and serve. Note: This recipe originally comes from Saveur magazine but I’ve tweaked it a bit to make it my own. (I omitted the rice vinegar and Thai peppers, increased the lime, and added bell peppers, scallions, Sriracha, and peanuts.) Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Vietnamese Shredded Chicken Salad.
2 min read   • Jun 26, 2023
This chicken curry recipe is family-friendly and easy enough for a busy weeknight. Serve it with basmati rice and dinner is done! In this family-friendly chicken curry dish, thinly sliced chicken breasts are sautéed with curry powder and simmered in an aromatic curry sauce thickened with Greek yogurt. You can have it on the table in 30 minutes — or in the time it takes to make some basmati rice — and the cooking method ensures that the chicken comes out reliably tender every time. As with many Indian dishes, the taste and spice level of this dish will vary a bit depending on the type of curry powder you use, so adjust the seasoning as necessary. What you’ll need to make chicken curry Step-By-Step Instructions Begin by cutting the chicken into 1/4-inch slices. The best way is to cut each breast in half lengthwise, then slice on the diagonal. Don’t make yourself crazy over it, but try to make each piece about the same size; this ensures that they cook evenly. Next, season the chicken with salt, pepper and curry powder. Heat some vegetable oil in a large skillet, then briefly sauté the chicken until it is lightly browned but still pink in spots. Transfer the partially cooked chicken to a clean bowl, then add the onions to the pan and cook until soft and translucent. Add the ginger, garlic, and more curry powder and sauté until fragrant. Add the chicken stock and cornstarch to the vegetables. Cook until the sauce is thickened, then add the chicken back to the pan, along with the frozen peas and simmer until the chicken is just cooked. Add the Greek yogurt and fresh chopped cilantro. Stir until combined. Serve with basmati rice and/or naan. Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Chicken Curry.
3 min read   • Jun 24, 2023
This healthy turkey chili has a rich, spicy flavor and thick texture — and it’s loaded with nutrient-rich kidney beans. When it’s cold outside, there’s nothing more inviting than a big pot of chili simmering on the stove, and this turkey chili adapted from The Complete One Pot Cookbook from America’s Test Kitchen always hits the spot. It has a rich, spicy flavor and thick texture, and it’s loaded with fiber-rich kidney beans. Since ground turkey is lean and can easily dry out, the recipe uses a genius technique to ensure the meat stays moist. Instead of adding all of the meat at once, a portion of the turkey is sautéed in the beginning and cooked low and slow to build flavor. Then, towards the end of the simmering time, the remaining turkey is pinched into small pieces and stirred into the chili, creating chunks of tender turkey in every bite. Be sure to use 93% lean ground turkey, which is a combination of light and dark meat, rather than 99% lean ground turkey breast. Serve with cornbread or cornbread muffins and your favorite chili toppings. What You’ll Need To Make Turkey Chili Step-by-Step Instructions Roughly chop the onions, bell pepper, and garlic and place in the bowl of a food processor fitted with the steel blade. Pulse, scraping down the sides as necessary, until the vegetables are finely chopped. Do not over-process; the vegetables should not be puréed. (Alternatively, finely chop the onions, bell pepper, and garlic by hand.) Heat the oil in a large pot or Dutch oven over medium heat. Add the chopped vegetables, chili powder, cumin, coriander, red pepper flakes, oregano, and cayenne pepper. Cook, stirring often, until the vegetables are softened, about 10 minutes. Add about 1-1/4 pounds of the turkey to the pot. Increase the heat to medium-high, and cook, breaking up the meat with a wooden spoon, until no longer pink, about 4 minutes. Stir in the beans, diced tomatoes and their juice, crushed tomatoes, broth, and salt and bring to a simmer. Reduce the heat to medium-low and cook, uncovered, until the chili has begun to thicken, about 1 hour. Pat the remaining 3/4 pound turkey together into a ball, then pinch off teaspoon-size pieces of meat and stir into the chili. Continue to simmer, stirring occasionally, until turkey is tender and chili is slightly thickened, about 40 minutes. (If the chili begins to stick to the bottom of the pot or looks too thick, stir in extra broth as needed.) Taste and adjust seasoning, if necessary, and serve with your favorite chili toppings.   Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Classic Turkey Chili.
3 min read   • Jun 19, 2023
Store-bought rotisserie chicken and puff pastry make these individual chicken pot pies easy to prepare.   Between the chicken, the sauce, and the crust, you could spend an entire day in the kitchen making traditional chicken pot pie. For this version, my goal was to come up with an easy recipe that didn’t sacrifice flavor. After many trials, I found that using a rotisserie chicken for the filling and a good quality store-bought puff pastry for the crust were both excellent shortcuts. With that settled, I moved on to tackle the problem with most chicken pot pies: the bland, goopy white sauce. I thinned the sauce to a chowder-like consistency. I also borrowed an ingredient from my favorite turkey gravy – Cognac – and it added that je ne sais quoi that makes these chicken pot pies next-level delicious. What you’ll need to make chicken pot pie recommend Dufour all-butter puff pastry if you can find it (it’s sold at Whole Foods) but Pepperidge Farm, which is readily available in the freezer section of most supermarkets, is very good, too. How to make chicken pot pie To begin, dust a clean, dry work surface with flour and place the puff pastry over top. Sprinkle the pastry with flour and roll to about 1/8-inch thick, smoothing the creases with the rolling pin at the same time. Using a sharp knife, kitchen shears, or a pizza cutter, cut out 4 circles about 2 inches larger than the circumference of your soup bowls. Place the dough rounds on a foil-lined baking sheet and refrigerate until ready to use. Next, make the filling. In a large sauté pan over medium heat, melt the butter, Add the yellow onion, garlic, celery, pearl onions, and carrots. Sauté for 8 to 10 minutes, or until the carrots are just cooked. Add the flour. Cook, stirring constantly, for about 2 minutes. Add the broth, cognac, salt, and white pepper. Bring to a boil, stirring with a wooden spoon to incorporate the flour. Simmer until thickened, a few minutes. Off the heat, stir in the heavy cream, herbs, chicken, and peas. Ladle the filling into oven-safe ramekins or soup bowls (be sure they are oven proof up to 425°F). The filling should come up no more than three-quarters of the way to the top of the bowls. If you have extra, make another bowl. Brush the outside edges of each bowl with an egg wash. Place the cold dough rounds over the soup bowls, pressing firmly around the edges so that the dough adheres, and then brush the top of the dough with the egg wash. Using a sharp knife, make a ½-inch slit in the top of each pie. Bake for 20 to 25 minutes, or until the pastry is a rich golden brown. Let cool for about 10 minutes, then use a wide spatula to carefully transfer the hot ramekins to serving plates. Sprinkle a few fresh thyme sprigs over top of the bowls and serve. For this recipe, you’ll need oven-safe (up to 425°F) soup bowls. To make four servings, use bowls with an 18 to 20-oz capacity. To make six servings, use bowls with a 12 to 14-oz capacity. Note: This recipe has been written by Jenn Segal and republished on MudMatter with Author’s Permission. Please find the original link here – Chicken Pot Pie.
4 min read   • Jun 19, 2023