Igor Kitsula - Developer

A Programmer Reference

  1  2  

Why ReturnUrl from login page doesn’t work and how to fix it

Common mistake or misunderstanding why login action doesn’t have ReturnUrl value, even if there is string parameter with value in the page URL. If you think about it more, you will get it – ReturnUrl  is in the page URL but not in the action URL of the login form. The trick is to pass this parameter to the form inputs or action URL parameters be submitted with login form request. It’s very easy to do with MVC.

Read more...

Using SQL Server for ASP .NET session state on hosting service provider

Can be several reasons why to use SQL Server for session state. In my case hosting service provider does not allow me to control application pool so user losing his session state from time to time and it’s very big issue. There are a lot of articles in Internet how to setup database to store ASP.NET session state, but no one explains how to setup it on a remote SQL Server database where you have no ‘sa’ rights. The problem with a standard InstallSqlState.sql script is that it tries to create SQL server job for cleaning up database from expired sessions.

Read more...

Create command line automated build for MVC app with msbuild 4 OR Visual Studio 2010 Publish command for msbuild Command line

I always wanted to have ability build or deploy my website with one run of the .bat or .cmd file. Of course there is software for this like Cruise Control or AntHill for example. But just for one small blog or website you don’t want to spend a lot of time for installing and configuring of these heavy tools.

So I always wanted to have "Publish" function from Visual Studio as a command line. And I found it! So let me share with you my experience how to build command line automated build for MVC web app.

Read more...

MVC Custom Error Pages

In previous article I shown you how to use log4net to log errors and redirect to custom error page. The problem in this approach is redirection. It’s not good for SEO to make redirection to custom error page.

Read more...

Versioning JavaScript and CSS files or How to update static files on client side

If you have enabled expiry headers, entity tags, etc. (and even if not), anyway most of the browsers have enabled cache. But how can we force client browser to load new version of JavaScript file or CSS static file? Especially if you did a change in any site specific static file. File from browser cache can broke behavior of website or/and design. So how to tell browser to load updated static file?

Read more...

How to Deploy an ASP.NET MVC 3 App to Web Hosting with "\bin Deployment"

If your hosting provider don’t support MVC 3 but have MVC 2 installed you still can deploy your web app. Solution is simple – MVC 3 files should be in Bin folder of your solution. Here is the list:


Read more...

How to: Turn on MVC compiled views or Turning on views compilation

Turning on views compilation will tell the compiler to compile your views and you will catch any errors (in views code) whenever you compile. Very handy and saves sometime. Unfortunately, it does add some time to the build process. If you have a lot of views, this could be lengthy, so you may want to disable this later.

Read more...

Image + ActionLink = Html.ImageActionLink

If you want to put image inside link using HTML.ActionLink you can use next nice implementation of extension method:

Read more...

ASP.NET MVC Razor - output HTML string non escaped

How do you show (safe) HTML saved in DB in a Razor view? It always escapes stuff like <.

Supposing your content is inside a string named mystring...

In releases from Beta 2 and earlier you can do:

@(new HtmlString(mystring))

In releases after Beta 2 you will be able to do:



MVC Handling and logging JavaScript errors

Most of browsers have window.onerror event which fired when JavaScript error occur. You can bind your function to this event which receives three parameters: message, URL and line number where error raised.

Let’s create function which will be graceful handling of JavaScript errors, send in poor JavaScript AJAX request all information about error and then we can log it with Log4Net and send email notice.

Read more...

  1  2