Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active June 25, 2018 06:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/197963aec1872c40bba515f8f95b7e0f to your computer and use it in GitHub Desktop.
Save yetanotherchris/197963aec1872c40bba515f8f95b7e0f to your computer and use it in GitHub Desktop.
Notes on converting Roadkill wiki (MVC 3/4) to .net core (MVC 6)
  • RedirectToRouteResult is now RedirectToActionResult, with an ActionName property

  • No System.Runtime.Caching - replace it with IMemoryCache (Microsoft.Extensions.Caching.Memory)

  • typeof(x).Assembly is now typeof(x).GetTypeInfo().Assembly

  • MongoCollection has changed

  • StringComparison.InvariantCultureIgnoreCase is gone, easy replacement

  • Configuration + Sections are totally different

  • HttpContext and HttpRequest etc. now found in Microsoft.AspNetCore.Http.Abstractions - Microsoft.AspNetCore.Http.HttpRequest

  • Request.RequestUri is now various new properties, for example Request.Host (a HostString)

  • WebActivatorEx?

  • DependencyResolver?

  • System.Net.Mail - Mailkit instead

  • MvcHtmlString/HtmlString - Microsoft.AspNetCore.Html.Abstractions

    • ToHtmlString() is now .Value
  • HtmlHelper -> IHtmlHelper in Microsoft.AspNetCore.Mvc.ViewFeatures package

    • this return IHtmlContent not HtmlString
    • Use StringHtmlcontent for this
    • HtmlHelper still exists
  • Encoding.Default is gone. Use UTF8 or Unicode

  • htmlhelper.ViewContext.Controller is gone, can't find a way around it.

  • I replaced UrlHelper with IUrlHelper

  • HttpResponse (Microsoft.AspNetCore.Http) has no Cache property anymore

  • Transferring models between actions (preserving ViewData)- no longer seems to work using an Attribute?

  • JsonRequestBehavior.AllowGet is gone

  • CacheContentType attribute is gone

  • OnActionExecuting is now public

  • Localization new technique - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization

    • services.AddLocalization(options => options.ResourcesPath = "Resources");
  • [ValidateInput] and request validation is gone - aspnet/Mvc#324

  • [HandleError] is gone

  • Json(obj, JsonRequestBehavior.AllowGet) - JsonRequestBehavior.AllowGet is gone

  • HttpStatusCodeResult is now StatusCodeResult

  • return Javascript() is gone, use Content("js here", "text/javascript")

  • HttpUtility is now System.Net.WebUtility

  • Request.QueryString["Key"] is now Request.Query:

if (Request.Query.ContainsKey("ReturnUrl"))
{
  StringValues values;
  if (Request.Query.TryGetValue("ReturnUrl", out values))
  {
    string firstValue = values[0].ToLower();

    if (firstValue.Contains("/filemanager/select") || firstValue.Contains("/help"))
    {
      return View("BlankLogin");
    }
  }
var urlHelperFactory = _httpContext.RequestServices.GetService<IUrlHelperFactory>();
var actionAccessor = _httpContext.RequestServices.GetService<IActionContextAccessor>();
IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(actionAccessor.ActionContext);
@Workshop2
Copy link

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment