Sai Stuff to Developers

December 14, 2016

How to crack browser cache issue?

Filed under: Client Side Applications — tosaik @ 5:10 pm
Tags: , ,

When we access any web application, our browser hits the server and gets all the required resource/content files and cache those for further requests to avoid latency and improve performance of the application.

This browser cache will be a problem in case if there is any changes to these resource or content files at server end, and these changes should reflect whenever user visit this application for the next time. But in most of the cases the browser will check for these files in their cache. If it founds then it won’t get latest files from server and lost the latest changes at client end.

To solve this issue we need to inform the browser that there are some changes to the files (JavaScript or CSS or images) and this time pick it from the server and update in your cache. To do so we need to append some query string kind of text at the end of each file, such that every time this string changes browser/cache-system treats it as a new file and requests the server for the latest version.

Following are the different approaches can be used.

Static Approach

Whenever the files are updated, all references to the files could be manually updated to increment a version number as follows.

<script type="text/javascript" src="~/Scripts/config.js?v=1"></script>

If there is any updates now increment the version from 1 to 2 as below

<script type="text/javascript" src="~/Scripts/config.js?v=2"></script>

Note: Instead of number we can have any number or string which uniquely identifies it for example may be any hash string or GUID string.

Advantages

  • Browser will request for new file request in case there is a change in version string. If there is no change then it will get from its cache system and improves performance.

Disadvantages

  • If we forget to update or change the version string at any file then the functionality might not work as expected. This can be avoided in case we are using any bundling tools like gulp or web pack.

Dynamic Approach

In this approach, developer always appends current server date time ticks such that every time a browser treat it as a new request and always get the latest version from the server irrespective of files updated or not.

MVC:  

<script type="text/javascript" src="~/Scripts/config.js?v=@(DateTime.Now.Ticks)"></script>

Advantages

  • No need to worry of forgetting to update the version string as every time this will be changed automatically irrespective of changes or updates.

Disadvantages

  • There will be lot of performance issue as for every request client browser should request for the file(s).
  • It will use lots of bandwidth and especially on slow networks.
  • Not much utilizing the browser cache system feature.

 

Happy Coding 🙂

September 3, 2014

Problem with ASP.NET using MySQL Connecting through ODBC Driver in some Hosting Servers

Filed under: DotNet — tosaik @ 9:48 am
Tags: , , , , , , ,

Recently i hosted one of my asp.net 4.0 application which is using MySQL as backend and i decided to use MySQL .NET connector to access the MySQL server. I hosted one of the local server and its works fine but i got some consistency issues with my local server and decided to shift my application to GoDaddy which they ensure our application will be 24 X 7 in active.

I moved the application successfully but when i try to run the application through browser i cannot able to connect to database when i dig in to the issue through my logs i came to know that GoDaddy doesn’t support MySQL .NET connector DLL because GoDaddy will run only components and application which are Fully Trusted. When i read the blogs regarding this DLL i came to know Oracle has built this component as partial trusted (medium trust) which means i cannot use anymore with my application to host in GoDaddy. But here i have 2 options

  1. Need to place my MySql .Net connector component to the GAC of GoDaddy server.
  2. Need to remove using MySql .Net connector component in my application.

In the above options, option-1 GoDaddy doesn’t allow me to do so. Now i have only option-2, i removed code related to MySql .Net connector component and removed the reference to it and i try to connect mySQL database through ODBC (Object Database Connector). Which i successfully implemented in my application and working fine on my local computer and i updated the same over the hosting server (in my case GoDaddy), Interestingly still i am unable to connect to the Database, Now when i log my application to find the root cause of the issue, following are the error its throwing:

Request for the permission of type ‘System.Data.Odbc.OdbcPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

OOPS, i realized that GoDaddy also need my application to be fully trusted which i need to configure in my application via. web.config in System.web section as shown below:

 

<trust level="Full"/>

Once i changed this and made my application full trusted with this simple configuration change, My Application working like a charm.

The reason behind on writing this post is, i worked nearly 5 hrs to fix this issue and i cannot find any direct help from any blogs so i decided to keep this information in my blog to make others time save.

Thank You,

Happy Coding…..

 

January 25, 2014

Happy Republic Day – 2014

Filed under: General — tosaik @ 1:41 pm
Tags:

I Wish you all a Happy Republic Day 2014 and please find a speech over here as we need to know something about Republic day special… Please find it in the below link

 

Happy Republic Day Speech 2014

 

