Self host Asp.net MVC 4.5.2 - c#

I am attempting to self host a Asp.Net 4.5 MVC 5 application. Now after some research it seems this cannot be done with this framework, it would require switching it out for Nancy.
I understand that Asp.Net 5 supports this with Owin. I have been able to convert my MVC project into the new Asp.Net 5 project (with the project.json) and set my runtime version as .net 4.5
"frameworks": {
"net45": {
"dependencies": { }
}
},
This is so I can still use the other .Net 4.5 projects in my solution (otherwise I need to upgrade all of my projects and their dependencies, which some do not support .Net 5 yet). Is there any way to self host like this?

Which Asp.Net 5 build are you targeting in your app? For the RC2 builds the hosting API has changed somewhat and therefore other examples you find online may not work anymore, please see here for more information on that, it also explains how other's are using IIS to self-host so hopefully that will prove useful to you:
Changes to hosting API
It would also be helpful to know which server you're planning on using to self-host your app. Generally Kestrel is used but this should always be behind a Web Server such as Nginx, Apache or IIS, and never exposed directly.

Related

How to create and Deploy a Mono ASP.NET web project in Visual Studio?

So the web server i am using right now is a Apache web server which runs ASP.Net on mono but i can't seem to get a project up and running on the mono ASP.Net server as it all ways just lists the directories within the folder
I tried creating a ASP.Net project uploaded it didn't work
I tried creating a MVC project and uploading it, also did not work
I tried creating a project on a .net framework 4 and uploaded it but still no luck
I've run of out of ideas how to get this to work, is there i special way i should be compiling the project? or is there a specfic version of .net i should use, as the mono ASP.NET version says 4
Mono is a linux based runtime like the .NET framework is a windows based runtime. You don't have "mono ASP.NET web projects" - you have "ASP.NET web projects" that run on .net framework in windows or mono (maybe) in linux.
What I'd actually recommend you do is create a .net core site if this is a new project; microsoft provide core for windows and linux so it should be easier to get started developing something that compiles and runs on windows, and then is either transported compiled to linux or recompiled there.
Note that your apache (if you're dead set on using that) will probably need to be configured as a proxy so that it forwards requests through to Kestrel, which is hosting your app. Apache doesn't natively understand .NET anything, and will just see a .NET application as a bunch of folders and files

Is ASP.NET Core 2.0 the technology which is implemented in both frameworks (.Net Framework and .NET Core)?

I want to create an ASP.NET Core MVC 2 web application which I could host on Linux and Windows (i.e. in both OS). So, I am to use .Net Core. But when I create new ASP.NET Core MVC 2 web application I see two comboboxes. At first I am to select either .NET Frmework or .NET Core. The second combobox contains only ASP.NET Core 2.0.
Q1:
Does it mean that ASP.NET Core 2.0 is technology which is implemented in both frameworks (.Net Framework and .NET Core)?
It is impossible to switch .Net Framework to .NET Core for such project later. I could use .NET Core but here Microsoft writes that I am to use .NET Framework if I want to use Windows Service...
I want to use Nginx for Windows on my computer (instead of IIS) - it is interesting for me to try it. :) Here Microsoft describes how to host ASP.NET Core web application on Linux with NGinx. At the article the Create the service file topic exists. But it is for Linux... So, if I want to host my ASP.NET Core MVC 2 web application on Nginx in Windows then I am forced to use Windows Services (look here). But in the Host an ASP.NET Core app in a Windows Service article Microsoft writes that I am to use .NET Framework instead of .NET Core...
Q2
Does it mean that I can't the same project use for build my web application for Linux and Windows (for Windows Service)? Does it mean that for my goal I am to create two project: for .NET Framework and for .NET Core and to share the code sources for both projects?
Q1
Does it mean that ASP.NET Core 2.0 is technology which is implemented
in both frameworks (.Net Framework and .NET Core)?
.NET Core 2.0 and .NET Framework 4.6.1 are both implementations of .NET Standard 2.0. What this means is that they can both do the same things, and work mostly the same, but .NET Framework contains some Windows only libraries (System libraries such as Windows Forms) that mean it can only run on Windows. .Net Core programs can run on Windows, Linux and MacOS.
It is impossible to switch .Net Framework to .NET Core for such
project later. I could use .NET Core but here Microsoft writes that I
am to use .NET Framework if I want to use Windows Service...
While this is technically possible, you really want to avoid it. It's a huge headache, and usually breaks a lot of your code, with missing dependancies etc.
I want to use Nginx for Windows on my computer (instead of IIS) - it
is interesting for me to try it. :) Here Microsoft describes how to
host ASP.NET Core web application on Linux with NGinx. At the article
the Create the service file topic exists. But it is for Linux... So,
if I want to host my ASP.NET Core MVC 2 web application on Nginx in
Windows then I am forced to use Windows Services (look here). But in
the Host an ASP.NET Core app in a Windows Service article Microsoft
writes that I am to use .NET Framework instead of .NET Core...
I haven't personally used NGinx for Windows, but it looks as though they want you to set the target version for your NET Core app to NET Framework for the purposes of their example. Since .NET Core doesn't have the references to System specific libraries, you can easily change target to NET Framework. This doesn't make it a NET Framework project, it just changes the runtime against which Visual Studio will build it.
Q2
Does it mean that I can't the same project use for build my web
application for Linux and Windows (for Windows Service)? Does it mean
that for my goal I am to create two project: for .NET Framework and
for .NET Core and to share the code sources for both projects?
You can absolutely use the same application for both platforms, however it'll be a little different to how you're used to it. Since .NET Core is platform agnostic, Visual Studio won't generate an exe for you, it'll just generate dll files. You then use the dotnet command at the command line to start the program, e.g.
dotnet helloWorld.dll
This is how you run the program on any OS, provided you have the .NET Core runtime installed (There are plenty of guides on how to do this online).
Hope I've answered everything clearly :)

