草庐IT

API安全

全部标签

c# - 在 ASP.NET Core Web API Controller 中使用 C# 7 元组

你知道为什么会这样吗:publicstructUserNameAndPassword{publicstringusername;publicstringpassword;}[HttpPost]publicIActionResultCreate([FromBody]UserNameAndPasswordusernameAndPassword){Console.WriteLine(usernameAndPassword);if(this.AuthenticationService.IsValidUserAndPasswordCombination(usernameAndPassword.u

c# - ASP.NET Web API + 长时间运行的操作取消

有没有办法在ASP.NETWebAPIbeta中确定HTTP请求是否被取消(由于任何其他原因被用户中止)?我正在寻找机会获得一种开箱即用的取消token,它会发出请求已中止的信号,因此也应中止长时间运行的操作。可能的相关问题-CancellationTokenModelBinder类的用例。为取消token设置单独的Binder的原因是什么? 最佳答案 您可以不时检查Response.IsClientConnected以查看浏览器是否仍连接到服务器。 关于c#-ASP.NETWebAPI

c# - 我应该为 Asp.NET web-api 路由使用 RouteParameter 还是 UrlParameter?

我已经看到两者都被使用了,所以我想知道,它们是做同样的事情还是做不同的事情?如果是后者,有什么区别?我尝试通过查看visualstudioMVC4(rc)webapi模板来自己回答这个问题,但遗憾的是它同时使用了这两种模板,所以我的困惑仍然存在。以下是模板包含的内容:publicclassRouteConfig{publicstaticvoidRegisterRoutes(RouteCollectionroutes){routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapHttpRoute(name:"DefaultApi

c# - 在 Asp.Net MVC Web Api 中测试 Controller 时,ModelState.IsValid 始终为真

我已尝试完成这项工作,并进行了多次google/stackoverflow搜索,但一点运气都没有。我有一个简单的模型:publicclassMovieModel{publicstringId{get;set;}[Required][StringLength(100)]publicstringName{get;set;}}Controller中的一个方法://POST:api/MoviespublicIHttpActionResultPost([FromBody]MovieModelmovieModel){if(ModelState.IsValid){//Code}}和一个测试方法(是一

c# - 带有 json 的 asp web.api 的最大 http 请求大小

我有webapi项目。我需要将带有文件的json数据作为编码的base64字符串(最多200mb)发布到那里。如果我发送大约10MB的数据,那么下一个方法通常会正确填充模型ImportMultipleFileModel。[HttpPost]publicasyncTaskImportMultipleFiles(ImportMultipleFileModelimportMultipleFileModel){varresponse=ImportFiles(importFileModel);returnresponse;}如果我发送更多,则模型为空。为什么?所以我将方法签名更改为:[HttpP

c# - 如何从 ASP.NET Web API 读取 XML?

我有一个WebAPI,可以读取XML并将其传递给适当的模型进行处理。我如何接收传入的XML?我应该使用哪种数据类型?我是否使用StreamReader、StreamContent或XmlDocument或其他? 最佳答案 ASP.NETWebAPI使用内容协商自动将传入的http请求反序列化为模型类。开箱即用,这将适用于任何XML、JSON或wwww-form-urlencoded消息。publicclassComputerController:ApiController{publicvoidPost(ComputerInfocom

c# - 如何从控制台应用程序使用客户端 api 连接到 TeamFoundationServer (tfs)?

我正在尝试连接到托管在visualstudio.com的TeamFoundationServer,使用其客户端API和控制台应用程序,但我收到此错误:TF400813:资源不可用于匿名访问。客户端我的代码:privatestaticvoidMain(string[]args){UricollectionUri=newUri("https://MyName.visualstudio.com/DefaultCollection");TfsTeamProjectCollectioncollection=newTfsTeamProjectCollection(collectionUri,new

c# - C#++ 运算符在 foreach 循环中是否成为线程安全的?

最近我从VB转到C#,所以我经常使用C#到VB.NET的转换器来了解语法差异。在将next方法转移到VB时,我注意到一件有趣的事情。C#原代码:publicboolExceedsThreshold(intthreshold,IEnumerablebools){inttrueCnt=0;foreach(boolbinbools)if(b&&(++trueCnt>threshold))returntrue;returnfalse;}VB.NET结果:PublicFunctionExceedsThreshold(thresholdAsInteger,boolsAsIEnumerable(Of

c# - 如何智能安全地将 Double 转换为 String?

尽量不要在这里重复自己(干),帮帮我。=)我有一个double代表评分/5。可能的值是:0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5.我想将其转换为不带小数位的字符串。所以值会变成:"0","05","1","15","2","25","3","35","4","45","5".我为什么要这样做?因为我正在尝试根据值动态创建链接:stringlink="http://somewhere.com/images/rating_{0}.gif";returnstring.Format(link,"15");可能的值在别处处理/验证,换句话说,我可以100%确定该值将始终是我

c# - .NET 2.0 : File. AppendAllText(...) - 线程安全实现

作为无聊的好奇心练习,考虑以下简单的日志记录类:internalstaticclassLogging{privatestaticobjectthreadlock;staticLogging(){threadlock=newobject();}internalstaticvoidWriteLog(stringmessage){try{lock(threadlock){File.AppendAllText(@"C:\logfile.log",message);}}catch{...handleloggingerrors...}}}File.AppendAllText(...)周围是否需要锁