Wednesday, January 6, 2016

ASP.NET 5 folder structure

Hi All,

In ASP.NET 5 Microsoft targeted to change the solution folder structure.  Here is the sample solution structure.



The first thing you may notice about this new structure is that it includes a Solution Items folder with a global.json file, and the web project itself is located within a src folder within the solution. The new structure also includes a special wwwroot folder and a Dependencies section in addition to the References section that was present in past versions of ASP.NET (but which has been updated in this version). In the root the project there are also several new files such as bower.json, appsettings.json, gulpfile.js, package.json, project.json, and Startup.cs. You may notice that the files global.asax, packages.config, and web.config are gone. In previous versions of ASP.NET, a great deal of application configuration was stored in these files and in the project file. In ASP.NET 5, this information and logic has been refactored into files that are generally smaller and more focused.

global.json file

The global.json file is used to configure the solution as a whole. It includes just two sections, projects and sdk by default.

The projects property designates which folders contain source code for the solution. By default the project structure places source files in a src folder, allowing build artifacts to be placed in a sibling folder, making it easier to exclude such things from source control.

The sdk property specifies the version of the DNX (.Net Execution Environment) that Visual Studio will use when opening the solution. It’s set here, rather than in project.json, to avoid scenarios where different projects within a solution are targeting different versions of the SDK

Dependencies

Now MSDN maintaining client side and server side dependencies/references as a separate folders

Dependencies folder : This will be used to maintain client side dependencies with the help of bower and node.js

References will have server side dependencies

bower.json : Client side packages/dependencies configuration file. It works with bower (a client side framework manager)

wwwroot : It contains the static files like images, scripts etc







Sunday, May 11, 2014

Disable model validations while submitting the form in MVC

Add below line in the top of the view.
@{
           Html.EnableClientValidation(false);
    }

Friday, March 28, 2014

No exports were found that match the constraint :ContractName Microsoft.VisualStudio.Utilities.IContentTypeRegistryService


Issue description : 

No exports were found that match the constraint:ContractName
Microsoft.VisualStudio.Utilities.IContentTypeRegistryService
RequiredTypeIdentity
Microsoft.VisualStudio.Utilities.IContentTypeRegistryService

Solution : removing all the files from following visual studio ComponentModelCache folder

COMPONENT MODEL CACHE folder location : C:\Users\{YourUserName}\AppData\Local\Microsoft\VisualStudio\11.0\ComponentModelCache

Friday, February 28, 2014

LESS : Dynamic CSS language

Recently come across the using LESS in one of my project. LESS looks very cool and provides the programming capabilities to CSS. Like using LESS in CSS, we can define variables, functions and much more and reuse them across the multiple css pages.

By default every CSS page is a less page.

We can achieve the LESS in a project in two ways.
1.Client side.
2. Server side.

Client side: It will costs the performance cost. Because when ever user requests a page browser needs to convert css file to LESS.

Server Side : when you add the LESS the less at server side it will automatically converts the CSS to LESS while building the application.

You can download the "dotless" package from Nuget.

For more Information, Please refer below reference urls

LESS -> http://lesscss.org/
LESS in dot net -> http://www.dotlesscss.org/

HAPPY CODING :)

Sunday, January 19, 2014

How long the view location will be cached in MVC?

The default cache is 15min.

we can extend this using follwing code in Global.asax


var viewEngine = new RazorViewEngine
                         {ViewLocationCache = new DefaultViewLocationCache(TimeSpan.FromHours(24))};
    ViewEngines.Engines.Clear();
    ViewEngines.Engines.Add(viewEngine);

Monday, November 11, 2013

New features in .NET 4.5


  • Async and wait 
  • Zip Compression
  • Regex timeout
  • Improvised garbage collector
  • Profile optimization (Improved startup performance)
  • Set default culture to App Domain  (helpful in working on multi threaded environment)
  • Array support more than two gigabyte size
  • Asynchronous HTTP Modules and Handlers.
  • New Request Validation features in Asp.Net 4.5

Saturday, August 24, 2013

