Skip to content

Instantly share code, notes, and snippets.

View tugberkugurlu's full-sized avatar
:shipit:
💥 shakalaka

Tugberk Ugurlu tugberkugurlu

:shipit:
💥 shakalaka
View GitHub Profile
public class HomeController : Controller {
public async Task<ActionResult> Index() {
HttpClient client = new HttpClient();
var result = await client.GetAsync("http://webapiasync.tugberk.me/api/cars");
doWork();
return View();
}
public static IEnumerable<T> Query<T>(this DbContext @this, System.Linq.Expressions.Expression<Func<T, bool>> predicate = null)
where T : class {
var query = (predicate != null) ? @this.Set<T>().Where(predicate) : @this.Set<T>();
var cmd = new SqlCommand();
cmd.Connection = (SqlConnection)(@this.Database.Connection);
//gets the generated t-sql
cmd.CommandText = query.ToString();
<Target Name="Compile" DependsOnTargets="Init">
<MSBuild Projects="@(MainSolutionfile)" Targets="Rebuild" Properties="OutDir=%(OutputDir.FullPath);Configuration=$(Configuration)" />
</Target>
<form action="/api/values" method="post">
<input type="text" name="value" />
<input type="submit" value="Submit" />
</form>
<form id="fooForm" action="/api/values" method="post">
<input type="text" name="value" />
<input type="submit" value="Submit" />
</form>
public class WebApiApplication : System.Web.HttpApplication {
protected void Application_Start() {
//...
GlobalConfiguration.Configuration.MessageHandlers.Add(new RemoveServerHeaderMessageHandler());
}
}
@tugberkugurlu
tugberkugurlu / CarsController.cs
Created June 21, 2012 12:26
Running conneg manually inside a controller - ASP.NET Web API
public class CarsController : ApiController {
public string[] Get() {
var cars = new string[] {
"Car 1",
"Car 2",
"Car 3"
};
Request:
----------------------------------------------------------------------------
GET http://localhost:49207/api/cars HTTP/1.1
User-Agent: Fiddler
Host: localhost:49207
Accept: application/json
Response:
----------------------------------------------------------------------------
HTTP/1.1 200 OK
@tugberkugurlu
tugberkugurlu / HttpContentProcessor.cs
Created July 2, 2012 21:36 — forked from HenrikFrystykNielsen/HttpContentProcessor.cs
Sample showing a DelegatingHandler which plugs in a special HttpContent wrapper for saving response content to local disk and perform asynchronous post-processing on that file. This allows content from a response to be post-processed, for example to send
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace ResponseEntityProcessor.Handlers
{
/// <summary>
/// Wraps an inner <see cref="HttpContent"/> and forces the content to be written
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
function guidGenerator() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}