Created
December 12, 2020 12:29
-
-
Save WamWooWam/89903d96cf97dde620b5b661303db910 to your computer and use it in GitHub Desktop.
ASP.NET Core + C++/CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include "Startup.h" | |
using namespace System; | |
using namespace Microsoft::AspNetCore; | |
using namespace Microsoft::AspNetCore::Hosting; | |
using namespace Microsoft::Extensions::Hosting; | |
using namespace Microsoft::Extensions::Logging; | |
int main(array<System::String ^> ^args) | |
{ | |
IWebHostBuilder^ builder = WebHost::CreateDefaultBuilder(args); | |
builder = WebHostBuilderExtensions::UseStartup<CppSite::Startup^>(builder); | |
WebHostExtensions::Run(builder->Build()); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "pch.h" | |
#include "Startup.h" | |
namespace CppSite | |
{ | |
Startup::Startup(IConfiguration^ config) { | |
this->_configuration = config; | |
} | |
void Startup::ConfigureServices(IServiceCollection^ services) | |
{ | |
} | |
Task^ Startup::Run(HttpContext^ context) | |
{ | |
return HttpResponseWritingExtensions::WriteAsync(context->Response, "Hello from C++!", CancellationToken::None); | |
} | |
void Startup::Configure(IApplicationBuilder^ app, IHostingEnvironment^ env) | |
{ | |
if (HostingEnvironmentExtensions::IsDevelopment(env)) | |
{ | |
DeveloperExceptionPageExtensions::UseDeveloperExceptionPage(app); | |
} | |
RunExtensions::Run(app, gcnew RequestDelegate(&Startup::Run)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
using namespace System; | |
using namespace System::Collections::Generic; | |
using namespace System::Threading; | |
using namespace System::Threading::Tasks; | |
using namespace System::Reflection; | |
using namespace Microsoft::AspNetCore::Builder; | |
using namespace Microsoft::AspNetCore::Hosting; | |
using namespace Microsoft::AspNetCore::Mvc; | |
using namespace Microsoft::AspNetCore::Http; | |
using namespace Microsoft::Extensions::Configuration; | |
using namespace Microsoft::Extensions::DependencyInjection; | |
namespace CppSite | |
{ | |
ref class Startup | |
{ | |
public: | |
Startup(IConfiguration^ config); | |
void ConfigureServices(IServiceCollection^ services); | |
void Configure(IApplicationBuilder^ app, IHostingEnvironment^ env); | |
static Task^ Run(HttpContext^ context); | |
private: | |
IConfiguration^ _configuration; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment