Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a React app inside a razor page

I have a react app created using create-react-app and now I want to integrate this to a ASP.NET Core 2.0 web application. The reason is, I need to enable windows authentication and generate a token before the user enters into the react app. In other words in my asp.net react app, I need the entry point to be a 'cshtml' instead of an 'html'. Has anyone done this before or is there another way to enable windows auth?

like image 530
voddy Avatar asked Sep 05 '25 03:09

voddy


1 Answers

There are two solutions to this so far; Both are summarized here, this would be enough to do a simple search on the web to find different flavors of the solution:

  1. write a simple express server that would server your index page from build directory. This is after you build the react app. Do the authentication by using node-sspi and do validations using middle ware. Use proxy key word in package.json file to redirect request to server in development mode.

  2. Create a asp.net web app with windows auth enabled. Copy react code inside a folder. configure webpack.config to use a template(you design a template) file to create a index.cshtml instead of a index.html and write some build scripts to copy index.cshtml file from build to Pages directory and other css and js content from build to wwwroot. Do authentication bit in the index.cshtml.cs file (code behind)

I implemented the second solution as my API was c# and hosted in iis and both client and server would be run on an intranet

like image 126
voddy Avatar answered Sep 07 '25 21:09

voddy