Visual Studio Project Templates, CORS Module - This week in Orchard (30/01/2021)

Gábor Domonkos's avatar
Documentation, This week in Orchard

Now you can use a CORS module that enables the configuration of CORS settings! Check out the two demos of this week: first look under the hood of the Cornish Mining WHS site! Then check out the new project templates for Visual Studio!

Orchard Core updates

CORS module

Browser security prevents a web page from making requests to a different domain than the one that served the web page. This restriction is called the same-origin policy. The same-origin policy prevents a malicious site from reading sensitive data from another site. Sometimes, you might want to allow other sites to make cross-origin requests to your app. And now you can easily manage your CORS policies with the new CORS module.

Just navigate to the admin UI of your site and enable the new CORS Configuration module. If you do that you will see a new option under Configuration -> Settings, called CORS. Here you can add as many policies as you want by just clicking on the Add a policy button. As you can see on the screen, here you can define the allowed origins, headers, methods, and so on.

CORS settings

Documenting CustomSettings recipe step

A recipe can execute multiple steps. In order to create a new Recipe step, you need to implement the IRecipeStepHandler interface and the ExecuteAsync method: public async Task ExecuteAsync(RecipeExecutionContext context). We have a page in the documentation that lists all of the available recipe steps. And now you can find the JSON format of CustomSettings recipe step too!

CustomSettings step documentation

Login via Email or User Name

If you navigate to the login page of your site you may notice that the label of the first textbox has been changed to Username or email address.

The new login screen with the email option

Yes, it does what it looks like: now you can use your email address too to log in, not just your username. When you log in, the logic does a POST request to the Login action of the AccountController and in line 193, it will try to find the given user not just by the username but also by the email address.

The updated Login action in the AccountController

But what will happen with the existing users then? How this affects them? Well, from now, there is a list that contains the allowed characters for the user name and you can also find a new migration step that is about to replace the @ sign in the user names with a + sign.

Migration for the existing users

Fix HTML semantics issues in modals

If you have modules for the admin theme and have modals where you used the itemprop attribute, now you will have a warning message in the console that says: Please use data-url-af instead of itemprop attribute for confirm modals. Using itemprop will eventually become deprecated. But why? If you run a Markup Validation Service to check the markup validity of an Orchard Core site, you saw the following error: Validation error: “The itemprop attribute was specified, but the element is not a property of any item”.

Removing the itemprop attribute

Demos

An Orchard Core site: Cornish Mining World Heritage

A few weeks ago we showed you a new Orchard Core site, the Cornish Mining World Heritage, that you can use to find information on how to make the most of your visit to the Cornwall and West Devon Mining Landscape World Heritage Site and many more. And now you can see a demo on YouTube too that allows you to look under the hood and get an overview about what Orchard Core features the developers used to implement this great site!

If you are interested in more websites using Orchard and Orchard Core, don't forget to visit Show Orchard. Show Orchard is a website for showing representative Orchard CMS (and now Orchard Core) websites all around the internet. It was started by Ryan Drew Burnett, but since he doesn't work with Orchard anymore, as announced earlier it is now maintained by our team at Lombiq Technologies.

Visual Studio Project Templates

A number of predefined project and item templates are installed with Visual Studio. These templates, such as the ASP.NET Web Application and Class Library templates, are available to choose from when you create a new project. Item templates, such as code files, XML files, HTML pages, and Style Sheets, appear in the Add New Item window.

These templates provide a starting point for users to begin creating projects, or to expand existing projects. Project templates provide the files that are required for a particular project type, include standard assembly references, and set default project properties and compiler options. Item templates can range in complexity from a single empty file that has a certain file extension to multiple source code files with stub code, designer information files, and embedded resources.

And now we have some custom templates when you are working with Orchard Core too! You may know that there is a page in the Orchard Core documentation about how to install and use Orchard Core code generation templates. The goal of this new feature is to able to use these code generation templates right from Visual Studio. Currently, it's a preview feature in VS 2019 16.8 but it should be enabled by default in VS 2019 16.9. So, if you are using VS 2019 version 16.8, first of all, you need to navigate to Tools -> Options -> Environment -> Preview Features and put a tick in the Show all .NET Core templates in the New project dialog (requires restart) checkbox.

Visual Studio Preview Features options

Now if you restart Visual Studio and say Create a new project, you will find a new project type called Orchard Core. But you can use these templates not just from here, but from an opened solution when you are about to add a new project to your existing Orchard Core site.

Create a new project dialog in Visual Studio

Let's say we would like to create our new Orchard Core application. For that, select the template called Orchard Core Cms Web App (Orchard Project). After setting up the name of the project, the location, and the solution name, we will see the following additional information window. Here you can specify which framework you would like to use (right now you can choose from .NET Core 3.1 and .NET 5.0), the type of the logger, and the version of the Orchard Core packages.

Create new Orchard Core application from Visual Studio

But wait! If these properties are familiar to you, you are right. Let's just open up PowerShell or a command line and type dotnet new occms. By using this command you can generate an Orchard Cms Web Application. If you type the --help, you can see which CLI parameters you can pass to setup options.

The dotnet new command for creating a new Orchard Core application

And yes, you can see that the new Visual Studio project templates are using the same values, it's just by adding a nice UI for you if you prefer using Visual Studio instead of the dotnet command.

But that's not all, you have several more project templates to play with. If you are interested, head to YouTube to check out a short recording about how you can use Visual Studio project templates!

News from the community

Work with us!

You've completed the Dojo Course, congratulations! You’re now officially an Orchard Core developer. Would you like to work on a variety of challenging Orchard Core projects with the biggest Orchard team in the world? Work with us! Just send us an e-mail to crew at lombiq.com. Please include what you’re most interested in professionally and attach around 100 lines of any kind of code that you’re especially proud of or just link to the favorite open-source project of your own on GitHub or else.

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 189 subscribers! We have started this newsletter to inform the community around Orchard with the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this week's Orchard meeting!

2 Comments

  • Darragh said Reply

    Hi,
    I am using CMS.Tragets 1.0.0-rc2-13450. I don't see Cors as an option to enable under features. I don't see the cors dlls in the bin directories. I noticed that they were originally released last January. Do I need to reference at different version of CMS.Targets?

    Thanks
    Darragh

  • Zoltán Lehóczky said Reply

    The CORS module was released _this_ January :). You just need to update to the latest packages.

Add a Comment