예제 #1
0
        public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
        {
            // do something before the action executes
            var resultContext = await next();

            // do something after the action executes; resultContext.Result will be set

            if (resultContext.HandlerInstance is PageModel result)
            {
                var metaTags = result.ViewData[ViewDataConstants.OpenGraphViewModel] as OpenGraphViewModel;
                if (metaTags == null)
                {
                    metaTags = new OpenGraphViewModel();
                }

                if (!string.IsNullOrEmpty(metaTags.Title))
                {
                    metaTags.Title = "TemplateV2.Razor";
                }
                if (!string.IsNullOrEmpty(metaTags.Description))
                {
                    metaTags.Description = "Admin template for small business applications using ASP.NET Core 3.1 + Razor Pages";
                }
                metaTags.Url  = context.HttpContext.Request.GetDisplayUrl();
                metaTags.Type = "website";

                result.ViewData[ViewDataConstants.OpenGraphViewModel] = metaTags;
            }
        }
        public static void SetMeta(this ViewDataDictionary viewData, string title, string?description = null)
        {
            var model = viewData[ViewDataConstants.OpenGraphViewModel] as OpenGraphViewModel;

            if (model == null)
            {
                model = new OpenGraphViewModel();
            }

            model.Title = title;
            if (description != null)
            {
                model.Description = description;
            }
            viewData[ViewDataConstants.OpenGraphViewModel] = model;
        }
예제 #3
0
 public ActionResult OpenGraph(OpenGraphViewModel viewModel)
 => PartialView(viewModel);