"景先生毕设|www.jxszl.com

C# AntiForgeryToken类代码示例

2023-12-29 17:04编辑: www.jxszl.com景先生毕设
本文整理汇总了C#中AntiForgeryToken类的典型用法代码示例。如果您正苦于以下问题:C#AntiForgeryToken类的具体用法?C#AntiForgeryToken怎么用?C#AntiForgeryToken使用的例子?这里精选的类代码示例或许可以为您提供帮助。 示例1:ValidateTokens_Success_AuthenticatedUserWithUsername publicvoidValidateTokens_Success_AuthenticatedUserWithUsername() { //Arrange varhttpContext=newMock().Object; varidentity=GetAuthenticatedIdentity("the-user"); varsessionToken=newAntiForgeryToken(){IsSessionToken=true}; varfieldtoken=newAntiForgeryToken() { SecurityToken=sessionToken.SecurityToken, Username="THE-USER", IsSessionToken=false, AdditionalData="some-additional-data" }; varmockAdditionalDataProvider=newMock(); mockAdditionalDataProvider.Setup(o=>o.ValidateAdditionalData(httpContext,"some-additional-data")) .Returns(true); varconfig=newAntiForgeryOptions(); vartokenProvider=newAntiForgeryTokenProvider( config:config, claimUidExtractor:newMock().Object, additionalDataProvider:mockAdditionalDataProvider.Object); //Act tokenProvider.ValidateTokens(httpContext,identity,sessionToken,fieldtoken); //Assert //Nothingtoassert-ifwegotthisfar,success! }
原文链接:http://www.jxszl.com/biancheng/C/556540.html