本文整理汇总了C#中WebContext.Finish方法的典型用法代码示例。如果您正苦于以下问题:C# WebContext.Finish方法的具体用法?C# WebContext.Finish怎么用?C# WebContext.Finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebContext
的用法示例。
在下文中一共展示了WebContext.Finish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel) {
var ctx = RequestParameters.Create(context);
var login = ctx.Get("login");
var role = ctx.Get("role");
var exact = ctx.Get("exact").ToBool();
if (string.IsNullOrWhiteSpace(role)) {
context.Finish("{\"error\":\"emptyrole\"}", status: 500);
return;
}
if (string.IsNullOrWhiteSpace(login)) {
login = context.User.Identity.Name;
}
var result = false;
if (login != context.User.Identity.Name) {
if (!Roles.IsInRole(context.User.Identity, SecurityConst.ROLE_ADMIN)) {
context.Finish("{\"error\":\"adminrequire\"}", status: 500);
return;
}
result = Roles.IsInRole(login, role, exact);
}
else {
result = Roles.IsInRole(context.User.Identity, role, exact);
}
context.Finish(result.ToString().ToLowerInvariant());
}
示例2: DefaultProcess
protected virtual HandlerResult DefaultProcess(IHostServer server, WebContext context, string callbackEndPoint,
CancellationToken cancel) {
var result = GetResult(server, context, callbackEndPoint, cancel) ?? HandlerResult.Null;
var outer = result.Result;
if (result.Mime == "application/json") {
var str = outer as string;
if (null != str &&
((str.StartsWith("{") && str.EndsWith("}")) || (str.StartsWith("[") && str.EndsWith("]")))) {
outer = str.jsonify();
}
outer = outer.stringify();
context.Finish(outer, result.Mime, result.State);
}
return result;
}
示例3: Run
public override void Run(IHostServer server, WebContext context, string callbackEndPoint,
CancellationToken cancel) {
var data = RequestParameters.Create(context);
var name = data.Get("name");
var root = EnvironmentInfo.ResolvePath("@[email protected]/.appdata");
Directory.CreateDirectory(root);
var fileName = Path.Combine(root, name);
var contentType = "text/plain";
if (fileName.EndsWith(".json"))
{
contentType = "application/json";
}
var content = "";
if (File.Exists(fileName))
{
content = File.ReadAllText(fileName);
}
context.Finish(content, contentType);
}
示例4: Run
public void Run(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel) {
context.Finish(context.User.Identity.IsAuthenticated.ToString().ToLowerInvariant());
}
示例5: Run
/// <summary>
///
/// </summary>
/// <param name="server"></param>
/// <param name="request"></param>
/// <param name="response"></param>
/// <param name="callbackEndPoint"></param>
/// <param name="cancel"></param>
public override void Run(IHostServer server, WebContext context, string callbackEndPoint,
CancellationToken cancel) {
context.Finish("command not found","text/plain; charset=utf-8",404);
}