locked
How to use System.Web in .Net Core RRS feed

  • Question

  • User-1167631307 posted

    How to use System.Web in .Net Core

    Wednesday, August 19, 2020 6:54 AM

Answers

  • User-821857111 posted

    You can't use System.Web in .NET Core to access HttpContext. While it may be technically possible to add a reference to System.Web in a .NET Core application, the HttpContext that it provides is never populated. Also, the FormsAuthentication system will not work in .NET Core for the same reason.

    Here's an article that tells you how to use basic cookie-based authentication in .NET Core: https://www.mikesdotnetting.com/article/335/simple-authentication-in-razor-pages-without-a-database

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 19, 2020 7:43 AM

All replies

  • User-821857111 posted

    kalva

    How to use System.Web in .Net Core

    Why do you want to do this? Is this related to your other questions about WebMethods and WebServices in .NET Core?

    Wednesday, August 19, 2020 7:01 AM
  • User-1167631307 posted

    no, its for checking the following 

    if (System.Web.HttpContext.Current != null &&
    System.Web.HttpContext.Current.User != null
    && System.Web.HttpContext.Current.User.Identity != null &&
    String.IsNullOrEmpty(System.Web.HttpContext.Current.User.Identity.Name) == false)
    {

    LBCTIntranetUser user = this.GetUser(System.Web.HttpContext.Current.User.Identity.Name);

    if (user != null)
    {
    FormsAuthentication.SetAuthCookie(System.Web.HttpContext.Current.User.Identity.Name, true);
    HttpContext.Current.Session.Remove(UserIdKeyName);
    HttpContext.Current.Session.Add(UserIdKeyName, user);
    }
    }

    Wednesday, August 19, 2020 7:17 AM
  • User-821857111 posted

    You can't use System.Web in .NET Core to access HttpContext. While it may be technically possible to add a reference to System.Web in a .NET Core application, the HttpContext that it provides is never populated. Also, the FormsAuthentication system will not work in .NET Core for the same reason.

    Here's an article that tells you how to use basic cookie-based authentication in .NET Core: https://www.mikesdotnetting.com/article/335/simple-authentication-in-razor-pages-without-a-database

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 19, 2020 7:43 AM