23 Kasım 2016 Çarşamba

IIS access loglarında X-Forwarded-For ile iletilen ip in görüntülenmesi

  1. Open IIS Manager.
  2. Select the site or server in the Connections pane, and then double-click Logging. Note that enhanced logging is available only for site-level logging - if you select the server in the Connections pane, then the Custom Fields section of the W3C Logging Fields dialog is disabled.
  3. In the Format field under Log File, select W3C and then click Select Fields....
    Select fields
  4. In the W3C Logging Fields dialog, click Add Field.... Note that enhanced logging is available only for site-level logging - if you selected the server in the Connections pane, then Add Field... is disabled.
    Add custom fields
  5. In the Add Custom Field dialog, enter a Field Name to identify the custom field within the log file. Please note that the field name cannot contain spaces.
  6. Select the Source Type. You can select Request HeaderResponse Header, or Server Variable (note that enhanced logging cannot log a server variable with a name that contains lower-case characters - to include a server variable in the event log just make sure that its name consists of all upper-case characters).
  7. Select Source, which is the name of the HTTP header or server variable (depending on the Source Type you selected) that contains a value that you want to log. You also can enter your own custom source string. For example, to record the custom HTTP Header "X-FORWARDED-FOR", enter that string in Source.
    Enter custom source
  8. Click OK.
  9. Click Add Field... for each additional custom field you want to add. You also can click Remove Field to remove a custom field you added or click Edit Field... to edit it.
  10. Click OK.
  11. Click Apply in the Actions pane to apply the new configuration

30 Mart 2016 Çarşamba

Oracle Create Table With Identity

Oracle 12c öncesi;

CREATE TABLE departments (
  ID           NUMBER(10)    NOT NULL,
  DESCRIPTION  VARCHAR2(50NOT NULL);

ALTER TABLE departments ADD (
  CONSTRAINT dept_pk PRIMARY KEY (ID));

CREATE SEQUENCE dept_seq;


CREATE OR REPLACE TRIGGER dept_bir 
BEFORE INSERT ON departments 
FOR EACH ROW
 
BEGIN
  SELECT dept_seq.NEXTVAL
  INTO   :new.id
  FROM   dual;
END;

/

Oracle 12c sonrası;
CREATE TABLE t1 (c1 NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY, 
                   c2 VARCHAR2(10));

11 Şubat 2016 Perşembe

linux centos Türkçe klavye

setxbpmap tr komutuyla türkçe klavye kullanılabilir.
her login olduğunuzda bu ayarın otomatik yapılması için .bashrc dosyasına bu komut girilebilir

13 Ocak 2016 Çarşamba

ASP.NET MVC BasicAuthenticationAttribute

public class BasicAuthenticationAttribute : ActionFilterAttribute
{
    public string Rol { get; set; }
   
    public BasicAuthenticationAttribute(string rol)
    {
        Rol = rol;//gönderilen user bilgisinin rolünü kontrol etmek için kullanılacak
    }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        string username;
        string password;

        var req = filterContext.HttpContext.Request;
        var auth = req.Headers["Authorization"];
        if (!String.IsNullOrEmpty(auth))
        {
            var cred = System.Text.ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(auth.Substring(6))).Split(':');
            username = cred[0];
            password = cred[1];
        }

        bool authenticated = false;
        bool authorized = false;
        if(string.IsNullOrEmpty(username) == false && string.IsNullOrEmpty(password) == false)
        {   //kullanıcı yetki kontrolü yap
            authenticated = true;//gönderilen username ve password geçerli mi kontrolü burada yapılabilir

            //yetki kontrolü
            authorized = true;//
        }

        if (authenticated && authorized) return;//eğer kullanıcı geçerliyse ve yetkisi varsa çık

        if (authenticated == false)
        {
            var res = filterContext.HttpContext.Response;
            res.StatusCode = 401;
            res.AddHeader("WWW-Authenticate", "Basic realm=\"RTM\"");
            res.Write("Kullanıcı adı ve şifre geçersiz");
            res.End();
            return;
        }

        if (authorized == false)
        {
            var res = filterContext.HttpContext.Response;
            res.StatusCode = 403;
            res.Write("Yetki yok");
            res.End();
            return;
        }
    }
}

5 Ocak 2016 Salı

MS SQL Count alternatif

SQL de çok fazla kayıt olan tablolarda count almak yavaş olduğunda aşağıdaki sorguyla index üzerinden kayıt sayısı alınabilir.

SELECT rows FROM sysindexes WHERE id = OBJECT_ID('CihazVeri') AND indid < 2

8 Nisan 2015 Çarşamba

Windows belirli bir tarihten eski dosyaları silme

forfiles -p "C:\tmp" -s -m *.* -d -5 -c "cmd /c del @file"

c:\tmp dizinindeki 5 günden eski dosyaları siler

6 Mart 2015 Cuma

Windows Service Debug

static class Program
{
    static void Main()
    {
        #if(!DEBUG)
           ServiceBase[] ServicesToRun;
           ServicesToRun = new ServiceBase[] 
    { 
         new MyService() 
    };
           ServiceBase.Run(ServicesToRun);
         #else
           MyService myServ = new MyService();
           myServ.Process();
           // here Process is my Service function
           // that will run when my service onstart is call
           // you need to call your own method or function name here instead of Process();
         #endif
    }
}

3 Nisan 2014 Perşembe

Visual Basic 6.0 ile XMLHTTP Request

Private Sub Command1_Click()
    Dim sHTML
    sHTML = RequestText("http://www.tcmb.gov.tr/kurlar/today.xml")
   
    Text1.Text = sHTML
End Sub

Private Function RequestText(sURL, Optional sMethod = "GET")
    Dim XMLHTTP
    Set XMLHTTP = CreateObject("microsoft.XMLHTTP")
    sMethod = UCase(sMethod)
    XMLHTTP.Open sMethod, sURL, False
    XMLHTTP.send (Null)
    RequestText = XMLHTTP.responseText
    Set XMLHTTP = Nothing
End Function

3 Mart 2014 Pazartesi

Linux ulimit hard ve soft limit ayarlaması

1. aşağıdaki satır /etc/security/limits.conf dosyasına eklenir
kullanıcı_adı hard nofile 65536

2. daha sonra kullanıcı_adı ile login olunur

.bashrc ve .bash_profile dosyalarına aşağıdaki satırlar eklenir

echo "ulimit -n 65536" >> .bashrc ; echo "ulimit -n 65536" >> .bash_profile

3. logout ve login işlemi sonrasında yeni ulimit değerleri set edilmiş olacaktır