Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can System.Web be used with ASP.Net Core with Full Framework

Tags:

We are running serveral sites based on different .Net versions.

One of the sites is running .Net 4.6 and ASP.Net MVC 5.xx

To use the new syntax for Razor we want to upgrade this site to use .Net 4.6 and ASP.Net Core

We use FormsAuthentication on our sites, and we will continue using that so user can move between sites. (one of the sites is a SharePoint site running FormsAuthentication)

We understand that ASP.Net Core is not using anything from System.Web but we need to use that from controllers (to create FormsAuthentication cookie during login) and from HttpModule to verify cookie.

I have not been able to find any example how to use system.web from a site running ASP.Net Core with Full framwork. I have not been able to add dependency for system.web in project.json.

Questions.

  1. Is it possible to use system.web from a setup like this?

  2. How can we add dependency to system.web so System.Web.FormsAuthentication is available from ASP.NET MVC 6. (Controllers/ http module)

like image 326
TheTechArch Avatar asked Dec 01 '16 13:12

TheTechArch


People also ask

Can .NET Core and .NET Framework coexist on same server?

You can only have one version of . Net Framework side by side with any number of . Net (Core) versions.

Can I use EF6 with ASP.NET Core?

You can't put an EF6 context in an ASP.NET Core project because . NET Core projects don't support all of the functionality that EF6 commands such as Enable-Migrations require.

Can ASP.NET Core work with the .NET Framework?

In order to run ASP.NET Core Apps on the . NET Framework it needs to only reference . Core NuGet packages which contains only the . NET Standard 2.0 builds.

Should I use .NET Core or .NET Framework?

NET Core is faster than . NET Framework because the architecture of . NET Core is written or restructured from scratch to make it a modular, lightweight, fast, and cross-platform Framework. The Applications require technologies like workflow, webforms or WCF that are not present in .


2 Answers

That may not work the way you think. When you use .Net Core MVC against the full framework it's true that the System.Web namespace exists and could technically be called but it won't work like you want. The reason is that the request pipeline for Asp.Net Core and System.Web are totally different. So for example when using Asp.Net Core MVC if you check the HttpContext object from when a request comes in it will be populated with all the information you expect but if you check for the current request using System.Web objects you will see that their is no current request. That's because the current request didn't come in via the System.Web pipeline. It came in through the .Net Core "pipeline" if you will. So if you are using .Net Core MVC you will need to stick with the tools and approaches of that framework, not the ones provided in System.Web.

However, It should be possible to reference the System.Web.dll if your really want to. If you are using VS2015 you will need to get a copy of the System.Web.Dll and wrap it in a nuget package in order to establish a reference to it. See here .net core 1.0 visual studio referencing external dll VS2017RC has alpha tooling that should eliminate the need to wrap it in a NuGet package but I've had trouble installing it on my machine so I can't vouch for it personally. Update: VS2017 now has great tooling for Asp.Net Core and referencing full framework Dlls.

like image 36
RonC Avatar answered Nov 06 '22 06:11

RonC


Using the System.Web dll isn't the same as using System.Web. None of the System.Web pipeline will run for your ASP.NET Core application so you can't do what you are trying to do.

like image 135
davidfowl Avatar answered Nov 06 '22 06:11

davidfowl