Tagged "aspnet"

Redirect to new domain after rebranding with IIS Url Rewrite Module

Client has a bunch of domains and and websites. Because They have decided to change company’s name recently I was asked to proceed with chanage of domain names as well. After few weeks of constantly informing visitors about planned changed We decided that it is a good time to abandon old domains and redirect visitors to new ones. In order to “be okay” with google (their page ranks, indexed pages and so on) we make those redirects permanent (301 Moved Permanently as a response status code).

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!

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.

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.

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.