Abortcontroller 信号不适用于 React 中的 Axios。
我想用 AbortController 替换 CancelToken (因为它已被弃用),但它不起作用,分别是请求没有被取消。
let testController: AbortController;
function loadTest() {
testController = new AbortController();
TestAPI.getTest(testController.signal)
.then((e) => {
console.log(e.data);
})
.catch((e) => {
console.error(e);
});
}
Run Code Online (Sandbox Code Playgroud)
同样在 UseEffect Cleanup 中,我执行了此操作(这里应该取消),并且信号的状态也设置为中止,但请求仍然没有取消:
useEffect(() => () => {
if (testController) testController.abort();
// console.log(testController.signal.aborted) => **true**
}, []);
Run Code Online (Sandbox Code Playgroud)
这是我的 API,我将 AbortSignal 传递给请求:
getTest(signal?: AbortSignal): Promise<AxiosResponse<Test[]>> {
return axios.get(`${URI}/test`, { signal });
},
Run Code Online (Sandbox Code Playgroud)
使用 Axios.CancelToken.source 时工作正常,但现在使用 AbortController,请求永远不会被取消。
使用:“axios”:“^ 0.26.0 ”,
有人设法将 AbortController 与 React 和 Axios 集成吗?或者 AbortController只 …
cancellation cancellationtokensource reactjs react-native axios
因此,我的 .NET Core Web 应用程序正在通过 Azure AD 登录用户,并且我有一个包含用户及其角色的数据库。
我已经创建了 OIDC MiddleWare 来从我的数据库中为尝试登录的用户添加声明。
所以流程是:
所以我的问题是:当用户在数据库中不可用或被阻止时,有没有办法拒绝用户的身份验证?
我现在所做的是设置一个声明,如果该声明不可用,它将被重定向到拒绝访问页面(通过使用授权策略),但我希望用户将被重定向到从 Microsoft/AD 的登录页面(最好的情况是带有一条消息)。
这是否可能以某种方式实现?如果可以,如何实现?
这是我现在的代码:
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => { Configuration.Bind("AzureAd", options); }
);
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.RequireAssertion(context =>
{
Claim claim = context.User.Claims.First(claim => claim.Type == ClaimTypes.Expired);
return context.User.HasClaim(x => x.Type == ClaimTypes.Expired) &&
context.User.Claims.First(claim => claim.Type == ClaimTypes.Expired).Value
.Equals("false", StringComparison.OrdinalIgnoreCase);
})
.RequireClaim(ClaimTypes.Name)
.RequireClaim(ClaimTypes.Role)
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
// OIDC Middleware, to access the User's Claims while …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试保护对 Hangfire 仪表板的访问。
由于我使用 .NET Core WebApi,我真的不知道如何使用 Azure AD 保护仪表板。
我尝试使用策略,但没有成功:
services.AddAuthorization(options =>
{
// Policy to be applied to hangfire endpoint
options.AddPolicy(AppConstants.HangfirePoilicyName, builder =>
{
builder
.AddAuthenticationSchemes(AzureADDefaults.AuthenticationScheme)
.RequireAuthenticatedUser();
});
});
Run Code Online (Sandbox Code Playgroud)
这里是配置方法:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}")
.RequireAuthorization();
endpoints.MapHangfireDashboard("/hangfire", new DashboardOptions()
{
Authorization = new List<IDashboardAuthorizationFilter> { }
})
.RequireAuthorization(AppConstants.HangfirePoilicyName);
});
Run Code Online (Sandbox Code Playgroud)
我期望的是,当我转到 Hangfire 仪表板时,我会看到 Microsoft 通过 Azure AD 登录,然后登录到我的租户并获得仪表板的访问权限。
也许值得一提:默认身份验证是 JWTBearerDefaults,但对于 Hangfire 仪表板,我需要 AzureAdDefaults
.net asp.net-web-api azure-active-directory hangfire asp.net-core
我正在尝试基于嵌入的 .cshtml 文件生成 HTML:
<EmbeddedResource Include="Templates\ReportTemplate.cshtml" />
Run Code Online (Sandbox Code Playgroud)
然而,从 RazorLight 我总是得到以下异常:
RazorLight.TemplateNotFoundException: Project can not find template with key My.Namespace.Application.Templates.ReportTemplate.cshtml
at RazorLight.Compilation.RazorTemplateCompiler.CreateRuntimeCompilationWorkItem(String templateKey)
at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
at RazorLight.Compilation.RazorTemplateCompiler.CompileAsync(String templateKey)
at RazorLight.EngineHandler.CompileTemplateAsync(String key)
at RazorLight.EngineHandler.CompileRenderAsync[T](String key, T model, ExpandoObject viewBag)
Run Code Online (Sandbox Code Playgroud)
但是当我检查嵌入资源时,我可以清楚地看到嵌入资源:
string[] files = Assembly.GetExecutingAssembly().GetManifestResourceNames();
Run Code Online (Sandbox Code Playgroud)
files包含:My.Namespace.Application.Templates.ReportTemplate.cshtml
这是我生成 PDF 的代码:
private async Task<string> RenderRazorTemplate(string key, Type viewModelType, object viewModel)
{
string[] files = Assembly.GetExecutingAssembly().GetManifestResourceNames();
var engine = new RazorLightEngineBuilder()
.UseEmbeddedResourcesProject(Assembly
.GetExecutingAssembly()) // Use the Executing Assembly as project that embeds the …Run Code Online (Sandbox Code Playgroud) 我目前正在从 Angular 和 MSAL 开始,但我不知道如何实现以下目标:
这是我的 app.module.ts 中的内容:
MsalModule.forRoot({
auth: {
clientId: '...', // This is your client ID
authority: '...',
// redirectUri: 'https://localhost:5001',
postLogoutRedirectUri: '**<--THIS MAYBE? BUT WHAT URL DO I PUT HERE TO COME BACK TO THE MICROSOFT LOGIN PAGE??**'
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // Set to true for Internet Explorer 11
},
}, {
popUp: false,
consentScopes: [
'user.read',
'openid',
'profile', …Run Code Online (Sandbox Code Playgroud) .net single-page-application asp.net-core azure-ad-msal angular
升级到 React 18 后,我遇到了以下 Antd 问题。
\n当使用 Antd 中的组件(模态、对话框等)时,出现以下错误:
\nTS2322: Type '{ children: ReactNode; ref: ForwardedRef<unknown>; className: string; visible: true; onCancel: (() => void) | undefined; onOk: undefined; footer: null; closable: false; }' is not assignable to type 'IntrinsicAttributes & ModalProps'. \xc2\xa0\xc2\xa0Property 'children' does not exist on type 'IntrinsicAttributes & ModalProps'.\nRun Code Online (Sandbox Code Playgroud)\n这是我的组件:
\nfunction TransitionsModal(props: Props): JSX.Element {\n const {\n open,\n onClose,\n children\n } = props;\n\n return (\n <div>\n {open &&\n <Modal\n className="flex items-center justify-center"\n visible={open}\n onCancel={onClose}\n …Run Code Online (Sandbox Code Playgroud) 我的应用程序通过 AzureAD 登录,但现在我需要从数据库获取信息,然后将角色存储为声明。
所以我的问题是:身份验证后如何将角色存储为声明?
这是我尝试过的:
var user = User as ClaimsPrincipal;
var identity = user.Identity as ClaimsIdentity;
identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
Run Code Online (Sandbox Code Playgroud)
但是当我转到另一个控制器时,该声明不再存在?
谢谢
.net claims-based-identity .net-core asp.net-core microsoft-identity-platform
我正在使用 .NET Core WebApi 和 EF Core。
我有以下场景:
我的问题:
所以我想创建一些任务来将批处理存储在数据库中(但在 .NET Core WebApi 中),你不能运行后台任务,对吧?
你们将如何实现这一目标?
asp.net-core ×6
.net ×5
reactjs ×2
.net-core ×1
angular ×1
antd ×1
axios ×1
c# ×1
cancellation ×1
hangfire ×1
microsoft-identity-platform ×1
razor ×1
razorengine ×1
razorlight ×1
react-native ×1
typescript ×1