Thank You…. 🙂

October 29, 2013

Windows Store apps for Absolute Beginners with C#

Filed under: DotNet,Windows Apps — tosaik @ 8:12 am
Tags: ,

In this lesson Bob kicks off the series talking about the organization, required setup and goals of the lessons, and provides some motivation and guidance for getting started.   Resources C# Fundamentals: Development for Absolute Beginners.
source: channel9
<!–

October 1, 2013

Launched New Technology Site developersfusion.com

Hi Friends,

I have recently launched a new Technology WebSite www.developersfusion.com .

 

About Developers Fusion

Developers Fusion is a place where the professionals can share their experience and views contributing knowledge to the developer’s community. A successful professional, learns, explores, matures and finally contributes.

The developersfusion.com works with an idea, that has a big vision of bringing Technology to the cozy of your room wherever you are, and make learning comprehensive and exploring Technology real simple and easy.

We are dedicated in providing our Readers quality implementation, education, documentation and solutions. Our ultimate goal is to provide our readers with appropriate solution to their technical questions and needs. The developersfusion.com personifies the passion for Software Technology, delivers power in the technology and the skills associated with it, and enhances the productivity of professionals who shape the software field.

The developersfusion.com believes that it is vital to make learning Technology easy and effective and help its readers, technical breakthroughs in their future career along with other sessions that make them more informed about things that happen around them.

The Articles section lists articles published from different professionals enabling our readers to learn what’s new in the market and also the experience of the author. The FAQs section enables readers to prepare for answering the interview questions shot at them.

Our Vision

Bringing Technology to the cozy of every developer room wherever you are, and make learning comprehensive and exploring Technology real simple and easy.

Our Goal

Our ultimate goal is to provide our readers with appropriate solution to their technical questions and needs.

 

Hope all you make my new website a grand success by visiting posting and participating in forums etc…,

 

Regards,

Sai Kumar K

April 23, 2013

Finding count of Prime Numbers contain for a given Number

Filed under: DotNet,OOPS Languages — tosaik @ 11:44 am
Tags: , , , ,

Recently I need to add some of this kind of functionality in my on-going project and for that i wrote some simple method to returning the count of prime Numbers contain for given input number…. so i just want to have this snippet in front of you… Hope it will help as.. as it is simple but while implementing it kills our brain surly 🙂


static int getNumberOfPrimes(int N) {
	
    int count = 0;
    bool res = false;
    for(int i=2;i<=N;i++)
    {
        res = false;
        for(int j=2;j<=i;j++)
        {
            if(i%j == 0 && i!=j)
            {
                res = true;
            }
        }
        if(!res)
            count++;
    }
    
    return count;

}

Hope it will help for you 🙂

December 4, 2012

Unobtrusive Validation in Framework 4.5 Data Validations

Filed under: DotNet — tosaik @ 7:41 am
Tags: , , , , ,

Today I was working on ASP.NET web application on framework 4.5; I came across a strange error which I never experienced in my past working on earlier environments of dot net framework and that is error titled

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for ‘jquery’. Please add a ScriptResourceMapping named jquery(case-sensitive).

When I dig in to this issue and found the root cause of this issue and here my case study about this issue…

Unobtrusive Validation is a new concept in Framework 4.5, and this is by default enables when we create a new ASP.NET web application by adding one of the key in a Web.Config->appsettings section as below

 <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />

What exactly this validation does for us

Forms with complex data including validators tend to generate too much JavaScript code in the page, which can represent about 60% of the code. With unobtrusive validation enabled, your HTML code will look cleaner and tidier.

For example we will compare the HTML code generated by both configurations.

Case-1:

Steps to create the sample application without unobtrusive validation enabled (default for all earlier versions)

1)      Open Visual studio 2012 IDE and create a new Web Application as shown below

UV1

 

 

 

 

 

 

 

 

2)      Now Press F5 to start the web application.

3)      Right-click on the browser page, and select View Source option to open the HTML code generated by the application.

4)      Scroll through the page source code and notice that ASP.NET has injected JavaScript code in the page to perform the validations and show the error list.

UV2

5)      Select the Script tab and expand the “{your current page}.aspx” combo to see all the referenced scripts. Notice that there are no references to the jQuery library. The validations are performed using the Microsoft Ajax Libraries together with JavaScript code injected within the page.

Case-2:

Steps to create the sample application with unobtrusive validation enabled (default for all new version(s))

