Monday, February 4, 2013

Real IPAddress of users



in ASP.NET ,UserHostAddress may not return the correct IPAddress of the client machine , use X-FORWARDED-FOR to getting the correct result.

FOR MORE INFO ::

http://thepcspy.com/read/getting_the_real_ip_of_your_users/

' Look for a proxy address first
Dim _ip As String = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
' If there is no proxy, get the standard remote address
If (_ip = "" Or _ip.ToLower = "unknown") Then _
_ip = Request.ServerVariables("REMOTE_ADDR")



Also ,very good info on wiki...
http://en.wikipedia.org/wiki/X-Forwarded-For

Intalling ARR in IIS 7 and higher



excellent article by wonyoo on how to do this if one doesn't want to use web platform installer (no permissions etc.issues)

http://blogs.iis.net/wonyoo/archive/2011/04/20/how-to-install-application-request-routing-arr-2-5-without-web-platform-installer-webpi.aspx

if you want to use web platform installer http://www.iis.net/downloads/microsoft/application-request-routing


Tuesday, May 3, 2011

Running Linux Side by Side with Windows

a really nice and easy way to install Linux on PC and run along with windows using wubi installer

WUBI Link


Happy Linuxing ! ! !

Monday, January 4, 2010

T4 Template Missing in VS 2010 Beta 2

 

T4 template for EF POCO Code generator is not a part of the vs2010 beta 2 ,it was part of  Microsoft ADO.NET Entity Framework Feature Community Technology Preview 1.

Hence to use it either u have to use the old preview and .net beta 1 instead of .net framework beta 2 .

If you have already installed .Net framework Beta 2 ,then the t4 template you can use is Templates for Self-Tracking Entities by installing

Microsoft ADO.NET Entity Framework Feature Community Technology Preview 2

Wednesday, November 11, 2009

ASP.NET MVC

 

ASP.NET MVC PROJECTS

6 top level directories

  1. Controllers – for controller classes that handles URL requests.
  2. Models – for classes that represent and manipulate data .
  3. Views – for UI Template files that are responsible for rendering output .
  4. Scripts – for JavaScript(JS) library files and scripts .
  5. Content – for CSS/Image files and non-dynamic/non-JS content.
  6. App_Data – to store data files needed for read/write .

In a Model-View-Controller framework the term “model” refers to –:

  • Objects that represent the data of the application .
  • Corresponding domain logic that integrates validation and business rules with it.

LINQ to SQL
LINQ to SQL is an ORM (object relational mapper) that ships as part of .NET 3.5.
LINQ to SQL provides an easy way to map database tables to .NET classes we can code against.

This minimizes the amount of data code we need to write, and allows us to build really clean applications.

Schema Validation

When model classes are defined using the LINQ to SQL designer, the datatypes of the properties in the data model classes will correspond to the datatypes of the database table.

LINQ to SQL will also automatically handles escaping SQL values for you when using strings - so you don't need to worry about SQL injection attacks when using it.

 

 

For small applications it is sometimes fine to have Controllers work directly against a LINQ to SQL DataContext class, and embed LINQ queries within the Controllers. As applications get larger, though,
this approach becomes cumbersome to maintain and test. It can also lead to us duplicating the same LINQ queries in multiple places.

One approach that can make applications easier to maintain and test is to use a “repository” pattern.
A repository class helps encapsulate data querying and persistence logic, and abstracts away the implementation details of the data persistence from the application.

In addition to making application code cleaner, using a repository pattern can make it easier to change data storage implementations in the future, and it can help facilitate unit testing an application without requiring a real database.

Tuesday, August 11, 2009

Covariance and Contravariance in Delegates

Covariance and contravariance provide a degree of flexibility when matching method signatures with delegate types.

Covariance -> permits a method to have a more derived return type than what is defined in the delegate.

Contravariance -> permits a method with parameter types that are less derived than in the delegate type.

Example 1 (Covariance)
This example demonstrates how delegates can be used with methods that have return types that are derived from the return type in the delegate signature. The data type returned by SecondHandler is of type Dogs, which derives from the Mammals type that is defined in the delegate.

C#
class Mammals
{
}

class Dogs : Mammals
{
}

class Program
{
// Define the delegate.
public delegate Mammals HandlerMethod();

public static Mammals FirstHandler()
{
return null;
}

public static Dogs SecondHandler()
{
return null;
}

static void Main()
{
HandlerMethod handler1 = FirstHandler;

// Covariance allows this delegate.
HandlerMethod handler2 = SecondHandler;
}
}
Example 2 (Contravariance)
This example demonstrates how delegates can be used with methods that have parameters of a type that are base types of the delegate signature parameter type. With contravariance, you can now use one event handler in places where, previously, you would have had to use separate handlers. For example, you can now create an event handler that accepts an EventArgs input parameter and use it with the Button.MouseClick event that sends a MouseEventArgs type as a parameter, and also with TextBox.KeyDown event that sends a KeyEventArgs parameter.

C#
System.DateTime lastActivity;
public Form1()
{
InitializeComponent();

lastActivity = new System.DateTime();
this.textBox1.KeyDown += this.MultiHandler; //works with KeyEventArgs
this.button1.MouseClick += this.MultiHandler; //works with MouseEventArgs

}

// Event hander for any event with an EventArgs or
// derived class in the second parameter
private void MultiHandler(object sender, System.EventArgs e)
{
lastActivity = System.DateTime.Now;
}


Source : MSDN

Saturday, January 3, 2009

SOA PRINICIPLES

Service-Oriented Architecture Principles
1)Explicit boundaries
    SOA is all about messaging—sending messages from point A to point B. These messages must be able to cross explicit and formal boundaries regardless of  what is behind those boundaries. This allows developers to keep the flexibility of how services are implemented and deployed. Explicit boundaries mean that a service can be deployed anywhere and be easily and freely accessed by other services, regardless of the     environment or development language of the other service.there is a cost associated with  crossing boundaries. These costs come in a number of forms, such as communication, performance, and processing overhead costs. Services should be called quickly and efficiently.
2)Autonomous services
    Services are built and deployed independently of other services. Systems, especially distributed systems,must evolve over time and should be built to handle change easily. This SOA principle states that each service must be managed and versioned differently so as to not affect other services in the process.
3)Policy-based compatibility
    Each service may or may not have certain requirements before it will start communicating and handing out information. Each service has its own compatibility level and knows how it will interact with other services.Services look at each others’ policy, looking for similarities so that they can start communicating. If two services can’t satisfy each others policy requirements, all bets are off. These policies exist in the form of machine-readable expressions.Policies also allow you to move a service from one environment to another without changing the behavior of the service.
4)Shared schemas(data) and contracts (behavior).
    The contract contains information regarding the structure of the message. Services do not pass classes and types;they pass schemas     and contracts. This allows for a loosely coupled system where the service does not care what type of environment the other service is executing on. The information being passed is 100 percent platform independent.