草庐IT

Request1

全部标签

c# - Request.Url.Query 和 Request.QueryString 有什么区别?

我一直在追踪一个关于UrlRewriting应用程序的错误。该错误表现为查询字符串中某些变音符号的编码问题。基本上,问题是基本上是/search.aspx?search=heřmánek的请求被重写为“search=he%c5%99m%c3%a1nek”的查询字符串正确的值(使用一些不同的工作代码)是将查询字符串重写为“search=he%u0159m%u00e1nek”注意两个字符串之间的区别。但是,如果您将两者都发布,您将看到Url编码重现相同的字符串。直到您使用context.Rewrite函数,编码才会中断。损坏的字符串返回“heÅmánek”(使用Request.QueryS

c# - 调用 HttpContext.Request 时如何避免 HttpException?

所以HttpContext.Request如果在全局启动内调用则抛出publicHttpRequestget_Request(){if(this.HideRequestResponse){thrownewHttpException(SR.GetString("Request_not_available"));}returnthis._request;}这实际上是有记录的ASP.NETwillthrowanexceptionifyoutrytousethispropertywhentheHttpRequestobjectisnotavailable.Forexample,thiswoul

c# - 值不能为空。参数名称 : request

我正在使用nunit创建单元测试,所有这些代码在运行时都运行良好。我在下面有这个protectedHttpResponseMessage代码,当它返回时我的Controller正在调用它。但是,报错:"Valuecannotbenull.Parametername:request"isdisplaying.当我检查请求时,它实际上是null。问题:我将如何编写单元测试代码以返回HttpResponseMessage?错误显示在这一行:protectedHttpResponseMessageCreated(Tresult)=>Request.CreateResponse(HttpStat

c# - 检查 Request.IsAjaxRequest 在我的 asp.net mvc4 中总是返回 false

我的Controller中有以下代码publicActionResultIndex(stringsearchTerm=null){System.Threading.Thread.Sleep(5000);varaccountdefinition=repository.FindAccountDefinition(searchTerm).ToList();if(Request.IsAjaxRequest()){returnPartialView("_CustomerTable",accountdefinition);}returnView(accountdefinition);}但如果我使用

c# - 无法上传到 Azure Blob 存储 : The remote server returned an error: (400) Bad Request

我正在尝试创建一个实用程序来从Internet下载文件并将其再次上传到Azureblob存储。Blob容器已经创建好了;但出于某种原因,当我尝试将文件上传到存储时出现“BadRequest400”异常......创建了容器名称,小写字母,特殊字符。但我仍然不知道为什么会出现异常!请帮忙。注意:我没有使用任何模拟器...直接在云端进行测试。我的所有容器都具有“公共(public)容器”访问选项。异常(exception)情况:Anexceptionoftype'Microsoft.WindowsAzure.Storage.StorageException'occurredinMicros

c# - 如何在 ASP.net Core 中进行 Per-Request 缓存

我的旧代码是这样的:publicstaticclassDbHelper{//OneconectionperrequestpublicstaticDatabaseCurrentDb(){if(HttpContext.Current.Items["CurrentDb"]==null){varretval=newDatabaseWithMVCMiniProfiler("MainConnectionString");HttpContext.Current.Items["CurrentDb"]=retval;returnretval;}return(Database)HttpContext.Cu

c# - 使用 Simple Injector 的 Per Thread 和 Per Web Request 的混合生活方式

我正在使用SimpleInjector作为我的IoC库。我根据网络请求注册了DbContext,它工作正常。但是有一项任务是我在后台线程中运行它。所以,我在创建DbContext实例时遇到了问题。例如Service1有一个DbContext实例Service2有一个DbContext的实例Service1和Service2从后台线程运行。Service1获取实体并将其传递给Service2Service2使用该实体,但实体与DbContext分离其实问题就出在这里:Service1.DbContext和Service2.DbContext的区别。似乎当我在ASP.NETMVC中的单独线

c# - System.Net.ProtocolViolationException : You must write ContentLength bytes to the request stream before calling [Begin]GetResponse

我得到了"System.Net.ProtocolViolationException:YoumustwriteContentLengthbytestotherequeststreambeforecalling[Begin]GetResponse"errorwhencallingtothe"BeginGetResponse"methodofthewebrequest.这是我的代码:try{StreamdataStream=null;WebRequestWebrequest;Webrequest=WebRequest.Create(this.EndPointAddress);Webrequ

c# - Request.Url.GetLeftPart(UriPartial.Authority) 在 https 站点上返回 http

我们使用Request.Url.GetLeftPart(UriPartial.Authority)获取站点的域部分。这满足了我们对http的要求。我们最近将站点更改为https(大约3天前),但这仍然返回http://..url全部改为https显示在浏览器地址栏中。知道为什么会这样吗? 最佳答案 以下示例工作正常并返回带有“https”的字符串:varuri=newUri("https://www.google.com/?q=102njgn24gk24ng2k");varauthority=uri.GetLeftPart(UriP

c# - Request.QueryString 是如何工作的?

我有一个这样的代码示例:location.href=location.href+"/Edit?pID="+hTable.getObj().ID;;//aspxparID=Request.QueryString["pID"];//c#它有效,我的问题是-如何?逻辑是什么?谢谢:) 最佳答案 HttpRequest类表示向服务器发出的请求,并具有与其关联的各种属性,例如QueryString。ASP.NET运行时解析对服务器的请求并为您填充此信息。阅读HttpRequestProperties获取由ASP.NET代表您填充的所有潜在属性