public async Task <IActionResult> OnPostJoinAsync(string name) { try { using (var cn = Data.GetConnection()) { int orgUserId = await new CreateOrgUserJoinRequest() { OrgName = name, UserId = UserId }.ExecuteSingleAsync(cn); var orgUser = await cn.FindAsync <OrganizationUser>(orgUserId); var page = new EmailContent.JoinRequestModel(_config); await page.OnGetAsync(orgUserId); var content = await _viewRender.RenderAsync("Pages.EmailContent.JoinRequest", page); await _email.SendAsync(orgUser.Organization.OwnerUser.Email, "Ginseng: Org Join Request", content); } Data.ClearErrorMessage(); } catch (Exception) { Data.SetErrorMessage("Error requesting org. You might have misspelled it."); } return(RedirectToPage("/Setup/Organization")); }
public async Task Invoke(HttpContext context) { HttpRequest request = context.Request; HttpResponse response = context.Response; IHeaderDictionary headersDictionary = request.Headers; string applicationUrl = $"{request.Scheme}://{request.Host.Value}"; string urlReferrer = request.Headers[HeaderNames.Referer].ToString(); if (!string.IsNullOrWhiteSpace(urlReferrer) && (_whiteList.Contains(urlReferrer) || !urlReferrer.StartsWith(applicationUrl))) { string suffix = Path.GetExtension(request.Path).ToLower(); if (_suffixArray.Contains(suffix)) { response.StatusCode = StatusCodes.Status403Forbidden; string html = await _viewRenderService.RenderAsync(_path); await response.WriteAsync(html); } } await _next(context); }
public async Task SendEmailAsync(string email, string viewName, MessageViewModel messageViewModel) { var emailMessage = await _viewRenderService.RenderAsync(viewName, messageViewModel); emailMessage.To = email; await _emailSender.SendEmailAsync(emailMessage); }
public async Task Invoke(HttpContext context, IViewRenderService viewRenderService) { HttpRequest request = context.Request; IHeaderDictionary headersDictionary = request.Headers; string applicationUrl = $"{request.Scheme}://{request.Host.Value}"; string urlReferrer = headersDictionary[HeaderNames.Referer].ToString(); if (!string.IsNullOrEmpty(urlReferrer) && (!urlReferrer.StartsWith(applicationUrl) || WhiteList(urlReferrer))) { HttpResponse response = context.Response; string suffix = Path.GetExtension(request.Path).ToLower(); if (suffix.Equals(".css") || suffix.Equals(".js")) { var htmlString = await viewRenderService.RenderAsync("/Common/ViewTemplate/403.cshtml"); response.StatusCode = 403; await response.WriteAsync(htmlString); } if (suffix.Equals(".jpg") || suffix.Equals(".png") || suffix.Equals(".gif") || suffix.Equals(".jpeg")) { await response.SendFileAsync(Path.Combine(_wwwrootFolder, "images/img-16434886-f889-46fd-ab1e-3bbe6de7fedf.png")); } } await _next(context); }
public async Task Invoke(HttpContext context, IViewRenderService viewRenderService) { try { await _next(context); } catch (Exception ex) { HttpResponse response = context.Response; response.Clear(); response.StatusCode = StatusCodes.Status500InternalServerError; //发生未捕获的异常,手动设置状态码 if (response.HasStarted) { _logger.LogWarning("响应已经启动,错误页面中间件将不会被执行"); throw; } string htmlString = await viewRenderService.RenderAsync(_path); await response.WriteAsync(htmlString); _logger.LogError(ex, "执行请求时发生未处理的异常"); } }
public static async Task <string> RenderToStringAsync(this IViewRenderService viewRenderService, ContentContext contentContext) { using (var writer = new StringWriter()) { await viewRenderService.RenderAsync(contentContext, writer); return(writer.ToString()); } }
public static async Task RenderToStreamAsync(this IViewRenderService viewRenderService, ContentContext contentContext, Stream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } using (var streamWriter = new StreamWriter(stream)) { await viewRenderService.RenderAsync(contentContext, streamWriter); } }
public async Task Invoke(HttpContext context) { HttpResponse httpResponse = context.Response; if (StatusCodes.Status404NotFound.Equals(httpResponse.StatusCode) && !httpResponse.HasStarted) { string html = await _viewRenderService.RenderAsync(_path); await httpResponse.WriteAsync(html); } await _next.Invoke(context); }