Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start writing!

 

//upload

[HttpPost,Route(“upload”)]
public async System.Threading.Tasks.Task<HttpResponseMessage> test()
{
var httpRequest = HttpContext.Current.Request;

foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
var originalFileExtension = Path.GetExtension(postedFile.FileName);//dosya uzantısını verir
var filePath = HttpContext.Current.Server.MapPath(“~/” + postedFile.FileName);
postedFile.SaveAs(filePath);
}
return Request.CreateResponse(HttpStatusCode.OK, “yüklendi”);

}

 

 

//asenkron

[HttpGet]
[Route(“harf/{harf}”)]
public async Task<ApiResponse<List<Firmalar>>> harfeGore(string harf)
{
var result = new ApiResponse<List<Firmalar>>();
await Task.Run(() =>
result.Data = db.Firmalar.Where(x => x.firmaAdi.StartsWith(harf)).OrderBy(x=>x.firmaAdi).ToList());

return result.Success();
}

 

//attribute

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] // veri yoksa jsonda dönmez

 

// verileri json formatında döndürür (global.asax içine)
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

 

 

// web api filter

 

public class MyFilter : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
string[] sonuc =(string[]) actionContext.Request.Headers.GetValues(“Sitekey”);
if (sonuc[0] == “girme”)//response doldurulursa işleme girmez
actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, “BURDA GİRMEDİ”);

// OnActionExecuted()
}

public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{

}
}

One Comment

Add a Comment

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir