It's been a while since I last blogged on the subject of the Lawn Maintenance Calendar, now know simply as Lawn Calendar. The plan is go live this Sunday. Although things are pretty much ready, there are a couple of tasks that I need to complete.
Firstly, I need to create a 'down' screen that I can switch on whilst I upload and configure the site.
Secondly, I need to work how how the data migrations are going to work. The content provider has already uploaded quite a bit of content into the system on the test hoster and I want to use that as the basis for the live database. That way, the content provider can add images to the existing written content. Entity framework now has a migration feature which might be just the replacement I need for the existing DropAndCreateOnModelChange strategy that is currently employed.
Update: The launch went ahead on Sunday after a hive of activity on Saturday.
Down screen
I found that my new hoster already provides this function, so I didn't have to develop it myself this time. It's not the most beautiful of down pages, but it will do for the time being.
Data Migrations
I've moved to using Entity Framework 4.3.1 which includes the migrations feature. This now allows me to make database enhancements and upgrade without having to lose the contents of the database. I've been very impressed with it and will be using it's scripting features to upgrade to V2 when the time comes.
Here's some useful links regarding EF 4.3. and migrations:
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx
http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-configuration-file-settings.aspx
http://www.ladislavmrnka.com/2012/03/ef-4-3-migrations-and-existing-database/
Uploading to hoster
This was quite straightforward for the website itself, but the database was a little trickier. I couldn't find a way of uploading the mdf files and attaching them to the database like I could with the test site hoster. So, the only way I could get the database uploaded was to create an empty database, script and re-create the schema and then import the data using SSIS.
Showing posts with label Entity Framework. Show all posts
Showing posts with label Entity Framework. Show all posts
Friday, 22 June 2012
Wednesday, 28 March 2012
Dynamic Detail Links
To dynamically inject the detail links from the task content to the keyword detail content I decided to inject the links using Regex.Replace, just prior to displaying the task content. So I wrote a helper that the razor page could call to make the replacements.
For this to work, I needed each task to have a property that contained a list of keywords that were applicable to the content, so I could pass these into the helper method. I didn't want to store these keywords with the task, as then I'd need a housekeeping task to keep these lists up to date with the detail content.
So, I used LINQ to SQL to dynamically look up keywords that were found in the content, which I then added to my new property. To prevent the new property from being automatically added to the task table, Entity Framework allows you to annotate properties on your entity classes as NotMapped. This is basically saying I'm going to calculate the values for this property myself in code.
To verify that EF was making the queries that I was expecting, I used a SQL profiler. I could see that the correct queries were being made and that SQL Server was correctly caching queries that had already been run.
Note about XSS: I've been reading up about cross site scripting (xss) and how pages can be vulnerable to such an attack if content containing html elements are not html encoded prior to display.
In this solution, I'm injecting links into content and for the links to be displayed correctly in the browser, I'm bypassing html encoding of the content using @Html.Raw. So to prevent a vulnerability, my helper method pre html encodes the content before injecting the links. This way, only the links that are injected by my managed code will reach the browser as html.
The other thing that I will need to do, before deployment, is ensure that the assembly containing the helper is signed with a strong name to prevent switching of a malicious version.
For this to work, I needed each task to have a property that contained a list of keywords that were applicable to the content, so I could pass these into the helper method. I didn't want to store these keywords with the task, as then I'd need a housekeeping task to keep these lists up to date with the detail content.
So, I used LINQ to SQL to dynamically look up keywords that were found in the content, which I then added to my new property. To prevent the new property from being automatically added to the task table, Entity Framework allows you to annotate properties on your entity classes as NotMapped. This is basically saying I'm going to calculate the values for this property myself in code.
To verify that EF was making the queries that I was expecting, I used a SQL profiler. I could see that the correct queries were being made and that SQL Server was correctly caching queries that had already been run.
Note about XSS: I've been reading up about cross site scripting (xss) and how pages can be vulnerable to such an attack if content containing html elements are not html encoded prior to display.
In this solution, I'm injecting links into content and for the links to be displayed correctly in the browser, I'm bypassing html encoding of the content using @Html.Raw. So to prevent a vulnerability, my helper method pre html encodes the content before injecting the links. This way, only the links that are injected by my managed code will reach the browser as html.
The other thing that I will need to do, before deployment, is ensure that the assembly containing the helper is signed with a strong name to prevent switching of a malicious version.
Subscribe to:
Posts (Atom)