Working SignalR with SSL

Hi everybody,

Questions are coming to me about how can work signalr with SSL. It’s so simple.

As a default, signalr selfhost under http procotol. You need to change this to https and 443 port. After this you need get the certificate hash.

Finding the CertHash

I mentioned the certhash below: To find the certhash, you need to find the certificate’s ThumbPrint which can be found in a couple of ways using:

  • The IIS Certificate Manager
  • The Windows Certificate Storage Manager

Using IIS to get Certificate Info

If IIS is installed the former is the easiest. Here you can easily see all installed certificates and this UI is also the easiest way to create local self-signed certificates.

To look up an existing certificate, simply bring up the IIS Management Console, go to the Machine node, then Server Certificates:

For every endpoint mapping you need to supply 3 values:

  • The ipport which identifies the ip and port
    Specified as ipport=0.0.0.0:8082 where the zeros mean all ip addresses on port 8082. Otherwise you can also specify a specific Ip Address.
  • The certhash which is the Certificate’s Thumbprint
    The certhash is the id that maps the certificate to the IP endpoint above.  You can find this hash by looking at the certificate in the Windows Certificate store. More on this in a minute.
  • An AppID which is fixed for HttpListener Hosting
    This value is static so always use appid={12345678-db90-4b66-8b01-88f7af2e36bf}

Before the install ssl cert check your ipport status with this on cmd :

netsh http show sslcert ipport=0.0.0.0:8082

If you don’t see any certificate, this is mean the port 8082 is available for install to certificate.

After this, type this on cmd :

netsh http add sslcert ipport=0.0.0.0:8082
           appid={12345678-db90-4b66-8b01-88f7af2e36bf} 
           certhash=yoursslcertificatehash

That’s it. Enjoy 🙂

Google reCaptcha ASP.NET Using

Google reCaptcha ASP.NET Using

Geçtiğimiz günlerde yaptığımız bir projede Google recaptcha kullanmak istedik. Google tarafında ASP.NET ile eski captcha modeli dökümantasyonları verilmiş durumda. Biraz uğraş ile asp.net tarafında kullanılabilir hale getirdim. DLL dosyası aşağıdaki linktedir. Projenize referans olarak eklemeniz yeterli olacaktır.

Recently days we want to use Google recaptcha in a project. Google has gived documentation for old capthca version in ASP.NET. With a little occupation i have complete to using for asp.net. DLL file has in the link on below. You should add as reference to your project. Thats it!

Kullanımı :

Aspx sayfanızın head tagları arasına :   ( between head tags in your aspx page )

<script type="text/javascript" src='https://www.google.com/recaptcha/api.js'></script>

Aspx sayfasınızın body tagları arasına :   ( between body tags in your aspx page )

<div class="g-recaptcha" data-sitekey="Size Verilen KEY" ></div>

ASPX sayfanızın CS tarafına :   ( Code Behind )

using reCaptchaHelper;

string privateKey = “Size Verilen KEY”;

if(reCaptcha.reCapthcaValidation(privateKey));

{

// Success

}

else

{

// Error

}

 

Dosyayı Buradan İndirebilirsiniz…

For download file click here…

C# Dış IP Alma

Bazı durumlarda C# dilinde kullanıcının dış ip’sini almak isteyebilirsiniz. İnternet üstünde eğer arama yaptıysanız herkes bir api üzerinden sorgulama yaptığını görürsünüz. Ancak aşağıda yazdığım çok basit yöntem ile siz bunu yapabilirsiniz.

HttpContext.Current.Request.UserHostAddress; 

İşte bu kadar 🙂

C# Text Dosyasından Satır Satır Veri Okuma

int counter = 0;

string line;

System.IO.StreamReader file =

new System.IO.StreamReader(@”test.txt”);

while ((line = file.ReadLine()) != null)

{

//line değişkenini ne yapmak istiyorsanız…

counter++;

}