Requiring authentication for a whole ASP.Net MVC site

This is easy from ASP.NET MVC 4 onwards: http://blogs.msdn.com/b/rickandy/archive/2012/03/23/securing-your-asp-net-mvc-4-app-and-the-new-allowanonymous-attribute.aspx You can register a filter that will require users to be authenticated to access all controllers public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); filters.Add(new System.Web.Mvc.AuthorizeAttribute()); } but then they won’t be able to access to the Login controller, so you simply add the [AllowAnonymous] attribute to that controller: [AllowAnonymous] public ActionResult Login(string returnUrl) [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public ActionResult Login(LoginModel model, string returnUrl)

February 28, 2014 · 1 min

Multiline Text Editor in MVC

In ASP.Net MVC, it’s so easy to create an entity data model and generate controllers and views for each entity. You can create lots of pages for editing your data just by clicking buttons… A downside is that the generated code doesn’t know the the difference between a small string and a large one, so you get the same small text input box to edit all strings. In your razor view, that’s created by ...

February 27, 2014 · 2 min

Intercepting FormView inserts and updates

Our FormViews in ASP.Net web forms tend to contain user controls in the templates. If you want to want to intercept the insert or update events, you end up with something like: protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) { } But how do you access the values in the user control? We’ve often had code like this: TextBox tReviewerName = (TextBox)FormView1.Row.FindControl("dataReviewerName"); which is OK to get the value from that field if you want to code your own updates/inserts but you can’t (I think) write back to that field in time for the update to pass that new value back to the database. ...

January 27, 2014 · 1 min

AutoMapper

From http://stackoverflow.com/tags/automapper/info AutoMapper uses a fluent configuration API to define an object-object mapping strategy. AutoMapper uses a convention-based matching algorithm to match up source to destination values. Currently, AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer. Slightly slow but useful video to show how AutoMapper is useful ...

January 16, 2014 · 1 min

NuGets of gold

“NuGet is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework.” http://docs.nuget.org/ To be as agile as possible, the projects developed by the team tend to be coded as separate .Net projects, rather than within one over-arching framework. This makes it easy, when starting a project, to copy the elements from the most similar existing project and just get on with it, without worrying about breaking existing applications. The downside to this is that bugs that are identified and fixed in one project may also need to be fixed in many other projects. In the same way, design changes (updates to templates) need to be rolled out across many sites. Updates to libraries such as jQuery or .Net need to be rolled out across many sites too but there can be an advantage in that, as testing can be done in smaller chunks before the new version can go live – plus the rule of, if it ain’t broke, don’t fix it, can be applied to the older projects that don’t have any other reason to be updated. ...

January 16, 2014 · 4 min

Frameworks for Rich Internet Applications

Reading to do relating to frameworks for Rich Internet Applications… Visual Studio 2013 bundles Knockout.js, which looks fairly straightforward (I hope) Postal could be a better way of handling the events https://github.com/postaljs/postal.js Need to make sure our applications are accessible: http://stackoverflow.com/questions/7370056/accessibility-and-all-these-javascript-frameworks With Knockout, you can pass the server side model to the client like this: <script> ko.applyBindings(@Html.ToJSON(Model)); </script> Comparison of frameworks http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/ Yet more from the developers at Twitter http://twitter.github.io/hogan.js/. This is a compiler for {{mustache}}, which is a templating language that can convert JSON to HTML in a similar way to Razor converting entities to HTML in ASP.Net. Useful if you want to say generate whole data grids on the client. If your server is getting JSON from elsewhere and you want to template it into HTML, you can use mustache templates on the server (rather than client) using https://github.com/jdiamond/Nustache ...

January 13, 2014 · 1 min

Entity Framework – Model First

There are 3 ways to link entity framework to a database: Database first. Point Visual Studio at your database and it will create an entity model for you. Code first. Write your classes in Visual Studio and it can create your database for you. Model first. Use the Entity Data Model Tool in Visual Studio to model your entities. Visual Studio will can them create your database and classes for you. I’ve just tried Model First and not achieved what I wanted. ...

January 9, 2014 · 2 min

HTML emails

If you need to dynamically create HTML emails (say for a new announcements system), the first thing to do is question whether you really need to or if any other alternative will do. This is especially the case if you’re going to give users a WYSIWYG editor to create marked up content. Some useful resources: http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/say-hello-to-the-html-email-boilerplate/ http://24ways.org/2009/rock-solid-html-emails/ http://htmlemailboilerplate.com/ https://litmus.com/blog/16-tips-troubleshooting-html-email https://templates.campaignmonitor.com/build/ http://www.campaignmonitor.com/css/ http://premailer.dialect.ca/ – converts CSS to inline styles https://litmus.com/email-testing – get screenshots of your email in different clients

September 4, 2013 · 1 min

Convert URLs to hyperlinks in Excel using VBA

Public Sub Convert_To_Hyperlinks() Dim Cell As Range For Each Cell In Intersect(Selection, ActiveSheet.UsedRange) If Cell <> "" Then ActiveSheet.Hyperlinks.Add Cell, Cell.Value End If Next End Sub

September 21, 2012 · 1 min

Linked servers in SQL Server

Querying across databases using linked servers should be easy: http://stackoverflow.com/questions/4091960/sql-server-linked-server-example-query but linking SQL Server 2008 (64 bit) to SQL Server 2000 (SP3 I think) results in an error: Cannot obtain the schema rowset “DBSCHEMA_TABLES_INFO” for OLE DB provider “SQLNCLI10” for linked server… To get around this the old server needs a stored procedure as follows: create procedure dbo.sp_tables_info_rowset_64 @table_name sysname, @table_schema sysname = null, @table_type nvarchar(255) = null as declare @Result int set @Result = 0 exec @Result = sp_tables_info_rowset @table_name, @table_schema, @table_type go as described here: ...

May 29, 2012 · 1 min