Skip to main content

Posts

Showing posts from May, 2016

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

When I try to connect to a remote WCF service which uses basicHttpBinding and transport security, I got this error message. It turns out that the reason of the error is the root certificate that issues the certificate for the WCF site is not in the calling machines "Trusted Root Certification Authority" store. By obtaining the root public certificate and import it into calling machines "Trusted Root Certification Authority" store, the problem solved. It is easy to obtain root public certificate using just the browser. Take Chrome as an example: Open Chrome and type the secured URL into the address bar, for example, https://www.google.ca/ In the browser address bar, click the lock icon in front the address. In the pop-up window, click the "Details" link after the sentence "Your connection to this site is private" Click the "View Certificate" button on the right panel In the "Certificate" dialog window, click "

MVC partial view not getting new model value after postback

It takes me quite a long time to figure out what the issue is and how to fix it. Here is a example to explain the problem. Say you have a view which include a partial view called "RandomNumber", which takes a RandomNumberModel object as model. Each time the page refresh or post back, the RandomNumberModel object will generate a new random number. public class RandomNumberModel { public static int Generate() { return new Random().Next(); } } Partial View: @model RandomNumberMode <p>         @Html.TextBoxFor(m => RandomNumber.new { autocomplete = "off" }) </p> It turns out after the postback, the values of all the inputs binding using HtmlHelper class are from ModelState instead of from Model. The value changes in model will not be shown in the rendered view. The solution for this is easy: 1. Using the plain html tag for data display instead of using Html helper <input type="text" name="RandomNumber" id="Ran

.NET - CryptographicException 'Keyset does not exist'

When you use the certificate to do signing and encryption, you may encounter this exception: CryptographicException 'Keyset does not exist' One possibility of this error is that the caller has not read permission of the private certificate using. By granting the read permission to the private certificate, the problem is solved. Following these steps to grant read permission to private certificate: In Windows -> Run, type mmc to open Microsoft Management Console In MMC, click File -> Add/Remove Snap-in... Choose "Certificates", then click "Add"  In the popup window, choose "Computer account" and then click "Next" Choose "Local computer" and click "Finish" to close popup window Click "OK" to close "Add or Remove Snap-ins" dialog. Go to "Personal"  certificates store on the left navigation Found the certificate on the right panel and right click it and choose "All T

Manage IIS 7 remotely using PowerShell and AppCmd

We can use  Windows PowerShell remoting features  to manage IIS 7 websites remotely.  Currently, remoting is supported on Windows Vista with Service Pack 1 or later, Windows 7, Windows Server 2008, and Windows Server 2008 Release 2.  Start Windows PowerShell as an administrator by right-clicking the Windows PowerShell shortcut and selecting Run As Administrator .  Enable PowerShell Remoting with Enable-PSRemoting -Force Starting a Remote Session using:  Enter-PSSession -ComputerName <COMPUTER> -Credential <USER> Now the PowerShell connected to the remote server. Any commands issued with work against the remote server. We can use the Appcmd.exe command line tool to manage remote server just as what we do locally. For example, to add an application pool: c:\windows\system32\inetsrv\appcmd add apppool /name:"Contoso" /managedPipelineMode:Integrated /managedRuntimeVersion:"v4.0" /enable32BitAppOnWin64:true To change application pool for a