草庐IT

authenticate_with_http_token

全部标签

c# - 尝试使用 .NET JWT 库生成 token 时出错

我正在尝试使用包System.IdentityModel.Tokens.Jwt来生成token。我在网上找到了一些代码示例,非常简单,但后来我遇到了一个我无法弄清楚的错误。这是我正在使用的代码(为简洁起见略有修改):publicclassTestClass{publicstaticstringGetJwtToken(){vartokenHandler=newJwtSecurityTokenHandler();varinput="anyoldrandomtext";varsecurityKey=newbyte[input.Length*sizeof(char)];Buffer.Block

Http Post 请求消息正文中的 C# Xml

我正在寻找一个示例,说明如何在C#中将xml文档放入http请求的消息正文中,然后解析响应。我已经阅读了文档,但我只想看一个示例(如果有的话)。有没有人有例子?谢谢 最佳答案 privatestaticstringWebRequestPostData(stringurl,stringpostData){System.Net.WebRequestreq=System.Net.WebRequest.Create(url);req.ContentType="text/xml";req.Method="POST";byte[]bytes=S

c# - 编辑记录时 RadGrid 中的 "Cannot unregister UpdatePanel with ID ' xxx ' since it was not registered with the ScriptManager... "

让我切入正题。我的场景如下:我有自定义添加的字段来过滤RadGrid并且过滤效果很好。当我想在RadGrid中使用EditForm编辑记录时,问题就来了。它过去工作正常,但后来我在选择正确的行时遇到了一些问题(我总是选择错误的行)所以这就是我修复它的方法。所以,我的带过滤器的RadGrid看起来像这样:我所做的是使用session,这将帮助我们稍后确定过滤的RadGrid数据源是已启动还是默认的。protectedvoidbtnSearch_Click(objectsender,EventArgse){Session["SearchKontakti"]="1";}之后,我必须使用if循

c# - .mdf"failed with the operating system error 2(系统找不到指定的文件。)

protectedvoidregister_Click(objectsender,EventArgse){AddUser(userName.Text,password.Text,confirm.Text);}voidAddUser(stringname,stringpass,stringconfirm){Useru=newUser(name,pass,confirm);if(u.Valid){using(vardb=newSiteContext()){db.User.Add(u);db.SaveChanges();}}}}publicclassUser{publicintUserId{

c# - System.Web.Http.ApiController.get_Request() 中缺少方法

我有一个Controller。publicsealedclassAccountsController:BaseApiController{privatereadonlyIDatabaseAdapter_databaseAdapter;publicAccountsController(IDatabaseAdapterdatabaseAdapter){_databaseAdapter=databaseAdapter;}[AllowAnonymous][Route("create")]publicasyncTaskCreateUser(CreateUserBindingModelcreate

c# - References of References with COM 调用者

这个问题在这里已经有了答案:AddmanagedDLLdependenciedtounmanagedC++project(1个回答)关闭6年前。我有这样一个场景:使用VBA从MSAccess应用程序调用COM调用我们正在构建的C#库,该库引用了Newtonsoft.Jsonv9库使用nuget包,它们自己依赖Newtonsoft.Jsonv6(例如,Microsoft.AspNet.WebApi.Client)当他们尝试使用Newtonsoft.Json(或与我们的C#库引用的版本不同的任何库)时,它自己的黑盒代码中的依赖库会崩溃错误:Couldnotloadfileorassembl

c# - 验证 Windows 身份 token

我正在尝试开发一个简单的Web服务来使用Windows身份框架对桌面应用程序的用户进行身份验证,目前我正在通过帖子传递WindowsIdentity.GetCurrent().Token生成的token变量(它是加密的和ssl的,考虑到我们域的布局和服务器的配置,Windows身份验证不是一个选项)。我正在将token传递回去并将其转换回IntPtr。我不知道如何验证token以确保它是由特定的ActiveDirectory(或任何与此相关的)生成的。我试图在给定token的情况下创建一个新的WindowsIdentity实例,但这只会导致异常(消息:模拟token无效-无法复制)。如

c# - 单元测试 Windows.Web.Http HttpClient 与模拟 IHttpFilter 和 IHttpContent,MockedHttpFilter 抛出 System.InvalidCastException

我有一个依赖于Windows.Web.Http(Windows10UAP应用程序)中的HttpClient的类。我想进行单元测试,因此我需要“模拟”HttpClient来设置Get-Call应该返回的内容。我开始使用HttpClient使用手写模拟IHttpFilter和IHttpContent进行“简单”单元测试。它没有按预期工作,我在Test-Explorer中收到InvalidCastException。单元测试看起来像:[TestMethod]publicasyncTaskTestMockedHttpFilter(){MockedHttpContentmockedContent

c# - 使用 ASP.NET Web API 启用 HTTP 压缩

我们通过Asp.NETWebAPI为网站提供文件服务:publicclassStartup{publicvoidConfiguration(IAppBuilderapp){varclientHostname=System.Configuration.ConfigurationManager.AppSettings["ClientHostname"];varstaticFileOptions=newStaticFileOptions(){OnPrepareResponse=staticFileResponseContext=>{staticFileResponseContext.Owin

c# - React Axios - C# WebAPI 请求 token 在没有服务器错误的情况下失败

我有以下代码:varqs=require('qs');constROOT_URL='http://localhost:56765/';constdata=qs.stringify({username,password,grant_type:'password'});axios.post(`${ROOT_URL}token`,data).then(response=>{debugger;dispatch(authUser());localStorage.setItem('token',response.data.token);}).catch((error)=>{debugger;dis