I originally have code using HttpContextBase from System.Web in my ASP.NET Web MVC project.
I would like to extend this functionality to a project that is using .NET Core by moving the code into a .NET Standard Library so both projects using ASP.NET Web MVC and ASP.NET Core respectively can use it.
Is there a replacement library or method I can use instead of HttpContextBase in my .NET Standard library to share code?
Related
I'm working on a Nuget library which can be used for web applications (WebForms, MVC, CORE) and will be published for both .NetFramework and .NetStandard.
In my library I need to access the HttpContext for reading the Request and also for redirecting and writing in the Response object.
What's the best way to have a common HttpContext for all three frameworks WebForms, MVC and CORE?
Note that Microsoft.Owin is not compatible with .NetStandard and also in WebForms and MVC there is a System.Web.HttpContextBase class which is completely different in .NETCore projects and there we have Microsoft.AspNetCore.Http.HttpContext.
Your library could be organized this way:
Define adapter interfaces (over HTTP context and etc) in shared source project
Define implementations of all those interface in concreate Core or Classic project - create both. There you should have 3 projects in your solution.
Now your library is 4th project it should be multitarget, use conditional symbols to enable or disable "Classic" or "Core" adapters. Use adapters to access "Http Context and etc".
I want to build a simple C# Class Library that can be referenced from both ASP.NET Core 1.1 MVC and MVC 5 web applications. By simple I mean that the library just contains some enums and some string constants, i.e. no additional dependencies.
I have tried building the library as a .NET Core Class Library, but it seems this cannot be referenced by MVC 5 applications and vice versa. Currently, all components (class library and web applications) are running in the same solution.
Is there a way of achieving this?
Thanks.
You want a .NET Standard class library. Be sure to pick a version of the .NET standard that both .net core and full framework supports (1.5 works for 4.6.2 and net core)
See matrix in this article for full compatibilities:
blogs.msdn.microsoft.com - Introducing .NET Standard
We are using Adal as authentication library but we would like to use the policy functionality in Asp.Net Core security in our MVC5 application. The idea is to compile the Asp.Net Core library to .NET 4.6. This works! However, now I need to click the authentication things in my owin application.
Just adding the AuthorizeAttribute from the library doesn't work, it is not executed.
I have also read about the ported version from P. Schaeflein, but I would preffer to use the libraries provided by Microsoft.
Anyone an idea how to get this working?
Asp.net Core / .net core is a total rewrite of asp.net framework and the way it work is very different. For example Asp.net Core is most made around a Dependency Injection. So moving part of a framework that made for Asp.net Core to Asp.net MVC 4.6 made not work and would have to be rebuild to work with Asp.net MVC 4.6.
In ASP.NET Core RC2 Microsoft split the Core web application into two separate templates:
ASP.NET Web Application (.NET Framework)
and
ASP.NET Web Application (.NET Core)
I am planning on developing an app that is net 451 only. If I go the (.NET Framework) path. What type of class libraries should I be using? I assumed Class Library (.NET Core), but when I tried adding reference from a project with the (.NET Framework Template) it says it can't add reference to .NET Standard.
Maybe I shouldn't be using the .NET Framework template. The main reason why I feel like I should be is because I do not want to have to deal with developing for the other operating systems and not having access to certain packages like email and transactionscope, etc..
If you set your class library to target net451 also it will work.
Change project.json in class library project as follows...
"frameworks": {
"net451": { }
}
As I understand it, .NET Standard can reference .NET Core libraries, but .NET Core cannot reference .NET Standard libraries.
So, it comes down to the end-use of your application. If it's only going to run (or be hosted) on Windows, then use the larger, more established .NET Standard for the application (although you can choose to put common code in .NET Core projects in the same solution for future cross-platform re-use). However, if there's a requirement to run/host it on another platform (Linux, Mac), then you'll have to use the younger .NET Core.
I have used .net framework 4.0 to design my web project I want to improve some features on my web site and I decided to use MVC in my project.
I research about mvc I found out System.Web.Routing in .net framework 3.5 is wrapped by System.Web in .net framework 4.0.
In the other side in my host environment I have IIS 7.0 with all necessarily handlers mapped to .aspx and some other extension like .cshtml and support them.
So I think I have all thing for mvc migration. my question is :
Is it possible to move mvc by configure web.config and make some structure for content, view and controller classes but don't change any asp.net pages and configuration like appcode and appdata which I had before in my asp.net application.
Note, I don't want to change or update my old application to mvc I want to add some mvc controllers class and view to my existing asp.net project to use mvc functionality.
Have a look at this walkthrough from Scott Hanselman:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx