On Sitefinity Custom Widget Caching

By | .NET, ASP.NET, C#, MVC, Sitefinity | No Comments

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…

Read More

Rewriting URLs to Lowercase in Sitefinity

By | .NET, MVC, Sitefinity | No Comments

Enforcing Lowercase on URLs to Normalize URLs In any web application, it is generally a good idea to make sure that all of your content has only one way to reach them via a user’s address bar in their browser. Whether you accomplish this by using canonical URLs, strict discipline/convention (i.e. “I will never capitalize any directory or filename”, very hard!), or rewriting URLs into lowercase ones, they all accomplish the same goal. Google only sees one URL for content, and your SEO doesn’t take a hit for “duplicate content” like what may happen if you can go to…

Read More

Set Layout for Views in MVC Areas

By | ASP.NET, ASP.NET Core, MVC | No Comments

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:

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…

Read More

MVC Areas with ASP.NET Core

By | ASP.NET, ASP.NET Core, MVC, Web | One Comment

Areas in MVC allow you to separate your web application into segments, each with their own set of Controllers and Views, for better organization and intuitive access via routing. I decided to play with this MVC Areas feature in ASP.NET Core and thought I’d share my experience in case it might help others using this feature. My first attempt to use this was to simply add the Areas folder to the root of my application, with a subfolder called Admin with the associated folders for Controllers, Models, and Views: I added a simple AdminController to simulate a separate Administration section…

Read More

QuerySelectorAll Error on BeginFormSitefinity

By | ASP.NET, MVC, Sitefinity | No Comments

When developing a custom form on Sitefinity MVC widgets, the HTML helper method Sitefinity provides, Html.BeginFormSitefinity(), is a very handy resource. You wrap your form elements up inside the whole thing, along with a submit button, and you can point it at an HttpPost Action on your custom MVC widget controller with ease. When you’re putting your form widget on a master page, however, you can run into a rather vague JavaScript error that prevents your form from submitting correctly. The error in JavaScript brings up something about querySelectorAll and you’re left scratching your head as to what you did…

Read More

Client-side validation of Sitefinity CAPTCHA MVC Feather Form Field

By | MVC, Sitefinity | No Comments

In the current 9.1.6110 release of Sitefinity, there is a known issue with the Sitefinity CAPTCHA MVC form field that prevents it from firing the client-side validation. If the user leaves the CAPTCHA field blank, the form will still submit (either a full post-back or via AJAX, depending on the settings of the form), and the user will see a generic “Entry not valid” error message. It would probably be better to catch this right away via client-side validation. Fortunately, using Feather, we can easily override the CAPTCHA template to enable this. We simply need to change the input field…

Read More

Preserve Feather Content Block HTML Formatting

By | JavaScript, MVC, Sitefinity | 2 Comments

Feather widgets in Sitefinity are a significant improvement over traditional Sitefinity widgets. They are more responsive, provide better tooling, and are easier to customize (both the main area as well as designer views). However, I recently encountered an issue with one of the basic default Feather widgets included with more recent versions of Sitefinity. In this post we’re going to see how to modify this behavior, so that when working with the Feather Content Block widget we have it behave the way we would like. This post also serves a second purpose: Introducing how to modify a built-in Sitefinity Feather…

Read More

Lock Down Content Widgets with UrlKeyPrefix

By | MVC, Sitefinity | No Comments

When you’re working with your content in Sitefinity, a very common practice to display said content is to provide a list and details view. On the page (or pages) containing these views, it is often good to provide a sidebar to provide for additional navigation functionality when users are browsing your content. News articles, for example, can support Tags to help classify stories into various buckets. It’s also nice for users to see a concise list of stories on the sidebar in addition to the more fleshed-out list that the page primarily shows. To accomplish this in Sitefinity appears trivial…

Read More

Using HandleUnknownAction in MVC Widgets

By | .NET, ASP.NET, C#, MVC, Sitefinity | No Comments

Sitefinity’s MVC widgets are fantastic. They allow untold amounts of customization and enable you to create an MVC framework as complex or as simple as you need. There is a caveat to using them, however: Because the controllers are typical ASP.NET MVC controllers, going to particular pages on your site might make them disappear! There is a simple workaround for this problem, and with this information you can ensure that your Sitefinity MVC widgets consistently display no matter what current state your web site is in. The Problem Say you have a simple custom MVC widget that has a single…

Read More

Working with Hybrid Forms in Sitefinity Widgets

By | .NET, C#, MVC, Sitefinity | No Comments

Throughout the course of web development, you often find yourself in a situation where you need data input from your user. Scenarios range from a simple contact form, to something as complex as a multi-part job application. In either case, Sitefinity offers multiple solutions. The easiest solution, for the simpler forms such as the aforementioned contact form, is to use Sitefinity’s built-in Forms capabilities. Much like with their pages, Sitefinity Forms provide a very simple, powerful way to create and customize even more complex forms for your site. The resulting data is then stored in Sitefinity, and can be set…

Read More

ReSharper Template for View Model Properties with Annotations

By | .NET, C#, MVC, News, Tools | 2 Comments

I am a huge fan of making things as easy as possible and as a developer that often comes down to getting code written in the least amount of keystrokes. Recently I have been working with a system that has very large data entry screens so I found myself repeatedly writing auto properties with data annotations over and over again.  I was doing this using the built in Visual Studio Code Snippet “prop” so it was handling the auto property creation but didn’t help me with the data annotations.  I wanted something better, but knew I didn’t want to deal with the XML…

Read More

File Downloads with ASP.NET MVC

By | .NET, ASP.NET, MVC | 5 Comments

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.

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…

Read More

Falafel Partners with New Venture Software to Provide Additional Custom Development Support

By | .NET, MVC, News | No Comments

Falafel is very happy to announce that we have formalized a partnership with New Venture Software, a boutique custom software development and consulting company. The partnership between Falafel and New Venture Software is built on a long history that started back in 2006. Moving forward, we are now able to extend our capabilities around .NET, MVC, WPF, HTML5, iOS development Objective C and Swift as we work side-by-side on select customer projects as needed.

Read More

Falafel Now Offers Sitecore Implementation Services!

By | MVC, News, Sitecore | No Comments

Falafel is happy to announce that we have now partnered with Sitecore, the global leader in customer experience management, and have expanded our offerings to include Sitecore Development and Mentoring. Our Certified Sitecore Developers can help you ensure that your (and your customers) Sitecore experience is perfect. Whether you’re looking to install Sitecore for the first time or just need a little bit of guidance, we’re here to help! Sitecore Development: Installation and setup Custom built modules and widgets Custom site designs Migration from another CMS Upgrade from a previous Sitecore version CRM integration (SalesForce and more) Payment gateway integration…

Read More

Child Actions in ASP.NET MVC

By | MVC | 4 Comments

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…

Read More

Start-up code using WebActivator in MVC application

By | MVC | One Comment

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…

Read More

Check User exists in a Role in ASP.NET Identity 2.0

By | MVC | 8 Comments

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…

Read More

Connect KendoUI AutoComplete to MVC Action

By | ASP.NET, JavaScript, Kendo UI, MVC | One Comment

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.

Read More

Seed the database with initial Users in MVC 5

By | MVC | 9 Comments

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…

Read More

Custom Action Filter in ASP.NET MVC 5

By | MVC | 8 Comments

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,…

Read More

Returning a Partial View Only for XHR Requests in ASP.NET MVC

By | ASP.NET, JavaScript, MVC | 3 Comments

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…

Read More

Customize the MVC 5 Application Users’ using ASP.Net Identity 2.0

By | MVC | 15 Comments

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…

Read More