Showing posts from 2014

Could not create SSL/TLS secure channel - Fixed


I am accessing a 3rd party client WCF secured web service using a client certificate issued by them. I have added this client certificate to my servers' certificate store. (Ref#1 (packing a certificate), Ref#2 (importing to store))

And I have the client WCF configuration as follows:

<system.serviceModel><bindings><basicHttpBinding><binding name="GoogleServiceSoapBinding"><security mode="Transport"><transport clientCredentialType="Certificate"/></security></binding><binding name="ProvisioningServiceSoapBinding1"/></basicHttpBinding></bindings><client><endpoint address="" behaviorConfiguration="GoogleBehavior" binding="basicHttpBinding"

Remote access to IIS Express

If you try to access the IIS Express website from a remote computer, you wont be able to do it unless you follow these steps.


Look for <sites> section
In there find your site

<site name="MyWeb" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="E:\MyWeb" /> </application> <bindings> <binding protocol="http" bindingInformation="*:52891:localhost" /> <binding protocol="http" bindingInformation="*:8080:" /> </bindings> </site>
Now, create another binding as highlighted. IP address is your computers' IP, port is whatever the port you want.

Allow incoming connections: Open command prompt as admin
netsh http add urlacl url= u…

Web API 2 - Route Not Found (404)

It worked before, now it doesn't?

Here's the checklist.

Web API routes registration.
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
Web API config should come before normal Routes.
Route Prefix change [Route("~/api/sendemail")] to [Route("/api/sendemail")]
Prefix "~" is not needed.
Route values[Route("{myId:int}/sendemail")][HttpPost()]public bool SendEmail(int id,ContactModel data){returnOk();} notice the route defines a myId but method accepts an id. This will give a 404 Change the id or myId like this for it to work.

MSSQL - Reverse string searching in a table

Imagine this scenario.

I have a string, lets call it the Hash which is equal to "44F3D19B7176128263BDC"

Now, I have a separate table with a structure like this.

What I want to do is that find every record in this table which contains the "Hasher" value on our original string "44F3D19B7176128263BDC".

To do this, we can

Loop through every record in the Ads table, Get the Hasher value of that record, Check whether this Hasher value contains in our original hash string. 
In SQL, we can do it very easy.

declare @hash varchar(20) = '44F3D19B7176128263BDC'; select * from [dbo].[Ads] where CHARINDEX([Hasher], @hash) > 0 order by DATALENGTH([Hasher]) desc

Scrape Hidden Public APIs using C#

So you found a hidden unprotected API of a website you like.
Lets use dynamic objects to represent JSON objects and save them in our database. For later processing. There are legitimate reasons to do this. Say a crappy built in search system of the website.

Please note that following code totally depends on the website backend implementation. Do your research and change accordingly.

Post might feel like out of sequence. It was intentional.
lets begin:

const string ajaxUrl = "";
Lets create a separate method to issue the http request.

private async static Task<int> GetResponse(HttpClient client, string url, int page) { int pageCount = 0; var response = await client.GetAsync(url + page); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); var serializer = new JavaScriptSerializer(); // here we need to register our own Dymaic JSON converter. //…