Aug 3, 2016

Passing data from the container (cshtml or a partial view) to the inner partial view

If you just render a partial with just the partial name:
@Html.Partial("_SomePartial")

It will actually pass your model as an implicit parameter, the same as if you were to call:

@Html.Partial("_SomePartial", Model)

Now, in order for your partial to actually be able to use this, though, it too needs to have a defined model, for example: @model Namespace.To.Your.Model

@Html.Action("MemberProfile", "Member", new { id = Model.Id })

Alternatively, if you're dealing with a value that's not on your view's model (it's in the ViewBag or a value generated in the view itself somehow, then you can pass a ViewDataDictionary

@Html.Partial("_SomePartial", new ViewDataDictionary { { "id", someInteger } });

And then:

@Html.Action("MemberProfile", "Member", new { id = ViewData["id"] })

As with the model, Razor will implicitly pass your partial the view's ViewData by default, so if you hadViewBag.Id in your view, then you can reference the same thing in your partial.

Passing data from the container (cshtml or a partial view) to the inner partial view

If you just render a partial with just the partial name:
@Html.Partial("_SomePartial")

It will actually pass your model as an implicit parameter, the same as if you were to call:

@Html.Partial("_SomePartial", Model)

Now, in order for your partial to actually be able to use this, though, it too needs to have a defined model, for example: @model Namespace.To.Your.Model

@Html.Action("MemberProfile", "Member", new { id = Model.Id })

Alternatively, if you're dealing with a value that's not on your view's model (it's in the ViewBag or a value generated in the view itself somehow, then you can pass a ViewDataDictionary

@Html.Partial("_SomePartial", new ViewDataDictionary { { "id", someInteger } });

And then:

@Html.Action("MemberProfile", "Member", new { id = ViewData["id"] })

As with the model, Razor will implicitly pass your partial the view's ViewData by default, so if you hadViewBag.Id in your view, then you can reference the same thing in your partial.

Aug 1, 2016

Update a Auto Increment Column in SQL Server



set identity_insert [WorkFlow].[WorkFlowMaster] on

INSERT INTO [WorkFlow].[WorkFlowMaster]
           (
      [WorkFlowID]
     ,[WorkFlowCategoryID]
           ,[Name]
           ,[ShortName]
           ,[StepNumber]
           ,[IsFinalStep]
           ,[DocumentsRequired])
     VALUES
           (
      7
     ,2
           ,'Decision Received'
           ,'DecisionRcvd'
           ,6
           ,0
           ,0
     )
GO

delete [WorkFlow].[WorkFlowMaster] where [WorkFlowID] = 11;

set identity_insert [WorkFlow].[WorkFlowMaster] off

Jun 15, 2016

cannot build project in VS2015. Error Message "the operation could not be completed. The parameter is incorrect"

I had downloaded a project from the net containing a demo of a reporting website.
When I tried to run the project as is. It threw a Error.( which was basically shouting about the startup project cant be loaded etc.)
When I tried to compile the same, I got the following error  "the operation could not be completed. The parameter is incorrect"... Some intuitive message that...
I tried many things to correct it, 
Finally opened it in SafeMode and tried compiling.. to my surprise, I was building and threw up a a few errors regarding missing nuget packages..
This was a pointer towards the right direction at least.
I again loaded the project in VS2015 this time not in safe mode and then updated the existing packages and also noticed the dlls of all crystal report packages were missing.. Downloaded them individually removed all the issues and I could build it..
Hope this helps..

Apr 18, 2016

OWIN KATANA TopShelf Nancy

OWIN and KATANA:
http://www.codeproject.com/Articles/826757/Understanding-OWIN-and-Katana
http://www.codeproject.com/Articles/864725/ASP-NET-Understanding-OWIN-Katana-and-the-Middlewa
http://www.codeproject.com/Articles/864725/ASP-NET-Understanding-OWIN-Katana-and-the-Middlewa
http://www.asp.net/aspnet/overview/owin-and-katana



TopShelf:
Tutorial: http://docs.topshelf-project.com/en/latest/configuration/quickstart.html

Windows Service creation:
http://dontcodetired.com/blog/post/Painless-NET-Windows-Service-Creation-with-Topshelf.aspx
http://blog.amosti.net/self-hosted-http-service-in-c-with-nancy-and-topshelf/
https://lunaverse.wordpress.com/2012/03/30/self-hosting-webapi-as-a-windows-service-with-topshelf/

Good Technical Study Links:


MVC Fluent API EF









-------------------------------------------------

Simple Web Token



---------------------------------------------------------
Instrumentation and Performance Metrics


----------------------------------------------------------------------------

SOA Patterns and standards:








-----------------------------------------------------------------------------------------------------------------------

WebAPI / REST related:



-----------------------------------------------------------------------------------------------------------------------

Precompile controllers and views






Lazy(T) Class





-----------------------------------------------------------------------------------------------------------------------

