Sudarshan's Blog

My Thoughts, Findings & Experiences

IIS 7.5 & Binding Wild Card Certificate Issue

February 21, 2015 21:32

Recently we were working on Asp.Net MVC project which was going to be deployed on IIS 7.5. So, we installed a wildcard certificate on the web server which we can use for other sites under the same domain.

But, when we tried associating the certificate withHost Name then it was NOT working. IIS was not allowing to enter value inHost Name field even though we have selected correct certificate.

Host name textbox is disabled

We found some articles about how to associate hostname using commands.

If we go via approach specified in these articles then it works ONLY if website has a binding

  • with port 443 without the hostname
  • with port 443 with the hostname

With this, you can't see the hostname is associated with a site when you try to edit the binding. BUT you can access a website using hostname just fine. Here is how IIS binding looks like

Both default and custom hostname bindings required

Both default and custom hostname bindings required

Now the drawback is: Even though you have wildcard certificate, you can't associate that to other websites on the IIS :(.

Real issue

Looks like IIS does not understand wild card certificate as wild card certificate unless it Friendly Name starts with *.

In our case it's friendly name was Wildcard certificate valid till XXXXX date

So, you need to change the friendly name which will start with *.

To do this,

  1. Select Start –> Run
  2. Type in “MMC” and hit enter
  3. From the console, select File –> Add / Remove Snap-in
  4. Select Certificates from the Add / Remove dialog
  5. Select Computer Account when prompt for which certificates the snap-in will manage.
  6. Select Local Computer when prompted
  7. Click OK to add the Snap-in to the MMC
  8. Locate your SSL certificate
  9. Double click the certificate
  10. Select 'Details' tab and select 'Edit Properties'
  11. You should be able to change the friendly name.

Change certificate friendly name

 

Now, if you go back to IIS and try to add/edit bindings, you can now enterHost Name along with selecting wild card certificate

Hostname textbox is editbale in IIS

 

Below article has good information about IIS and certificates:
http://blogs.msdn.com/b/varunm/archive/2013/06/18/bind-multiple-sites-on-same-ip-address-and-port-in-ssl.aspx

Now, you can also associate the same certificate with multiple websites on same IIS server!

ASP.NET AJAX async call doesn't fire jQuery's 'document.ready()' event: Solution

October 6, 2010 00:56

On our current project we were using following technologies:

  1. ASP.NET
  2. jQuery: for DOM manipulation at client side
  3. jQuery plugins like validator plugin, cleditor plugin, msked input plugin etc.
  4. ASP.NET AJAX: For doing asynchronous calls

Before introducing AJAX functionality on the page, all the jQuery plugins were working fine.But, as we implement AJAX functionality on the page, all the plugins stopped working.

BIG QUESTION, why?

Lets examine working on any jQuery plugin. We need to perform some operations inside the jQuery's 'document.ready()' event.

Here is the example for masked input plugin:

$(document).ready(function() {
// Attaches masks to page controls
$('#<%= txtSsn.ClientID %>').mask("999-99-9999");
$('#<%= txtBirthDate.ClientID %>').mask("99-99-9999");
});

This code get executed every time page is loaded.

Now, when we do asynchronous call using ASP.NET AJAX, only update panel's content get refreshed and not the whole page. This is why jQuery's 'document.ready()' event doesn't get fired. Because of this the masking associated with page controls gets removed.

But, this is so common situation and what to do?

Solution:

There are 2 different ways that I know:

  1. Make use of async call end event which is provided by ASP.NET AJAX. I don't prefer this way because we need to explicitly register and handle async event.
  2. Implement jQuery 'AjaxReady' event . (Thanks to unknown person who posted this solution on some forum, but he missed out to mention how exactly we should use it).

So, we will prefer 2nd way.

This solutions involves following steps:

Register event into jQuery like this

jQuery.fn.extend({
AjaxReady: function (fn) {
if (fn) {
return jQuery.event.add(this[0], "AjaxReady", fn, null);
} else {
var ret = jQuery.event.trigger("AjaxReady", null, this[0], false, null);
// if there was no return value then the even validated correctly
if (ret === undefined)
ret = true;
return ret;
}
}
});

This code should present into your *.js file or inside '<script language="javascript">' tag

Add following script within update panel's 'ContentTemplate'

<asp:UpdatePanel ID="upnlInsuranceCarrier" runat="server">
<ContentTemplate>
// Below script is very important
<script type="text/javascript">
prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequest);
function EndRequest(sender, args) {
$(document).AjaxReady();
}
</script>

Define your $(document).AjaxReady() event like this

$(document).AjaxReady(function () {
// Add code which needs to be executed after async call
});

Finally your code will look like

$(document).ready(function () {
setup();
});

$(document).AjaxReady(function () {
setup();
});

function setup() {
$('#<%= txtSsn.ClientID %>').mask("999-99-9999");
$('#<%= txtBirthDate.ClientID %>').mask("99-99-9999");
}

// Now, masked input plugin will work fine in async call as well

 

Happy Programming!