Category: Configuration

  • Additional Pages in an Umbraco 7 MVC Website

    Additional Pages in an Umbraco 7 MVC Website

    Umbraco 7 has messed around with, and closed down much of the MVC routing engine, to such a point that one cannot really be sure what standard MVC techniques still work.

    I have quickly come to the conclusion that while Umbraco makes very good CMS only sites this is a difficult area for a developer wishing to extend the site, say by putting additional pages in. All pages should be CMS pages and the components that the developer develops should be view based within them, or using the so called “Surface Controllers”.

    Is this a problem? I’m not sure right now for myself, and for the reader, it depends on your requirements. There may be times when you legitimately want to add some functionality outside of a CMS page. Your choices are very restricted as related – even examples that should work such as using Plugin Controllers, I can’t get to work – at best the website just hangs. Possibly because its passing some data around between pages and I’m not getting my routing code correct yet – I’ll update this post if I find out the answer.

    So if you want to mix CMS and your own pages, you must start with Umbraco pages and write your pages into the content, or choose another CMS.

    If you want additional pages in your site, then your choice is between making Umbraco pages and “programming” these, or putting your additional pages into a pure MVC project based sub-domain.

    Redirecting the odd .aspx page

    I have a small website that I wanted to perform some simple 301 redirects as it was replacing a webforms website.

    There are better ways of doing this (URL rewriting in the config file, or writing an handler for example), but what I ended up doing was creating a number of ASP.NET webpages of the same names as the old pages in the site, and having a Response.RedirectPermanent(“url”) in the Page_Load of the code behind.

    I also needed to alter the following Umbraco web.config AppSetting to get this to work:

    
      
        
    ...
    
  • Deploying a Visual Studio 2012 Project to Azure

    Deploying a Visual Studio 2012 Project to Azure

    This has probably been covered about a million times on the net, but I have included it to complete my previous post on Installing Umbraco Visual Studio Install using Nuget.

    This post assumes you have a Windows Azure account and know a little bit about whats in there (databases, web applications etc.)

    To sign up for Azure, please click the following link: http://azure.microsoft.com/en-gb/pricing/free-trial/. This link covers in more detail setting up a web application in Azure for the first time http://azure.microsoft.com/en-gb/documentation/articles/web-sites-dotnet-get-started/. I am going to be a bit briefer here in this post.

    Step 1: Deploy the SQL/Server database to Windows Azure
    Deploy Database to SQL Azure menu option in SQL Server 2012
    Deploy Database to SQL Azure menu option in SQL Server 2012
    The following page appears. You should connect to SQL/Azure (assuming you have opened the Firewall at the Azure end) and enter the connection details for your Azure database server, along with the name of the new database.

    Deploy to SQL Azure Settings
    Deploy to SQL Azure Settings
    Step 2: Create the web application in Azure

    Go to your Azure portal and create a web application using quick start. No need to specify any database details at this point.

    Azure Management Portal Create Web Application
    Azure Management Portal Create Web Application
    Step 3: Download your Azure Publish Profile

    After the web application has created, go into the dashboard for it and on the right hand side, you should choose the download the publish profile option to download the publish profile to your local machine.

    Azure Web App Dashboard - Download Publish Profile Link
    Azure Web App Dashboard – Download Publish Profile Link
    Step 4: Import your Azure Publish Profile into Visual Studio

    The final step is to right click your project and click Publish, and then at the first step Import the publish profile into Visual Studio. See below.

    Publish Visual Studio 2012 Project - Step 1
    Publish Visual Studio 2012 Project – Step 1
    You also need to specify the connection string that the web app will use to connect to your Azure database. This information is available in the Windows Azure Management Portal for your database – there is an option to show the connection strings. You should use the ADO.NET connection string listed on this page in the Windows Azure Management Portal.

    Specifying connection string in the Visual Studio 2012 publish wizard
    Specifying connection string in the Visual Studio 2012 publish wizard

    I hope somebody finds this useful. For sure, deploying to Azure is easy enough, but setting up Umbraco via Nuget was not.

  • Howto: Umbraco Visual Studio Install via Nuget

    Howto: Umbraco Visual Studio Install via Nuget

    As mentioned in a previous post, I have struggled to install Umbraco using 7.2.1/7.2.4 and Visual Studio 2013 (VS2013).

    As a developer my requirement is to add content management to an existing MVC project, or to start a new MVC project and give the users the option of content management so on the face of it Umbraco is a pretty good fit. Umbraco is more intrusive to Visual Studio than it could be in my opinion, because it overwrites the global.asax and uses its own compiled version for routing configuration etc. Not exactly an open system. However it does install correctly on VS2012. I have used MVC 4 and Visual Studio 2012 on .NET Framework 4.5.1.

    This is part of 2 posts, the second post covers Deploying a Visual Studio 2012 project to Azure – this are follow on steps once you have completed all the steps listed in this post.

    Here are the steps:

    Step 1: Create a C# or VB Web project in Visual Studio 2012.
    Screen print of Visual Studio New Project dialog
    Screen print of Visual Studio New Project dialog

    Choose your name and Click OK.

    Step 2: Choose Empty Project
    VS2012 - New ASP.NET MVC 4 Project options
    VS2012 – New ASP.NET MVC 4 Project options
    Step 3: Remove your global.asax and web.config

    I am not 100% convinced that this step is necessary, however I did it anyway during my install as some posts on the internet related to Visual Studio and Umbraco recommended it. Its probably a good idea to remove the files in the App_Start folder and also compile the project at this point (a better way if you have any concerns at this point is to go into Nuget and remove all packages).

    Step 4: Disable Resharper if you have it installed

    Again based on a recommendation I have read about. Go to Tools, then Options then Resharper as shown below:

    Resharper Options screen in Visual Studio
    Resharper Options screen in Visual Studio
    Step 5: Add Umbraco using Nuget Package Manager Console

    Go to Tools, then Package Manager, then Package Manager Console and enter the following command (N.B. omit the version part to get the latest version):

    
    install-package umbracocms -version 7.2.1
    

    Any errors at this stage – remove umbracocms and all other packages in Nuget and try again. Don’t forget to re-enable Resharper if you suspended it.

    Step 6: Create a SQL/Server Database

    You should create a SQL/Server database on your local machine:

    Creating a new database in SQL/Server 2012
    Creating a new database in SQL/Server 2012

    You also need to set up a user for this database:

    Creating a user in SQL/Server 2012
    Creating a user in SQL/Server 2012
    Setting up a user in SQL/Server 2012 step 3
    Setting up a user in SQL/Server 2012 step 3
    Step 7: Build and Run the Project to Install Umbraco

    Now you have set up Umbraco in the project, you need to set up Umbraco in its database for your website.

    Switch back to Visual Studio 2012 and Build and Run the project. If the following prompt comes up enter as desired (the publish option should transform debug out of the web.config in any case):

    Debug Question in VS2012
    Debug Question in VS2012

    Important: on the following page enter your details and click Customize. Do not click Install unless you want all the default options.

    Umbraco Installation Configuration Page 1
    Umbraco Installation Configuration Page 1

    On this page, you should enter the details of your SQL/Server database and user you just set up, then click Continue, to well, continue…

    Umbraco Installation Configuration Page 2
    Umbraco Installation Configuration Page 2

    You should choose “No thanks, I do not want to install a starter website”, unless you are doing this for the first time and want to have a play.

    Umbraco Installation Configuration Page 3
    Umbraco Installation Configuration Page 3

    Umbraco then “whirrs” for a bit (or maybe its just my computer) and then takes you into the Umbraco admin area. You are now ready to go and set up your own template. However, I’m going to take you straight into deploying this empty website to Azure in my next post.

    Umbraco Backoffice Admin Area
    Umbraco Backoffice Admin Area
    At this point, I think I checked the Add Item options in Visual Studio about 1,000 times, just to marvel at the “Add Controller” option, unable to believe my eyes. The reason? Following exactly the same steps in Visual Studio 2013 results in the scaffolding options being absent, with no way to get them back for that project. Not really good enough given that VS2013 has been around for a couple of years.

    To deploy this project to Azure, please refer to my next post on Deploying a Visual Studio 2012 website to Windows Azure. Having just created an Umbraco project, there are a few additional things you should be aware of:

    1. You need to ensure that all the correct files are included in the project, because by default, many are not. More or less everything apart from the usual bin, obj and packages folders should be deployed. So to do this, click Show All Files and right click and choose Include in Project as appropriate. If you don’t do this your project will not work when it publishes because it will not be complete.
    2. You should remove the umbraco\install folder within the solution. It is no longer needed and should not be deployed up to the web.
    3. You might like to add a robots.txt file before you deploy. There are many ways to do this, but I just added a text file to the Visual Studio project with some suitable lines in it.
    4. If you get errors when you deploy for the first time, you can use WebMatrix to change your deployed Web.Config to set CustomErrors=”Off” rather than “RemoteOnly”. This will allow you to see the YSOD (yellow screen of death). In my case, it was due to missing dlls – from an Umbraco package that I had installed as part of my theme. Visual Studio Publish doesn’t know about these. So I manually copied this DLL into my bin folder.
    5. Once you have deployed for the first time, its very important to ensure that any .config files in App_Data are NOT deployed subsequently. This is because these are data files that hold some of the content for the site. The reason why I deployed these the first time was because I had installed a theme locally before deploying so I wanted my sample content up. So I set build action to “None” for these files.

    Update: After following the steps in this post, you may like to review which files are in the project and also if they are added correctly to your source control system. I usually use SVN, and some work is always required in this respect. In particular Umbraco will not add files from a template into Visual Studio automatically, so you have to show all files and then include the files you would like in the project by right clicking and choosing “Include in Project”.

  • Umbraco VS2013 Nuget Install Problems

    Umbraco VS2013 Nuget Install Problems

    I have been working on my first Umbraco 7 project. No matter what I do I cannot get it to install correctly via Nuget with VS2013. I am tearing my hair out here, which is bad because I don’t have much to start with!

    The instructions are from our.umbraco.org, titled Installing Umbraco with Nuget.

    I have followed the instructions to the letter, including turning off my Resharper install. I have tried on two different machines, a Windows 7 with VS2013 professional and the same install on Windows 8.1.

    No matter what I do, I lose the Add Controllers and other scaffolding options at the point that the Umbraco install completes.

    I have tried installing an empty MVC project (which creates the menu options), then uninstalling MVC via Nuget, then installing via the instructions above, same result.

    If I follow the instructions above for VS2012 I get the correct scaffolding.

    I am using Umbraco 7.2.1, I have also tried 7.2.4.

    With VS2013 the end results are always as shown in the image below. The solution (ugh thats so 2012!) is to use VS2012!

    Image showing missing scaffolding in VS2013
    Umbraco install trashes VS2013 project
  • Uploading Zip files in Umbraco 7

    Uploading Zip files in Umbraco 7

    I have am in the process of setting up an Umbraco 7 website that has limited editing facilities (i.e. only one person will be updating the site, a relatively experienced user at that). I would like this user to be able to upload Zip files.

    It appears that the disallowedUploadFiles in config/umbracoSettings.config is totally ignored:

    
     ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd,swf,xml,html,htm,svg,php,htaccess
    

    Instead, it uses jQuery to upload the files, and the jQuery uploader has its own list of allowed files. I looked inside umbraco_client\FileUploader\Js\jquery.fileUploader.js and altered the following:

    
    (function ($, window, document, undefined) {
    
        $.event.props.push('dataTransfer');
    
        var defaultOptions = {
            autoUpload: false,
            limit: false,
            allowedExtension: 'jpg|jpeg|gif|png|pdf', // alter this line to include your file types
            dropTarget: null,
    ...
    


    I don't recommend expanding this to Exe's or Zips if your users are not 100% expert and totally trusted not to upload bad files. I wanted just to be able to upload Zip files.

    Next, I had to look at the file size limits. ASP.NET's defaults are too low. To fix this, I edited web.config, to add the maxRequestLength and executionTimeout attributes:

    
      
        
        
        
    ...
    

    I also had to add a System.WebServer.Security section to the web.config:

    
      
        
          
            
          
        
    ...
    

    This allowed my uploads to work ok.

    The alternative to doing this I guess (I didn't try it) was to upload small text files as place holders and then log into the server and change the files - which are placed inside the media folder under a subfolder which is the Id of the media item.

    Thanks to Scott Leslie's post that I found that reminded me of what needs doing to set the file upload limits in web.config http://sleslie.me/2014/change-maximum-upload-file-size-in-umbraco/