Tagged "dotnet"

Running C# on AWS Lambda

One of the greatest things about AWS cloud is the AWS Lambda - event-driven service where AWS “runs your code in response to events”. It is a perfect fit for any backend jobs or scheduled tasks.¬†Unfortunatelly AWS Lambda currently supports code in Node, Python or Java. And it runs on Amazon Linux.¬†Thankfully, it looks like Microsoft is making .net for a cross platform world. Moreover, it looks like it would be possible to natively compile dotnet applications.

Javascript Encode on server side - Medium Trust Environment

It happens from time to time I have to get rid of those funky apostrophe in my server/javascript code. To do such kind of things I was using Microsoft Anti-Cross Site Scripting Library. By simply calling: public static string JavaSriptEncode(this string text) { return Microsoft.Security.Application.AntiXss.JavaScriptEncode(text, false); } Unfortunately, It doesn’t work in Medium trust environment - btw, why the hell i get stingy clients. After some time digging all over internet and trying to write it by myself I accidentally found a thing that I never believed to be there.

Handler Elmah Has a Bad Module Managedpipelinehandler in Its Module List

Elmah - awesome library for asp.net that enable to log exceptions (as well as those that end up with Yellow screen of death). It comes with a great module and a handler used to view error logs. It really helps a lot. I used that in literally every web project I have made. Yesterday, I was installing new project on fresh Windows Server 2008 R2. I ended up with an error: Handler “Elmah” has a bad module “ManagedPipelineHandler” in its module list.

Validate max file size during upload in asp.net mvc

Just a quick sketch. Validation is done as an Attribute (DataAnotations way). public class FileAttribute : ValidationAttribute { public int MaxContentLength = int.MaxValue; public string[] AllowedFileExtensions; public string[] AllowedContentTypes; public override bool IsValid(object value) { var file = value as HttpPostedFileBase; //this should be handled by [Required] if (file == null) return true; if (file.ContentLength > MaxContentLength) { ErrorMessage = "File is too large, maximum allowed is: {0} KB".FormatWith(MaxContentLength / 1024); return false; } if (AllowedFileExtensions !

NLog binaries compiled to run under Medium Trusted environment

To save any one hassle with downloading NLog, StructureMap sources, updating assembly info in order to allow it to be run under Medium Trust, compiling them I have decided to attach a copy of compiled binaries. Or, simply how to run Nlog on shared hosting (like GoDaddy and others). NLog for Medium Trusted environment Happy coding!

Weird exception (with the simplest solution) after playing with Entity Framework

I have been playing with Entity framework Code-First approach (this is definitely the way I am going to use for my next project, i love it). Anyway, doesn’t matter if it is Code-First or Database-First approach, from time to time I keep on getting an exception: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. It always takes few minutes to remember - what was that.

Manually forcing ELMAH to log exception

ELMAH is one of those projects that I use for literally ALL my own projects. It is an easy to implement error-logging component - for ASP.NET (MVC as well). The best thing about it is that it comes with web page that allows you to view all logged errors (even those of ‘yellow screen of death’), plus email notification or rss feed. wow ?! Okay, so ELMAH logs all of our unhanded exceptions… What about the case when you ‘catch’ exception but would still like to log it in ELAM defined medium.

How to implementing log in to site with Facebook account in ASP.NET MVC

I have decided to enable users that already have a Facebook account (who hasn’t ?!) to log on my site with their Facebook credentials. Process has shown to be pretty easy but It took me some time to figure out few things. I have decided to implement so called ‘Single Sign-On’ and I pretty much followed guildlines from http://developers.facebook.com/docs/guides/web. So, not to loose your precious time, let us start from the beginning.

LINQ Enumerable.Agregate with Path.Combine

Path.Combine accepts two parameters. Just two… So when we combine multiple path we have to deal with with nesting of Path.Combine: string rootDir = "/root/app"; string folder1 = "users"; string folder2 = "mike/upload"; string filename = "text.xml"; var path = Path.Combine(rootDir, Path.Combine(folder1, Path.Combine(folder2, filename))); There are 2 ways to handle this: 1. Use Enumerable.Agregate: string rootDir = "/root/app"; string folder1 = "users"; string folder2 = "mike/upload"; string filename = "text.xml"; var path2 = new string[] { rootDir, folder1, folder2, filename }.

Client Side Validation After Ajax Partial View Result in Asp Net Mvc 3

Now, as ASP.NET MVC 3 beta was finally released I have decided to give it a try. The most exciting thing that I have noticed is implementation of an idea of so called Unobtrusive JavaScript. This is for both Ajax helpers and Client Validation. And I have to admit that I just love it. I wll just copy and paste text from scottgu blog: Unobtrusive JavaScript and HTML 5: The AJAX and Validation helpers in ASP.

Getting ugly with BeginActionLink helper!

Have You ever had such a moment when the most stupid and trivial solution turns out to be the ONLY ONE that is logically suitable at the moment? When I had such a feeling today…. I am working on a module for one of huge web portals (not to mention which one). Part of that module is only accessible to users with administration permissions - as typical as it can be.

A Hint for Entity Framework Multi Join Performance Problem

How I have started my adventure with Entity framework Some of you may refer to one of my previous entries, when I was discussing tool I would use for my new web project. Look for (2. Database and ORM). I made a “brave” decision to choose Entity framework as my Object Relational Mapping tool. Well, I must say, i slightly regret this. To be honest, I would consider choosing other tools - or at least wait a little until more mature version of EF arrive (looking forward to play with it in .

VS2010 Beta 2 is out! For MS employees :/

I have just read that It looks like Microsoft employees are already playing with beta 2 of Visual Studio 2010. Nice, very nice. We want it too! Especially that it sucks to use beta 1 on old machine! And because You promised to fix some performance issues in next beta I desperately need that. Like now! Read here blog entry from Misfit Geek. Hope to download this version soon…

ASP.NET MVC 1.0 issue within HtmlHelper.GetModelStateValue method

It all started innocently… :) I had the simplest form ever. Just a few text inputs, and one checkbox. State of one of the text inputs was determined by status of one the checkbox. If checkbox was not checked (or “on”) input was set to be disabled. As simple as that. The problem arrived when someone was trying to view web site with javascript turned off. Because input was set disabled at initial stage there was no way to enable it - no matter if checkbox was checked or not.

ASP.NET MVC 2 Preview 1 released!

YES! YES! YES! Great news for all MVC lovers, check it out on Phil’s blog

Abandon ASP.NET WebForms!

Just abandon ASP.NET WebForms - the sooner You realize that - the better for You. At the begging I would like to say that I used to be a BIG fan of ASP.NET. Before my experience with Microsoft technology started I had some really bad time with php and mysql. But that was some long time ago - in the begging of this century. Then I started playing with ASP.NET - and I really dig into it.