Weak Reference Class








-----------------------------------------------------------------------------------------------------------------------

SOA Entity Composition:














Apr 12, 2016

ASP.NET pre-compile into a single assembly


Approach 1: (From StackOverflow)
The easiest way to do this is to Create (or change) your project as (or to) an "Asp.Net Web Application" rather than the "Asp.Net Web Site". The process of converting is not that hard, but you will need to move everything out of the app_code folder, as WAP (Web Application Projects) projects do not have code inside app_code.

This will cause your project to be compiled into a single dll, rather than the "dll per page" or "dll per directory" scheme that the web sites normally work off of. It will also force you to resolve any type name problems (IE: if you have 6 pages called Default), It's important when you make a single assembly that fully qualified names be unique.

This will give you a proper project file (build script) and dump all your dll's out to the /bin folder when you compile.

You can then use something like ILMerge to combine all your assemblies in the /bin folder into a single dll if that's what you want to do. This assumes all your references are managed assemblies, if you have any non .Net libs it's going to be a lot trickier, although still not impossible.


Approach 2: Use the aspnet_merge.exe Utility to Merge Assemblies
how-do-i-use-the-aspnet_mergeexe-utility-to-merge-assemblies


Approach 3: Compile MVC project to a single DLL embed your js and css files. When you publish, in the configure part of the settings tab (see capture below), be sure to uncheck "allow precompiled site to be updatable" <--- a="" and="" assembly="" br="" chose="" compile="" control="" cshtml="" in="" merge="" page="" single="" the="" will="">

By default there is an assumption that whoever has access to your views and DLLs is trusted. If they have your files, they can do whatever they want with them.

By the nature of HTML, there is no point in trying to conceal your content files such as javascript and CSS. These files are served to the client regardless, so they are always retrievable.

If you want to put your views into DLLs, you can look into RazorGenerator.

A Custom Tool for Visual Studio that allows processing Razor files at design time instead of runtime, allowing them to be built into an assembly for simpler reuse and distribution. Please note that what you're doing is known as "Security through obscurity".(Security through obscurity is the use of secrecy of the design or implementation to provide security).Security through obscurity is discouraged and not recommended by standards bodies.


Approach 4: Packaging ASP.NET ASPX Pages into a separate Assembly

Read here

Find Max length of string array


My requirement was to get the string with the longest value and the shortest value from a huge array. Naturally I was inclined to use the Max() and Min() extensions of Array. But it was throwing queer results. I was stumped, why was it not behaving uniformly? Then I realized for Max or Min on a string all it does is a alphabetical sorting and returning the top and the bottom of the sorted list. I also added a simple lambda solution to it.


Feb 1, 2016

Configure ASP.NET SignalR in a web farm


I had a problem after I put into production a Visual Studio project with SignalR library.

In localhost every call seemed to be right but after the publishing step, some random request returned me an http error. After some google search I found that the problem was that the site is published in a web farm with 7 differents servers. In this case could happen that the first call is send from one server and managed from another server in the farm.

Every server has its encryption and decryption own code and if you want SignalR calls return a valid http status you should share these keys from the servers in the farm. So for each server in the farm open IIS and go to Sites and single click in the site where SignalR is used. In the central panel now go to Machine Key and double click.

Uncheck “Automatically generate at runtime” and “Generate a unique key for each application” and put a valid unique validation Key and a valid unique decryption key in the text boxes.

Look at the picture below, you should have something similar to this.

[Excerpted from: http://nextstepblog.altervista.org/configure-asp-net-signalr-in-web-farm/?doing_wp_cron=1454300698.7938909530639648437500]



Other Important Links:

http://www.asp.net/signalr/overview/performance/scaleout-with-sql-server

http://www.tugberkugurlu.com/archive/scaling-out-signalr-with-a-redis-backplane-and-testing-it-with-iis-express

http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx

Jan 19, 2016

Using Fiddler to test Web API Rest Services and pass an array as parameter + Filtering

1. In Fiddler’s Composer tab, Select the "Parsed" tab.

2. In the same tab, Change GET to POST and enter the address of your Web.api controller (“http://yoursite.com/api/yourControllerName”).

3. Again, under the same tab, In the Request headers Text Box Area (The heading 'Request Headers' may not be visible), enter a JSON content type. “Content-Type: application/json; charset=utf-8″ (w/o the braces). 4. Again, under the same tab, Put your JSON string array (Input param) in the Request Body. e.g., ["aaa","bbbbb","cccccccc"].

5. Click on "Execute". it will hit the controller and you can debug.

To Filter the huge number of network communications recorded in the Fiddler

1. Click on the "Filters" tab, Select "Use Filters"

2. In the 1st drop down under the Hosts Heading, Select "Show Only Intranet Hosts", in the second drop down, select "Show only the following Hosts"

3. In the following text box enter: Enter the local url for e.g. "http://localhost:31314/", here, I was hosting the service in IISExpress.