我正在开发Blazor服务器端应用程序,我需要包括cookie身份验证.我们创建了一个自定义的登录页面组件,但是为了创建cookie,我需要调用Razor页面来创建cookie.
I am developing a Blazor Server Side Application which I need to include cookie authentication. We created a custom login page component, but in order to create a cookie I need to call a Razor page to create the cookie.
是否可以在不刷新页面的情况下调用剃刀页面.
Is there a way to call the razor page without doing a page refresh.
我尝试使用UriHelper.NavigateTo,但不适用于非Blazor组件路由.
I tried using the UriHelper.NavigateTo but does not work with non Blazor component routes.
然后我尝试使用Javascript调用来执行window.location,但是问题在于这会导致浏览器刷新,从而重新创建我的所有实例(例如AppState,HttpClient),因此这些实例中的所有信息都是丢失(例如httpclient标头等).
Then I tried with a Javascript call to do a window.location, but the issue is that this causes a browser refresh that makes all my instances to be recreated (like AppState, HttpClient), so all the information in these instances are lost (like httpclient headers, etc).
我希望通过以httpclient和appstate范围内的实例保留其值的方式调用剃刀页面来创建cookie.
I expect to call the razor page to create a cookie, in a way that the httpclient and appstate scoped instance keep their values.
推荐答案
我们尝试了身份支架,但是在最新的Preview 8中有一个错误
We tried the Identity scaffolding but it has a bug in the latest Preview 8
我已经看到该错误,很容易纠正.您现在可以安装脚手架了.否则,
I've seen that bug, easily corrected. You can scaffold now. And otherwise,
我们唯一的问题是找不到自定义平淡的登录"和注册"页面的方法.
the only problem that we have is that we could not find a way to customize the bland Login and Register pages.
也许您可以使用这些平淡的页面"直到9月底发布?
maybe you could live with those 'bland pages' until the release, end of September?
这些步骤基于带有个人用户帐户"的Preview8服务器端项目
The steps, based on a Preview8 server-side project with "Individual user accounts"
NB:在此之前和之后提交Git更改是个好主意
NB: it is a good idea to Commit-changes in Git before and after this
- 在启动中暂时禁用此行:// endpoints.MapBlazorHub<App>(selector: "app");
- 运行脚手架向导,添加所需的任何页面
- 再次取消注释endpoints.MapBlazorHub()行
- 删除Pages/_ViewStart.cshtml
- 修复Pages/Shared/_Layout.cshtml,第一行缺少@using
- 修复Pages/Shared/_Loginpartial.cshtml,第二行缺失@inject
- temporarily disable this line in Startup: // endpoints.MapBlazorHub<App>(selector: "app");
- run the scaffolding wizzard, add any pages you want
- uncomment the endpoints.MapBlazorHub() line again
- remove Pages/_ViewStart.cshtml
- fix Pages/Shared/_Layout.cshtml, the first line is missing an @using
- fix Pages/Shared/_Loginpartial.cshtml, the second line is missing @inject
编译并运行
更多推荐
如何从服务器端Blazor应用程序中的Blazor组件调用剃刀页面而不会导致页面刷新
发布评论