If a service application such as ASP.NET Web application cannot access a client certificate that other applications like console applications can access, then the client certificate may not be stored in the local machine. You can understand that something like that may be happening if you get the error:
Could not create SSL/TLS secure channel for your Web Request and you can’t understand what is going wrong while it might be ok at your development machine but when you try to publish it you get this error.
So let’s copy a client certificate in the local user store to the local machine store by using the Certificate Export Wizard following the steps below:
- Click Start, click Run, type mmc, and then click OK.
- On the File menu, click Add/Remove Snap-in, and then click Add.
- In the Add Standalone Snap-ins dialog box, click Certificates, click Add, click Computer account, click Next, and then click Finish.

- In the Add Standalone Snap-ins dialog box, click Certificates, click Add, click My user account, and then click Finish.

- Click Close, and then click OK.

- To export the client certificate from the local user store, follow these steps:
- Expand Certificates – Current User, expand Personal, and then click Certificates.

- Right-click the client certificate, click All Tasks, click Export, and then click Next.

- Click Yes, export the private key, and then click Next two times.

- In the Password box and in the Confirm Password box, type a password, and then click Next.

- In the File name box, type a file name. Click Next, and then click Finish.

- In the Certificate Export Wizard dialog box, click OK.

- To import the client certificate to the local machine store, follow these steps:
- Expand Certificates (Local Computer), and then expand Personal.

- Right-click Certificates, click All Task, click Import, and then click Next.

- In the File name box, type the file name that you specified in step 6e, and then click Next.

- In the Password box, type the password that you specified in step 6d, and then click Next two times.

- Click Finish, and then click OK.

Here is a small recipe about making some things a little more beautiful using asp.net Validators and some javascript.
What do we need:
- ASP.NET Validators like RequiredFieldValidator
- jQuery
- jQuery Tooltip
- A nice tooltip image and some css
Read more…
This is a small one
By default when you create a new asp.net handler (.ashx) it implements the interface IHttpHandler. If you want to access information about user and other things stored in session you need also to implement the IRequiresSessionState.
IRequiresSessionState specifies that the target HTTP handler requires read and write access to session-state values
Let’s assume you have a database messing around with sample data and want an easy and fast way to delete all data.
What you can use:
sp_MSforeachtable: Stored Procedure to perform same actions for all tables in the specified database
DELETE: Removes rows from a table or view. More here
TRUNCATE TABLE name: Identical to DELETE statement with no Where clause. Both removes all rows in a table but TRUNCATE is faster and uses fewer system and transaction log resources than DELETE.
Have in Mind
You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint, so instead, use DELETE statement without a WHERE clause. The reason is that
TRUNCATE TABLE is not logged and it cannot activate a trigger.
-- Disable Referential Integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'IF OBJECTPROPERTY(object_id(''?''), ''TableHasForeignRef'') = 1 DELETE FROM ? else TRUNCATE TABLE ? '
GO
-- Enable Referential Integrity Again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
What confuses sometimes is the use of virtual keyword, so let’s keep some notes in order to remember it.
Definition
The virtual keyword is used to modify a method or property declaration, in which case the method or the property is called a virtual member. The implementation of a virtual member can be changed by an overriding member in a derived class.
Have in mind
You cannot use the virtual modifier with the following modifiers: static, abstract, override.
How to use it
A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.
When to use it
When you want to support polymorphism. When objects derive from a common class, having some common behavior but there are some small differences at the implementation of each object’s behavior.
Examples
using System;
class TestVirtual
{
public class Shape
{
public const double pi = Math.PI;
protected double x, y;
public Shape() { }
public Shape (double x, double y)
{
this.x = x;
this.y = y;
}
//This method can be overriden
public virtual double Area()
{
return x*y;
}
}
public class Circle: Shape
{
public Circle(double r): base(r, 0)
{
}
// This method is being overriden
public override double Area()
{
return pi * x * x;
}
}
public class Rectangle: Shape
{
public Rectangle(double x, double y): base(x, y){}
}
public static void Main()
{
double r = 3.0, h = 5.0;
Shape c = new Circle(r);
Shape s = new Rectangle(r, h);
// Display results:
Console.WriteLine("Area of Circle = {0:F2}", c.Area());
Console.WriteLine("Area of Rectangle = {0:F2}", s.Area());
}
}
Results
Area of Circle: 28.27
Area of Rectangle: 15