.NET, Archive, ASP.NET, C#

Cookie Renaming in ASP.NET

Jason / January 20, 2007

In ASP.NET you can seamlessly rename cookies on the fly with the help the PreSendRequestHeaders and BeginRequest events of the HttpApplication class.

Both events call EventArgs delegates, with the sender object as a HttpApplication instance.

///

/// Called when a cookie is about to be sent to the browser. /// private void CookieOut(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; HttpCookie cookie = app.Response.Cookies["ASP.NET_SessionId"]; if (cookie != null) { app.Response.Cookies.Remove("ASP.NET_SessionId"); cookie.Name = "fooBar"; app.Response.Cookies.Add(cookie); } } read more

Archive, ASP.NET

Web Services & Self Signed SSL Certificates

Jason / September 20, 2006

Sometimes you want your web services to use an SSL communications channel, but for one reason or another you cannot use a SSL certificate from a major CA.

Just this past week we had just such a need at work. A coworker of mine was having difficulties making web service calls over SSL when the certificate’s CA could not be trusted by .NET. I had mentioned to him that I had done something similar in the past, and offered my help.

I eventually came up wit this solution:

using System;
using System.Net; //For the ServicePointManager
using System.Security.Cryptography.X509Certificates; //for the X509 certificate
using System.Net.Security; //for RemoteCertificateValidationCallback delegate & SslPolicyErrors

public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e){
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(certExaminer);
}
public bool certExaminer(object sender, X509Certificate c, X509Chain chain, SslPolicyErrors sllPolicyErrors) {
return true; //true means the certificate is okay to use
}

}
read more

Archive, ASP.NET, C#

Disabling buttons on click in ASP.NET

We have all seen the websites that disable "submit" buttons when you click on them. This is often done to prevent users from clicking the button multiple times.
Normally this is accomplished using an ‘onclick’ JavaScript event to disable the button. In ASP.NET, each server side item already has a onclick event handler which calls the server back for event processing.
To accomplish the same thing in ASP.NET, you could easily do: read more