1)      Now you will enable unobtrusive validation. Open Web.Config and locate ValidationSettings:UnobtrusiveValidationMode key in the AppSettings section. Set the key value to WebForms.

<appSettings>
    <add key="aspnet:uselegacysynchronizationcontext" value="false" />
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms"/>
</appSettings>

2) Open the Global.asax.cs file and add the following using statement

using System.Web.SessionState;
using WebFormsLab.Model;
using System.Web.ModelBinding;

3)      Within the Application_Start method of the Global.asax.cs file, add the following code

ScriptResourceDefinition myScriptResDef = new ScriptResourceDefinition();
myScriptResDef.Path = "~/Assets/Scripts/jquery-1.7.1.min.js";
myScriptResDef.DebugPath = "~/Assets/Scripts/jquery-1.7.1.js";
myScriptResDef.CdnPath = "http://code.jquery.com/jquery-1.7.1.min.js";
myScriptResDef.CdnDebugPath = "http://code.jquery.com/jquery-1.7.1.js";
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);

4)      Open Site.Master. Add the code below to include a ScriptManager on the page to include a script reference to the jQuery client library.

<form runat="server">
<asp:ScriptManager ID="uxScriptManagerMasterPage" runat="server" EnableCdn="False">
<Scripts>
    <asp:ScriptReference Name="jquery" />
</Scripts>
</asp:ScriptManager>


5)      Now Press F5 to start the web application.

6)      Right-click on the browser page, and select View Source option to open the HTML code generated by the application. Notice that by enabling the unobtrusive validation ASP.NET has replaced the injected JavaScript code with data- *attributes.

UV3

Don’t want this feature enabled?

Simply add the following setting in your AppSettings section in your web.config if it doesn’t exist. If already exist make value as “none” as shown below

 <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

Conclusion:

With Unobtrusive validation we reduce the unnecessary JavaScript code generation for all validation controls by asp.net runtime. As if we enable this validation the asp.net runtime by default get and use the jquery environment to perform these validations through this we can have least overhead of unwanted JavaScript code in our HTML page and it also effect the improvement in the performance and take less time in rendering and loading your pages.

I Hope you got advantage of this article…

Please drop a comment if you like it…

Thanks Happy Coding  🙂

November 30, 2012

Error: the exec task needs a command to execute in visual studio

Filed under: DotNet — tosaik @ 6:02 am
Tags: , ,

Got Error:

the exec task needs a command to execute in visual studio

Solution:

This is a common issue in visual studio and this error could be a cause when we add/remove the Pre-build event command line(s) and in Post-build event command line(s)…

Generally visual studio gives every line as a new command line to the command prompt to execute with “EXEC” command, if we by mistake keep any empty line… visual studio also send this empty line as a new command line and command prompt throws an error as it expects a valid command but what we sent is not a valid command to it…

as you can see the below image as i selected the empty line which by mistakenly entered in the project->properties Build Events Tab section…

ExecError

Hope this solution work for you….

Happy Coding 🙂

November 19, 2012

BadImageFormatException: Could not load file or assembly ‘x’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

Filed under: DotNet — tosaik @ 12:01 pm
Tags: , , , , ,

Exception:

BadImageFormatException: Could not load file or assembly ‘x’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

Solution:

Hi Recenty i had faced this exception and when i digg in to this issue…. and i forgot that when we are using any COM Interop DLL components in our .EXE application we need to target the respective .EXE application platform as x86

Please change the target platform to x86 in the properties section and build again before using it..

 

 

 

 

 

 

 

Hope this solution works for you too………

October 22, 2012

Download: Visual Studio Express 2012

Filed under: DotNet — tosaik @ 11:02 am
Tags: , , , ,

Visual Studio Express 2012(Free)

Microsoft Visual Studio Express 2012 for Web is a free and robust development environment for building, testing, and deploying web applications across the Microsoft Web Platform. After installation, you can try this product for up to 30 days. You must register to obtain a free product key for ongoing use after 30 days.

Download Here

Visual Studio 2012 Express for Windows Desktop(Free)

You can use Visual Studio Express 2012 for Windows Desktop to build powerful desktop apps in C#, Visual Basic, and C++. You can target client technologies such as Windows Presentation Foundation (WPF), Windows Forms, and Win32. After installation, you can try this product for up to 30 days. You must register to obtain a free product key for ongoing use after 30 days.

Download Here

Happy Coding 🙂

Next Page »

Blog at WordPress.com.