Sitefinity is Caching too Hard! If you’ve done software development for any length of time, you’ve likely run into a caching issue. Caching is difficult to get right, but it is so beneficial that we work with it in nearly everything we do. In the case of Sitefinity, it performs caching all over the place. As a result, many aspects of the Sitefinity experience are greatly improved. If you disabled caching for a Sitefinity site altogether, the site would slow down immensely. Sitefinity, by its nature of being a Content Management System, stores the bulk of its content in the…
This is post 5 of 17 in the series “Google Cloud for the .NET Developer” Now that we understand how to authenticate a C# application to work with your own project’s GCP resources, let’s take it a step further. In this post, we’ll look at how we can combine that connectivity with end user data, via three-legged OAUTH authorization, to perform operations on user content, with their permission of course. For this example, I’ve created a very simple ASP.NET MVC project that logs a user in, gets their profile image, and uploads it to a specific bucket. Let’s take a…
Here’s a quick tip follow up for my last post on working with MVC Areas with ASP.NET Core. When I visited the pages in the new Admin area I created, it was obvious that they were not picking up the layout and style from the other pages in the site: To fix this I needed to add the Layout property to the View:
Layout = "_Layout";
<a asp-action="Other">Go to Other view (TagHelper)</a>
@Html.ActionLink("Go to Other view (ActionLink)", "Other")
Alternatively, you can create a file named _ViewStart.cshtml with just the layout definition and place it in the Views folder for the Area. This approach will make all views automatically use the defined template. This…
Overview Sitefinity CMS features a powerful internal Search Engine that allows your site visitors to search your content and find what they are looking for. The Search Engine is built on top of the .NET port of the infamous Lunene Engine which powers an unlimited number of websites today. Unlike the solid Search Engine behind it, the Search Widget which Sitefinity offers is not as mature. It provides the options to set up a basic search page and returns the results in a form of a list. Perhaps that will be satisfactory in most cases, but what if your requirements exceed…
So you need to download a file to the browser with ASP.NET MVC? Let’s take a look at a simple example, starting with the Controller’s Action method. Controller Code System.Web.Mvc provides a few different types of FileResult (which derives from ActionResult): FileContentResult, FilePathResult, and FileStreamResult. However, since they all derive from FileResult, we can simply use FileResult as our return type.
public FileResult DownloadWidgetDataFile(long widgetId)
using (var mem = new MemoryStream())
// Create spreadsheet based on widgetId...
// Or get the path for a file on the server...
return File(mem, "application/vnd.ms-excel", "WidgetData.xlsx");
In this example, we are using an ID to look up some sort of data and create a MemoryStream that contains the file contents. If the data already exists as a file on the server’s file system, you would only…
We can replace Data Annotations with Entity Type Configuration to make our classes look clean and simple. Majority of developers prefer using View Models for CRUD operations leaving no reason to have Data Annotations defined in our model classes. This article will show you how to replace Data Annotations with Entity Type Configuration when using Entity Framework Code-First.
Your Sitecore data needs to reach a broad range of clients, including browsers and mobile devices that only RESTful applications can fulfill. Use Sitecore and MVC to build REST services for providing your customers and users with rich, interactive applications.
Child Actions are the action methods which can be invoked within the view. This is used to work with the data in the view, which are not related to the main action method. For example, if you want to create a data driven widget in the view using data that is not related to the main action method, you will need to use the child action method. In ASP.NET MVC any action can be used as a child action. However, to use an action only as a child action and attribute it with the ChildActionOnly. It will make sure the…
WebActivator allows us to execute a code long before application start-up. There may be requirements when you need to load external assemblies or instantiate a particular object before the application start up. You need to make sure some codes execute before the codes inside the App_Start folder and the global.asax file. To do this WebActivator should be used. You can add the WebActivator package using NuGet. Let us consider an example in an MVC application in which we want to call a method of a class before the execution of the application. To do this follow the steps below: Attribute…
ASP.NET MVC5 uses Identity 2.0 to manage the users and their roles. There may be scenario to check whether the currently logged in user or any user with the id exists in the given role or not, and checking can be done either in the controller class or in any other class of the application. Check for the currently logged in user In a controller you can find whether the currently logged in user exist in a role or not by using User property of the controller class. Type of the User property is IPrincipal and it has a Boolean…
Although Kendo UI’s default use of OData provides powerful, standard mechanisms for filtering data via HTTP requests, it can be overkill in many scenarios. In particular, if you are not using WebAPI in your ASP.NET application, it can be much simpler to implement server-side filtering using a single querystring value. Using the parameterMap function, you can control how the Kendo UI datasource communicates with your server-side methods.
In MVC 5 applications you may want to seed the database with initial users for various reasons. You may want default users and roles added as part of the application. In this post, we will take a look at how to seed the database with default users. The MVC 5 application uses ASP.Net Identity 2.0 to manage users, roles and identities. ASP.Net Identity 2.0 uses the Entity framework code first approach to create a database. To seed the database, first you need to enable migration on the database. To enable migration, in the package manager console run the command enable-migrations…
ASP.NET MVC 5 provides five different kinds of Filters. They are as follows: Authentication [Introduced in MVC5] Authorization Action Result Exception Filters are used to inject logic at the different levels of request processing. Let us understand where at the various stages of request processing different filters get applied. Authentication filter runs before any other filter or action method Authorization filter runs after Authentication filter and before any other filter or action method Action filter runs before and after any action method Result filter runs before and after execution of any action result Exception filter runs only if action methods,…
As Single-Page Applications (SPAs) become more prevalent, it is becoming more important to know how to leverage your server-side technologies to best enable them. ASP.NET has a lot of great features that will help you create this type of modern web application. One of these features is the partial view. In this post, I want to show you a simple helper method for your controller classes in ASP.NET MVC that will allow you to return partial views when your client-side application is requesting them via an asynchronous request (that is, an XHR, or XMLHttpRequest), and to return full views-with-layout when the same…
In ASP.Net MVC 5.0, users and their roles are managed using ASP.Net Identity 2.0. By default when you create a new account email, password and confirm password are required as it’s shown below. You may come across a requirement to modify the required fields for a particular application user. For example, along with the email and password, you want to save the user’s age, country and city. In this post we will learn to modify the user information. Basically there are the three steps involved in this: Modify the ViewModel To modify the ViewModel, you should change the RegisterViewModel classin…
Many developers struggle to work with jQuery UI in an ASP.NET MVC application. In this post, I will show you three steps required to start working with jQuery UI in an ASP.NET MVC application. At the end of the post we will take a look at working with the autocomplete widget. The following three steps will let you work with jQuery UI in an ASP.NET MVC application: Step 1: Add the jQuery UI Reference Add the jQuery UI reference into the project using the NuGet manager. Once this is done, you should find the reference added in the Content folder…
While working on an ASP.NET MVC 5 application, I came across a requirement to use an Area from one project in another project. For example: I have a project A and a project B. I need to use an Area which is part of project B inside of project A. In this post I will discuss how this can be achieved. To start with, let us say I have an MVC project AreaDemo with the structure as follows: Right now there is one area DataAnalysis in the project. To demonstrate multiple areas, I have created multiple ActionLink in the layout…