DCSIMG
Rotem Bloom's Blog

Rotem Bloom's Blog

Share knowledge on .NET and web development

News

About Me

Glad to help and share knowledge on .NET and also huge fan of Dream Theater.

Contact me via messenger

View Rotem Bloom's profile on LinkedIn

Dream Theater Pics

Blogs I Read

Minifying HTML With ASP.NET MVC And Razor

Hi,

I read nice article with cool solution for Minifying HTML With ASP.NET MVC And Razor.

You can read more here.

You can start use it in you MVC projects, for 25% smaller HTML pages.

firefox not executing javascript on back button

Hi,

firefox has a cache behavior that uses in-memory caching for entire Web pages, including their JavaScript states, for a single browser session.

This can cause to unexpected javascript and HTML behavior when pressing on the browser back button.

For example:

  1. PageLoad will not fired
  2. javascript code will not executed
  3. DHTML that was created by JavaScript will be shown

and more...

In case firefox cache is something you want to prevent, Below are some common programmatic reasons that a page will not be cached by firefox:

  • the page uses an unload or beforeunload handler
  • the page sets "cache-control: no-store"
  • the page sets "cache-control: no-cache" and the site is HTTPS.
  • the page is not completely loaded when the user navigates away from it
  • the top-level page contains frames that are not cacheable
  • the page is in a frame and the user loads a new page within that frame (in this case, when the user navigates away from the page, the content that was last loaded into the frames is what is cached)
  • Code example for prevent page caching on firefox:

    window.addEventListener('pageshow', PageShowHandler, false);
    window.addEventListener('unload', UnloadHandler, false);

    function PageShowHandler() {
    window.addEventListener('unload', UnloadHandler, false);
    }

    function UnloadHandler() {
    window.removeEventListener('unload', UnloadHandler, false);
    }

    You can read more here.

    Rotem

    ASP.NET MVC Razor CSS and Javascript Compress and Manager

    Hi,

    If you are ASP.NET MVC Razor developer and you are looking for a nice solution to Combine, Compress and Manage your CSS and JavaScript files,

    Well SquishIt can fit your needs.

    Razor Code Sample:

    @MvcHtmlString.Create(
      SquishIt
    .Framework.Bundle.Css()
       
    .Add("~/media/css/reset.css")
       
    .Add("~/media/css/style.less")
       
    .Add("~/media/css/handheld.css")
       
    .Render("~/media/css/combined_#.css"))

    @MvcHtmlString.Create(
      SquishIt
    .Framework.Bundle.JavaScript()
       
    .Add("~/media/js/geo.js")
       
    .Add("~/media/js/jquery-1.4.4.js")
       
    .Add("~/media/js/jquery.unobtrusive-ajax.js")
       
    .Add("~/media/js/jquery.validate.js")
       
    .Add("~/media/js/jquery.validate.unobtrusive.js")
       
    .Render("~/media/js/combined_#.js"))

    Output looks like this:

    <link rel="stylesheet" type="text/css" href="/media/css/combined_312454.css" />
    <script type="text/javascript" href="/media/js/combined_312454.js"></script>

    You can read more here.

    We are using SquishIt on the company I work and it look like a really nice and useful solution.

    I hope you will find it useful on your company or project also :-)

    Yours,

    Rotem

    האתר של ארטיזון עלה לאוויר בטכנולוגית ASP.NET MVC 3.0

    היי,
    היום העלינו את האתר של ארטיזון לאוויר. האתר נכתב מחדש והועבר מטכנולוגיה של SILVERLIGHT ל-ASP.NET MVC 3.0
    אני חייב לציין שמיקרוסופט עשו עבודה והחלטה מעולה לצאת עם ה-MVC וכתיבת האתר בטכנולוגיה זו עשתה לנו חיים קלים בהפרדה לשכבות, שליטה על קוד ה-HTML, אין שמירה של VIEWSTATE ושאר ירקות רקובים. 
     
    אומנם האתר מיועד לקנייה רק לתושבי דאלאס ארה"ב אבל אשמח אם תכנסו ותגידו מה דעתכם על האתר ובכלל תראו אתר LIVE שנכתב כולו ב-ASP.NET MVC 3.0
    בנוסף אנחנו עדיין צחפשים אנשי .NET חזקים שיצטרפו לחברה.
     
    https://www.artizone.com/zone
     
    ביי רותם

    ASP.NET MVC 3.0 jquery unobtrusive ajax Failed on IE 8

    Hi All,

    I'v notice a strange behavior when working with ASP.NET MVC 3.0 jquery unobtrusive ajax on forms HTML element on IE (internet explorer) 8.

    Razor code example for generating ajax call on a form element using unobtrusive ajax: @using (Ajax.BeginForm("MyAction", "MyController",  new AjaxOptions { HttpMethod = "POST" })){

    Sometimes (not always) i'm getting a javascript error with the message "Falied" that come from the javascript file jquery.unobtrusive-ajax.js:

    The line is:

    $("form[data-ajax=true] :submit").live("click", function (evt) {

    Well the only solution I can find is to modify jquery.unobtrusive-ajax.js code with the following code:

    $("form[data-ajax=true]").find("submit").live("click", function (evt) {

    This fix the javascript error and the ajax call works always on IE 8.

    Until now I can explain why the error happened only on IE 8 and was not reproduce permanently on each page refresh.

    If it happened to you, I would be happy to know if you find other solution to this strange problem.

    Rotem

    How to decide which WCF binding to choose??!!

    Hi,

    I decided to share a nice diagram that can help you decide which WCF binding you should choose for your application or SOA architecture.

    (If you can see the entire image you can download it using right click and "Save Picture As...")WCF Binding

     

    ארטיזון עושים האחים בלוז

    היי,
    בארטיזון החברה שאני עובד עשינו LIP DUB לשיר של האחים בלוז.
    כנסו תראו כמה כיף לעבוד פה ואני מזכיר לכם שוב שעדיין מחפשים פה אנשי דוט נט ו-WEB.
    ראש צוות דוט נט, ומפתחי דוט נט WEB.
    אז שלחו לי קורות חיים:
    rotemb@artizone.com
     
     

    חברת ארטיזון מגייסת עובדים

    חברת ארטיזון מחפשת אנשי דוט נט מנוסים וחזקים:
    1. מומחה HTML, CSS, JAVASCRIPT להובלת כול פיתוחי החברה בתחום ה-UI.
    2. ראש צוות דוט-נט תותח ומנוסה עם ידע וניסיון מעמיק באפליקציות WEB מרובות משתמשים.
    3. תותחי דוט-נט שמחפשים לעבוד בטכנולוגיות החדשות ביותר.
     
    בארטיזון עובדים בדוט-נט 4.0 עם TFS וכול הטכנולוגיות החדשות כולל סילוורלייט ותכנון לעבודה עם AZURE.
    מי שנראה לו מעניין או יש לו חברים שמחפשים מוזמן לשלוח לי קורות חיים אל:
    rotemb@artizone.com
     
    רותם

    שאלה לתותחי SQL ו-DATABASE

    שלום לכולם,
    יש לי שאלה לכול מומחי ה-SQL ו-DATABASE והשאלה היא:
    רציתי לדעת מה הגישה המקובלת והמומלצת יותר היום לעבודה עם DATABASE שאמור להיות עמוס מבחינת גישות SQL ונתונים (נגיד DB כמו של פייסבוק או אמזון).
    1. האם לעבוד ב-DB שונים לכול שירות? כלומר: DB למשתמשים, DB למוצרים, DB להזמנות וכו'... ככה אין כמעט JOIN אבל יש לחבר את התוצאות מהשירותים השונים במקרה שיש צורך ב-JOIN.
    2. האם בכול זאת עדיף לעבוד עם DB אחד לבצע JOIN שיכולים להיות מורכבים ורק להפריד את הנתונים ל-DB שונים לפי לוגיקה מסויימת
    3. האם יש גישה אחרת מומלצת
     
    ברור לי כמובן שיש לעבוד עם מנגנוני CACHE כדי למנוע גישות ל-DB כמה שאפשר אבל עדיין אי אפשר להתחמק משמירת ושליפת הנתונים מה-DB. מה עושים אתרים גדולים היום כדי לפתור בעיות ביצועים ב-DB גדולים ועמוסים.
    תודה רותם

    Jquery TreeView with RTL support

    Hi All,

    Well after month of silent (7 I think) I got back with a new post on Jquery TreeView.

    First you can download the plugin from here. I must say this plugin is amazing very fast even with large trees.

    The problem of Jquery TreeView is the lack of RTL (Right To Left) support for languages like: Hebrew, Arabic etc...

    If you got the same problem I have and you need Jquery TreeView RTL version you can download it from my blog right here.

    To the AJAX fans I also add a nice cool ajax application example you can download it from here.

    Hope it helps

    Cheers

    Rotem

    Unlocker the tool that must for developers

    Hi,

    Have you ever bump into messeges like:

    • Cannot delete file: Access is denied
    • There has been a sharing violation.
    • The source or destination file may be in use.
    • The file is in use by another program or user.
    • Make sure the disk is not full or write-protected and that the file is not currently in use.

    Well when such cases happeneds you really want to know which application lock your Files or Folders.

    The Unlocker is the solution for you.

    Just look for "unlocker" in Google or Bing or you can download it from here.

    Bye Rotem

    How to find and reproduce bugs in multi thread applications - CHESS is to tool you must use!!!

    Hi All,

    If you want to test and reproduce multi thread applications bugs there is a new tool from Microsft called: CHESS.

    CHESS is a tool for finding and reproducing Heisenbugs in concurrent programs. CHESS repeatedly runs a concurrent test ensuring that every run takes a different interleaving. If an interleaving results in an error, CHESS can reproduce the interleaving for improved debugging. CHESS is available for both managed and native programs.

    Great movie that explain CHESS: An Automated Concurrency Testing Tool

    You must adopt this tool for your future multi threaded (concurrent programs) programs.

    More information on Threading in C# can be found on Joseph Albahari great article here.

    Expert Days 2010 יוצא לדרך שווה ללכת

    ימי המומחים מה שידוע גם כ-Expert Days יוצא לדרך ב-22 לנובמבר.
    אז בתור אחד שהיה בכנס בשנה שעברה אני ממליץ בחום ללכת לכנס למסלול שמעניין אתכם.
    השנה לפי מה שראיתי באתר הכנס שמו דגש על הטכנולוגיות החדשות שאמורות לצאת בשנה הקרובה, לכן אני חושב שכדאי ללכת ולהתעדכן בטכנולוגיות החדשות שאמורות לצאת בשנה הקרובה.
     

    מסלולים

    מסלול המה חדש בויז'ואל סטודיו 2010 ודוט-נט 4.0 סוקר את כל
    החידושים שיהיו בשנת 2010. המסלול מנוהל ע"י ורדי אייל.
    מסלול הווב מכסה את כל הנושאים החדשים בתחום הווב שיהיו בויז'ואל סטודיו 2010.
    המסלול מנוהל ע"י לנגלייבן ליאון מחברת SRL.
    יש הרבה שיטות להתחבר למסד נתונים, אך מהי הדרך הטובה ביותר לארגון?
    במסלול זה תיחשפו לכל הטכנולוגיות החדשות בתחום. המסלול מנוהל ע"י ורדי אייל.
    WPF או Silverlight זאת השאלה? מסלול זה מביא את כל הטכנולוגיות החדשות
    לפיתוח ממשק משתמש. המסלול מנוהל ע"י קוגמן גל.
    ויזואל סטודיו 2010 מביא איתו מהפכה בתחום התקשורת, ע"י שיפור משמעותי של
    שתי טכנולוגיות קיימות WCF ו-WF והשילוב בניהם. המסלול מנוהל ע"י ורדי אייל.
    מסלול SQL Server 2008 מכסה מקצה לקצה את כל התחומים של מסד הנתונים.
    המסלול מנוהל ע"י גלנצר גיא מחברת Madeira Information Technologies.
    טכנולוגית ה- CRM של מיקרוסופט נכנסה השנה למספר רב של ארגונים, כמערכת CRM וככלי
    פיתוח ארגוני. המסלול מנוהל ע"י ארדיטי יניב מחברת E4D Solution.
     
    פרטים נוספים באתר http://www.expertdays.co.il/
     
    תהנו רותם
     

    Sending .NET configuration section over the wire using WCF

    Hi,

    Have you ever needed to implement configuration sections for the application configuration file? Well probably you have.

    Let's say you want to read the configuration section from your *.config file and send it thru WCF service. The default behavior when working with configuration object is use the System.Configuration namespace that doesn't support WCF.

    So the question is what can we do?

    A nice solution is to use the IConfigurationSectionHandler interface and mark the section implementation as a DataContract.

    It will be something like:

    [DataContract]

        public class MyConfigurationSectionHandler : IConfigurationSectionHandler

        {

            #region IConfigurationSectionHandler Members

     

            public object Create(object parent, object configContext, System.Xml.XmlNode section)

            {

                DataContractSerializer xs = new DataContractSerializer(typeof(MyConfigurationSectionHandler));

     

                using (XmlNodeReader xnr = new XmlNodeReader(section))

                {

                    try

                    {

                        var configSection = xs.ReadObject(xnr, false) as MyConfigurationSectionHandler;

                        if (configSection != null)

                        {

                            Applications = configSection.Applications;

                        }

                        return this;

                    }

                    catch (Exception ex)

                    {

                        string s = ex.Message;

                        Exception iex = ex.InnerException;

                        while (iex != null)

                        {

                            s += "; " + iex.Message;

                            iex = iex.InnerException;

                        }

                        throw new ConfigurationErrorsException(

                        "Unable to deserialize an object of type \'" + GetType().FullName +

                        "\' from  the < " + section.Name + "> configuration section: " +

                        s,

                        ex,

                        section);

                    }

                }

            }

     

            #endregion

     

            [DataMember(Name = "applications")]

            public Application[] Applications { get;set; }

        }

     

        [DataContract(Name = "application")]

        public class Application

        {

            [DataMember(Name = "name")]

            public string Name { get; set; }

        }

    An example for an appropriate configuration section can be something like:

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

      <configSections>

        <section name="MyConfigurationSectionHandler" type="DataContractConfiguration.MyConfigurationSectionHandler, DataContractConfiguration"/>

      </configSections>

      <MyConfigurationSectionHandler xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DataContractConfiguration">

        <applications>

          <application>

            <name>App1</name>

          </application>

          <application>

            <name>App2</name>

          </application>

        </applications>

      </MyConfigurationSectionHandler>

    </configuration>

    Now we can use the ConfigurationManager to get our configuration object that can also be send over the wire using WCF.

    MyConfigurationSectionHandler section = (MyConfigurationSectionHandler)ConfigurationManager.GetSection("MyConfigurationSectionHandler");

    I also add small application as an example you can download from here.

    Enjoy :-)

    Rotem

    Insert and Update pattern for multiple threads application with SQL Server

    Hi, 

    Have you ever try to insert a row in to a SQL table if the key does not exist and update a row if a key exists. Well this is very common scenario.

    Usually you would achieve this goal by writing SQL like:

    if exists (select * from TestTable where ID = @id)

    begin

        update TestTable set myCount = myCount+1  where ID = @id

    end

    else

    begin

      insert into TestTable values (@id, 1)

    end

    This code will work fine for single threaded applications but will not work for multiple threads application. To solve this issue you need to handle primary key violations and fix up the transactional integrity of the batch.

     So now let's see the solutions:

    Option 1:

    begin tran

    if exists (select * from TestTable with (updlock,serializable) where ID = @id)

    begin

      update TestTable set myCount = myCount+1 where ID = @id

    end

    else

    begin

      insert TestTable (ID, myCount) values (@id, 1)

    end

    commit tran

    Option 2:

    begin tran

      update TestTable with (serializable) set myCount = myCount + 1 where ID = @id
    if @@rowcount = 0

    begin

      insert TestTable (ID, myCount) values (@id,1)

    end

    commit tran

    That's all.

    Enjoy Rotem

    More Posts Next page »