本文整理汇总了C#中Response.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Write方法的具体用法?C# Response.Write怎么用?C# Response.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: App
public static AppDelegate App()
{
return (env, result, fault) =>
{
var request = new Request(env);
var response = new Response(result);
if (request.Path == "/")
{
response.Status = "200 OK";
response.ContentType = "text/html";
response.Start(() =>
{
response.Write("<h1>Sample.App</h1>");
response.Write("<p><a href='{0}/wilson/'>Wilson</a></p>", request.PathBase);
response.Write("<p><a href='{0}/wilsonasync/'>Wilson (async)</a></p>", request.PathBase);
response.Write("<p><a href='{0}/nancy/'>Nancy</a></p>", request.PathBase);
response.Write("<p><a href='{0}/fileupload'>File Upload</a></p>", request.PathBase);
response.End();
});
}
else
{
NotFound.Call(env, result, fault);
}
};
}
示例2: Something
public async Task Something(Request req, Response res, string echo)
{
await res.Start();
await res.Write("SomeOtherController.Something");
await res.Write("\n" + echo);
await res.Finish();
}
示例3: Create
public static AppAction Create()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result) {
Status = 200,
ContentType = "text/html"
};
response.Write("<h1>Sample1</h1>");
response.Write("<p>Hello world</p>");
response.Write("<p>This part is being added to the response helper's buffer. The result callback has not been invoked yet.</p>");
response.Finish(() => {
response.Write("<p>The result callback has been invoked. This part is going out live, but you can no longer change http response status or headers.</p>");
response.Write("<p>request.PathInfo=").Write(request.PathInfo).Write("</p>");
response.Write("<p>request.ScriptName=").Write(request.ScriptName).Write("</p>");
response.Write("<p> see also <a href='wilson'>Wilson</a> and <a href='wilsonasync'>WilsonAsync</a></p>");
response.Write(new byte[] {65, 66, 67, 68});
response.Write("<p>And now for something completely different.");
throw new ApplicationException("Something completely different");
});
};
}
示例4: Should_Update_Content_Length_When_Body_Appended_To_Using_Write
public void Should_Update_Content_Length_When_Body_Appended_To_Using_Write()
{
var response = new Response();
response.Status = 200;
Assert.IsFalse(response.Headers.ContainsKey("Content-Length"));
response.Write("Hi");
Assert.AreEqual("2", response.Headers["Content-Length"]);
response.Write(" there");
Assert.AreEqual("8", response.Headers["Content-Length"]);
}
示例5: Can_Be_Written_To
public void Can_Be_Written_To()
{
var response = new Response();
var body = response.Finish(_ =>
{
response.Write("foo");
response.Write("bar");
response.Write("baz");
})[2];
var parts = new List<string>();
((IIterable)body).Each(part => parts.Add(part));
CollectionAssert.AreEquivalent(new List<string> { "foo", "bar", "baz" }, parts);
}
示例6: Index
public async Task Index(Request req, Response res)
{
await res.Start();
await res.Write("SomeController.Index");
throw new Exception("bad news everyone");
await res.Finish();
}
示例7: Call
public static AppAction Call(AppAction app)
{
return (env, fault, result) => {
Action<Exception, Action<ArraySegment<byte>>> writeErrorPageBody = (ex, write) => {
write("<h1>Server Error</h1>".ToBytes());
write("<p>".ToBytes());
write(ex.Message.ToBytes()); //TODO: htmlencode, etc
write("</p>".ToBytes());
};
Action<Exception> sendErrorPageResponse = ex => {
var response = new Response(result) {Status = 500, ContentType = "text/html"};
writeErrorPageBody(ex, value => response.Write(value));
response.Finish();
};
try {
// intercept app-fault with sendErrorPageResponse, which is the full error page response
// intercept body-error with writeErrorPageBody, which adds the error text to the output and completes the response
app(env, sendErrorPageResponse, (status, headers, body) =>
result(status, headers, body.Filter((subscribe, next, error, complete) =>
subscribe(next, ex => {
writeErrorPageBody(ex, data => next.InvokeSync(data));
complete();
}, complete))));
}
catch (Exception ex) {
sendErrorPageResponse(ex);
}
};
}
示例8: AsyncApp
public static AppDelegate AsyncApp()
{
return (env, result, fault) =>
{
var request = new Request(env);
var response = new Response(result)
{
ContentType = "text/html",
};
var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
var href = "?flip=left";
if (request.Query["flip"] == "left")
{
wilson = wilson.Split(new[] {System.Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.Select(line => new string(line.Reverse().ToArray()))
.Aggregate("", (agg, line) => agg + line + System.Environment.NewLine);
href = "?flip=right";
}
response.Finish((fault2, complete) => TimerLoop(350, fault2,
() => response.Write("<title>Hutchtastic</title>"),
() => response.Write("<pre>"),
() => response.Write(wilson),
() => response.Write("</pre>"),
() =>
{
if (request.Query["flip"] == "crash")
{
throw new ApplicationException("Wilson crashed!");
}
},
() => response.Write("<p><a href='" + href + "'>flip!</a></p>"),
() => response.Write("<p><a href='?flip=crash'>crash!</a></p>"),
complete));
}
catch (Exception ex)
{
fault(ex);
}
});
};
}
示例9: SetErrorResponse
private static void SetErrorResponse(IDictionary<string, object> env)
{
Response response = new Response(env);
response.StatusCode = 500;
response.ReasonPhrase = "Internal Server Error";
response.ContentType = "text/html";
response.Write(Body);
}
示例10: Invoke
public Task Invoke(IDictionary<string, object> env)
{
var request = new Request(env);
var response = new Response(env);
if (request.Path == "/")
{
response.Status = "200 OK";
response.ContentType = "text/html";
response.Write("<h1>Sample.App</h1>");
response.Write("<p><a href='{0}/wilson/'>Wilson</a></p>", request.PathBase);
response.Write("<p><a href='{0}/wilsonasync/'>Wilson (async)</a></p>", request.PathBase);
response.Write("<p><a href='{0}/nancy/'>Nancy</a></p>", request.PathBase);
response.Write("<p><a href='{0}/fileupload'>File Upload</a></p>", request.PathBase);
}
else
{
response.StatusCode = 404;
}
return TaskHelpers.Completed();
}
示例11: Call
public dynamic[] Call(IDictionary<string, dynamic> environment)
{
var request = new Request(environment);
string lobster;
string href;
if (request.GET.ContainsKey("flip") && request.GET["flip"] == "left")
{
lobster = string.Join("\n", LobsterString.Split('\n').Select(line => new string(line.PadRight(42).Reverse().ToArray())));
href = "?flip=right";
}
else if (request.GET.ContainsKey("flip") && request.GET["flip"] == "crash")
{
throw new InvalidOperationException("Lobster crashed!");
}
else
{
lobster = LobsterString;
href = "?flip=left";
}
var response = new Response();
response.Write("<title>Lobstericious!</title>");
response.Write("<pre>");
response.Write(lobster);
response.Write("</pre>");
response.Write("<p><a href='" + href + "'>flip!</a></p>");
response.Write("<p><a href='?flip=crash'>crash!</a></p>");
return response.Finish();
}
示例12: App
public static FnApp App()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result);
var wilson = "left - right\r\n123456789012\r\nhello world!\r\n";
var href = "?flip=left";
if (request.GET["flip"] == "left") {
wilson = wilson.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
.Select(line => new string(line.Reverse().ToArray()))
.Aggregate("", (agg, line) => agg + line + Environment.NewLine);
href = "?flip=right";
}
response.Write("<title>Hutchtastic</title>");
response.Write("<pre>");
response.Write(wilson);
response.Write("</pre>");
if (request.GET["flip"] == "crash") {
throw new ApplicationException("Wilson crashed!");
}
response.Write("<p><a href='" + href + "'>flip!</a></p>");
response.Write("<p><a href='?flip=crash'>crash!</a></p>");
response.Finish();
};
}
示例13: Adds_connection_close_response_header_if_no_length_or_encoding
public void Adds_connection_close_response_header_if_no_length_or_encoding()
{
Request request = Request.Create();
Response expectedResponse = new Response(request.Environment);
expectedResponse.OutputStream = new MemoryStream();
expectedResponse.Write("12345");
expectedResponse.Write("67890");
expectedResponse.OutputStream.Seek(0, SeekOrigin.Begin);
var app = new StaticApp(expectedResponse);
var requestDelegate = new GateRequestDelegate(app.Invoke, new Dictionary<string, object>());
requestDelegate.OnRequest(new HttpRequestHead() { }, null, mockResponseDelegate);
Assert.That(app.Env.Get<Stream>(OwinConstants.RequestBody), Is.EqualTo(Stream.Null));
Assert.That(mockResponseDelegate.Head.Headers.Keys, Contains.Item("Connection"));
Assert.That(mockResponseDelegate.Head.Headers["Connection"], Is.EqualTo("close"));
Assert.That(mockResponseDelegate.Body, Is.Not.Null);
var body = mockResponseDelegate.Body.Consume();
Assert.That(body.Buffer.GetString(), Is.EqualTo("1234567890"));
Assert.That(body.GotEnd, Is.True);
}
示例14: ShowEnvironment
public static AppDelegate ShowEnvironment()
{
return (env, result, fault) =>
{
var response = new Response(result) {Status = "200 OK", ContentType = "text/xml"};
response.Finish((error, complete) =>
{
var detail = env.Select(kv => new XElement(kv.Key, kv.Value));
var xml = new XElement("xml", detail.OfType<object>().ToArray());
response.Write(xml.ToString());
complete();
});
};
}
示例15: Run
public override void Run()
{
AppDelegate app = (env, result, fault) =>
{
var response = new Response(result);
string message = string.Format("Instance Id : {0}, Counter value : {1}", RoleEnvironment.CurrentRoleInstance.Id, _counter);
response.Headers.SetHeader("Content-Length", message.Length.ToString());
response.Write(message);
response.End();
};
ServerFactory.Create(app, 1234, null);
while (true)
{
Thread.Sleep(10000);
this._counter++;
}
}