ASP.NET Core 2.1 MVC react.js模板和身份

时间:2018-07-22 05:04:40

标签: reactjs asp.net-core-mvc-2.1

是否可以在带有React.js的SPA项目中使用Microsoft.AspNetCore.Identities? Visual Studio 2017中的模板仅提供``无身份验证''选项。如果您不能使用Microsoft.AspNetCore.Identity,还有哪些其他选项?谢谢。

2 个答案:

答案 0 :(得分:0)

使用ReactJs.Net-https://reactjs.net

[Authorize]
public async Task<IActionResult> Index()
        {
            var result = await drw.GetAllCompanysAsync();
            return View(result);
        }

可见

@model IEnumerable<Company>
@{
    ViewBag.Title = "Абоненты";
}
Html.React("Application", new
{
    initialData = Model,
    url = Url.Action("GetCompanyHeatPerDay", ,
    submitUrl = Url.Action("AddComment"),
}, containerId: "app")


<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.1/umd/react.development.js"></script>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.1/umd/react-dom.development.js"></script>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.2/prop-types.min.js"></script>
<script src="@Url.Content("~/js/app.jsx")"></script>

Html.ReactInitJavaScript()

app.jsx中的所有视图逻辑

答案 1 :(得分:0)

带有AspNetCore的IdentityServer4。Identities是SPA应用程序的解决方案。