Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Threading.Tasks;
- using HtmlAgilityPack;
- using Microsoft.AspNetCore.Mvc;
- using Seo.Models;
- using Seo.Utilities;
- namespace Seo.Controllers
- {
- public class HomeController : Controller
- {
- private readonly ITitleTagValidate _titleTagValidate;
- private readonly Ih1h6TagsValidate _h1h6TagsValidate;
- private readonly IKeyWordValidate _keyWordValidate;
- private readonly IPicturesAltValidate _picturesAltValidate;
- private readonly IWebsiteContentValidate _websiteContentValidate;
- private readonly IDescriptionValidate _descriptionValidate;
- private readonly IExternalFilesValidate _externalFilesValidate;
- private readonly ISslValidate _sslValidate;
- public HomeController(ITitleTagValidate titleTagValidate, IKeyWordValidate keyWordValidate, IWebsiteContentValidate websiteContentValidate, IPicturesAltValidate picturesAltValidate, IDescriptionValidate descriptionValidate, IExternalFilesValidate externalFilesValidate, ISslValidate sslValidate, Ih1h6TagsValidate h1h6TagsValidate)
- {
- _titleTagValidate = titleTagValidate;
- _h1h6TagsValidate = h1h6TagsValidate;
- _keyWordValidate = keyWordValidate;
- _picturesAltValidate = picturesAltValidate;
- _websiteContentValidate = websiteContentValidate;
- _descriptionValidate = descriptionValidate;
- _externalFilesValidate = externalFilesValidate;
- _sslValidate = sslValidate;
- }
- [HttpGet]
- public IActionResult Index()
- {
- return View();
- }
- [HttpPost]
- public IActionResult Index(string url)
- {
- var web = new HtmlWeb();
- var document = web.Load(url);
- h1h6TagsValidate h = new h1h6TagsValidate();
- Website website = new Website();
- string websideContent = document.DocumentNode.OuterHtml;
- var htmlBody = document.DocumentNode.SelectSingleNode("//body");
- var nodes = document.DocumentNode.SelectNodes("//h1");
- string titleTagFromWebside = document.DocumentNode.SelectSingleNode("//head/title")?.WriteContentTo();
- website.titleTag = _titleTagValidate.TitleTagChecker(titleTagFromWebside);
- website.h1Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h1"));//nodes);
- website.h2Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h2"));
- website.h3Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h3"));
- website.h4Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h4"));
- website.h5Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h5"));
- website.h6Tag = _h1h6TagsValidate.h1h6TagsChecker(document.DocumentNode.SelectNodes("//h6"));
- var topWords = _keyWordValidate.WordCounting(document.DocumentNode.InnerText);
- var topWordsSorted = _keyWordValidate.WordSorting(topWords);
- website.pageContent = topWordsSorted;
- website.altPicturesTags = _picturesAltValidate.CheckAltAttributes(document.DocumentNode.SelectNodes("//img"));
- website.facebook = _websiteContentValidate.CheckWebsideContent(websideContent,"facebook");
- website.twitter = _websiteContentValidate.CheckWebsideContent(websideContent, "twitter");
- website.instagram = _websiteContentValidate.CheckWebsideContent(websideContent, "instagram");
- website.linkedin = _websiteContentValidate.CheckWebsideContent(websideContent, "linkedin");
- website.descriptionPage = _descriptionValidate.CheckDescriptionLength(document);
- website.robots = _externalFilesValidate.CheckExternalFilesExist(url + "/robots.txt");
- website.sitemap = _externalFilesValidate.CheckExternalFilesExist(url + "/sitemap.xml");
- website.favicon = _externalFilesValidate.CheckExternalFilesExist(url + "/favicon.ico");
- website.noindex = _websiteContentValidate.CheckWebsideContent(websideContent, "noindex");
- website.canonical = _websiteContentValidate.CheckWebsideContent(websideContent, "canonical");
- website.analytics = _websiteContentValidate.CheckWebsideContent(websideContent, "googletagmanager");
- website.ssl = _sslValidate.SslCheckExist(url);
- return View("SourceView",website);
- }
- public StreamReader HTTPRequest(String url)
- {
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
- HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
- return streamReader;
- }
- public String PrintHTTPRequest(StreamReader streamReader)
- {
- string pageContent = "";
- while(!streamReader.EndOfStream)
- {
- pageContent += streamReader.ReadLine().ToString();
- }
- return pageContent;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement