Creating ‘Basic’ edition Web setup:
TechTalk
Saturday, March 17, 2012
Installer - ASP.NET MVC - Pluggable application modules/components/area/features
Creating ‘Basic’ edition Web setup:
Monday, March 5, 2012
Entity Framework - INSERT operation with many to many relations
Wednesday, February 29, 2012
ASP.NET MVC - Pluggable application modules/components/area/features
Application Master Page - main application has master page (_Layout.cshtml) which is at parent directory in ASP.NET application. As per ASP.NET framework, this layout is inherited to its all sub directories. This way even if marketing is separate project it inherits master page of main application and same applies to all other resources like CSS, image, javascripts and other static resources/pages.
Monday, August 16, 2010
Using enum in Entity - Entity Framework 4.0
Entity framework only allows primitive data types to be used as type while creating property. It is not possible to create property of custom enum type. Many times enum are needed to facilitate developer to choose valid value for property and it also makes developers life simple since Visual Studio provides hints for valid values via intelligence.
Here I present trick which will help developer to expose enum property from entity and use it during coding to make code more readable. Trick is let entity framework create integer properly for such column but create forwarding property using partial class with type casting and make original property private so that it is not available to programmer. This way programmer will get single enum column to read and write value to entity.
Let us take example of Support Ticket system, Ticket table has following structure:
Status column has check constraint ( or it could be foreign key to StatusMaster table). For our example let us go with simpler design of having check constraint. Valid status are listed below:
1 - New
2 - Open
3 - On Hold
4 - Closed
5 - Re-Opened
Visual Studio work:
Now go ahead and create Empty solutions.
Add Class Library project with name Domain.
Add edmx with name TicketModel. Generate model from database and choose Ticket table.
After edmx designer is shown, it would have Ticket entity with Status as byte property. As shown below:
Here in this example, we would like to represent Ticket Status as enum. To do so add new class file with name Ticket.cs and add below code in class file. Modify class definition to look like below:
Create new public enum TicketStatusCode for above mentioned valid statues. And Create new property TicketStatus of this enum type in ticket class. Write getter and setter of this property as mentioned below:
Since class definition created here is partial class, it adds this code to original Ticket entity which is also a partial class. Getter and Setter of this property refers original Status field which is mapped with database table column. So when application will try to read enum value, it will retrieve value from Status field and return type cast value.
Now go to designer, select Status column in Ticket entity and open property window. Make Getter and Setter of this property to private.
ha
Tuesday, August 10, 2010
Sorting Dictionary using LINQ and using ToDictionary() method to get Sorted Dictionary back
Following code snippet demonstrates:
- Using Dictionary to maintain list of items with key
- Use LINQ query on Dictionary to sort dictionary
- Convert LINQ result to Dictionary back
class Program
{
static void Main(string[] args)
{
//Dictionary to maintain list of months
Dictionary<int,string> months = new Dictionary<int,string>();
months.Add(1, "January");
months.Add(3, "March");
months.Add(8, "August");
months.Add(12, "December");
months.Add(2, "February");
months.Add(4, "April");
months.Add(5, "May");
months.Add(6, "June");
months.Add(7, "July");
months.Add(9, "September");
months.Add(10, "October");
months.Add(11, "November");
//Original display
display(months, "Original Dictionary");
var sortedMonths = (from KeyValuePair<int,string> item in months
orderby item.Value
select item).ToDictionary(kvp => kvp.Key, kvp => kvp.Value) as Dictionary<int,string>
//Sorted display
display(sortedMonths, "\nDictionary Sorted by Value");
Console.ReadKey();
}
static void display(Dictionary<int,string> list, string displyName)
{
Console.WriteLine("{0}:", displyName);
foreach (KeyValuePair<int,string> item in list)
{
Console.WriteLine("{0} {1}", item.Key.ToString().PadLeft(2,' '), item.Value);
}
}
}
Thursday, June 17, 2010
Configure Windows Registry for application Event Logs
System needs to register Application into registry in order to accept event logs. Application Name configured in registry is used as "Source" parameter while writing log entry using .NET code as explained below:
Example assume application name to be "MyApp"
Code snippet to log event:
EventLog.WriteEntry("MyApp", "Page Load is called", EventLogEntryType.Information)
Registry would require entry like below:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\eventlog\Application\MyApp]
"EventMessageFile"=hex(2):43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,\
00,73,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,2e,00,\
4e,00,45,00,54,00,5c,00,46,00,72,00,61,00,6d,00,65,00,77,00,6f,00,72,00,6b,\
00,5c,00,76,00,32,00,2e,00,30,00,2e,00,35,00,30,00,37,00,32,00,37,00,5c,00,\
45,00,76,00,65,00,6e,00,74,00,4c,00,6f,00,67,00,4d,00,65,00,73,00,73,00,61,\
00,67,00,65,00,73,00,2e,00,64,00,6c,00,6c,00,00,00
Important Note: Application running under Administrator context then it would create above registry entry automatically. But in case of deployment on production server this would never be the case. So in this case above registry entry need to be created manually.
Thursday, June 10, 2010
Self Signed Certificates
Steps to create .cer and .pfx files from certificate store
- Create Self –signed certificate from local machine (.cer file)
- Open inetmgr
- Go to Certificates
- Choose "Create Self-Signed Certificate…"
- Give Friendly name to certificate and complete step
(You will see new certificate created in list)
- Double click on Certificate
- Click "Copy to File…" button from Details tab
- Open inetmgr
- Generate .pfx file
- Open inetmgr
- Go to Certificates
- Select certificate from list to export
- Right click- Export Follow wizard steps
- Open inetmgr



















