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

ぐ巨炮叔叔 提交于 2019-12-09 02:23:41

问题


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)


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/40912473/can-system-web-be-used-with-asp-net-core-with-full-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!