What are the new features introduced in MVC4




  1. ASP.NET Web API
  2. Enhancements to default project Templates
  3. Mobile Project Template
  4. Display Modes
  5. JQuery Mobile
  6. View Switcher
  7. Browser Overriding
  8. Task Support For Asynchronous controller
  9. Empty Project template

FIND() selector in Jquery


To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.
find() lets you filter on a set of elements based on a selection you've already made. For example if you wanted to set the back-ground color to all the spans inside a div, you could write:

$('#testDiv').find('span').css('background-color', 'red');

We can do the same by using below syntax
$('#testDiv span').css('background-color', 'red');


Here “testDiv” is a div tag.


Find selector is a much faster comparative to above one.

Identifying the elements by attribute values in Jquery

$(‘element[attribute=”value”]’): Selects all elements that have the specified attribute with a value exactly equal to a specified value.
Ex:  $('span[id="spnTest1"]').css('background-color', 'red');

$(‘element[attribute^=”value”]’): Selects all elements that have the specified attribute with a value beginning with specified value. The comparison is case sensitive.
Ex: $('span[id^="span"]').css('background-color', 'blue');

$(‘element[attribute$=”value”]’): Selects all elements that have the specified attribute with a value ending with specified value. The comparison is case sensitive.
Ex: $('span[id$="test3"]').css('background-color', 'yellow');

$(‘element[attribute*=”value”]’): Selects all elements that have the specified attribute contains sub string of specified value. The comparison is case sensitive.
EX: $('span[id*="test"]').css('background-color', 'green');

Basic selectors in Jquery

Identifying the element by tag  name
Ex: $('p') -> selects all paragraphs in the document

Identifying the element by ID
Ex: $(‘#divUser’) -> selects a DOM element which contains ID as “divUser”.

Identifying  the element by class

Ex: $(‘.divUser’) -> selects a DOM element which contains class as “divUser”.

Why to go with Editor Templates instead of partial views in MVC?

The problem with partials is that they do not preserve the navigational context. This means that any input fields that you might have put inside this partial will have incorrect names and the default model binder will not be able to retrieve the values back when you POST.


To make partial views to preserve the values while doing the http post we need to pass the top level model(parent view model) to partial view.

Parse the Sql query with out executing it.

declare @sql nvarchar(max)
set @sql = 'select * FROM Students'
declare @testsql nvarchar(max)
declare @result int =1
set @testsql = N'set parseonly on; ' + @sql
BEGIN TRY
exec @result = sp_executesql @testsql
END TRY
BEGIN CATCH
PRINT 'ERROR’
END CATCH
Select @result
-- If it worked, execute it
if @result = 0
begin
exec sp_executesql @sql
end

Adding a custom Jquery function to check whether a element exists in a html page or not using Jquery

Please add the below code your custom .JS file

(function($) {
    if (!$.exist) {
        $.extend({
            exist: function(elm) {
                if (typeof elm == null) return false;
                if (typeof elm != "object") elm = $(elm);
                return elm.length ? true : false;
            }
        });
        $.fn.extend({
            exist: function() {
                return $.exist($(this));
            }
        });
    }
})(jQuery);

Usage
------------
// With ID
$.exist("#eleID");
// OR
$("#eleID").exist();

// With class name
$.exist(".class-name");
// OR
$(".class-name").exist();

// With just a tag // Probably not best idea as there will be other tags on the site
$.exist("div");
// OR
$("div").exist();

Friday, March 1, 2013

How to override IIS error pages with the custom pages in MVC

First we should turn off custom error pages in <system.web> section:


<system.web>
    <customErrors mode="Off" />
</system.web>

And then enable it <system.webServer> section:

<system.webServer>
    <!-- Custom Error Pages -->
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" subStatusCode="-1" />
      <remove statusCode="500" subStatusCode="-1" />
      <error statusCode="404" path="/Error/404" responseMode="ExecuteURL" />
      <error statusCode="500" path="/Error" responseMode="ExecuteURL" />
    </httpErrors>
</system.webServer>