Communication between .netCore WebApi and Windows Service .net 2.0

On one side i have a Asp.Net Core WebApi 1.1 project hosted on a web server providing REST endpoints. On the other side i have a Windows Service project using .net framework 2.0.
.net 2.0 is a requirement and i can't update to a later version.
What is the best way to communicate between these two?
I never used .net2.0 so I'm not quite sure what my options are. Communicating with REST endpoints on the WebApi would be preferred, but i can't find a good way to achieve this as libraries like WCF/Json/.. are not available on 2.0.
Edit: The client (Windows Service) should be able to register itself to the web service (PUT), get a status and download a file from it (GET).

Combine ASP.NET and ASP.NET core in the same solution

I am creating a solution using ASP.NET Core 1.1 (SDK 1.0.4) and I require to use System.DirectoryServices namespace.
According to this Github issue
they are porting those APIs from the .Net Framework in the upcoming 1.2 version. However, I have seen that you can create an ASP.NET Core app targeting the full .Net Framework. I have follow some tutorials but all of them seem to be outdated (.Net Core 1.0 using project.json) and I have found no way to make it work.
In the same manner, I have seen some Github projects that seem to run ASP.NET Core and System.DirectoryServices namespace using something called DNX (like this one ). However, this project also fails in Visual Studio 2017.
Is there any real solution to have access to System.DirectoryServices on ASP.NET Core?
There might be a hacky way to go about it, but I haven't explored this enough, yet. I have noticed that when you create an "ASP.NET Core Web Application (.NET Core)" project, it doesn't allow you to change the .NET framework version to anything but available .NET Core versions. You'll need to create an "ASP.NET Core Web Application (.NET Framework)" project in order to use the full framework.
If you've already got an existing project you're working on, the best thing I can recommend is to simply create a new "ASP.NET Core Web Application (.NET Framework)" project and migrate your existing code over to that. For the most part, it should just be copy-and-paste. Like I said, there might be some other way, that I just don't know, but you at least have that method.
FWIW, DNX was .NET Core, before it was ".NET Core". There was a somewhat similar setup where you could run DNX on full .NET or just the "core" .NET functionality. It doesn't really help you here.

Where is Request.ClientCertificate in ASP.net 5

Currently I'm developing an application with ASP.net 5 and it needs to get client certificates. The certificate used to be in Request.ClientCertificate and was available in a controller (v. 4.6), but now there is no such option in Request.
I'm not bonded to Core, because the application is only for Windows and IIS => I've set in project.json just .net 4.5.2 instead of dnx451 and dnxcore50 in the frameworks section, but the option hasn't appeared.
Is there any workaround or a particular library I should add to use client certificates in controllers with ASP.net 5 (RC1) or it is simply better to write the application on ASP.net 4.6?
Thank you in advance!

Categories

Resources