【C# HttpContext(盗)】教程文章相关的互联网学习教程文章

C#-函数的名称是什么,与HttpUtility.JavaScriptStringEncode相反?【代码】

我需要评估字符串上的转义序列.为了转义字符串,使用了HttpUtility.JavaScriptStringEncode或类似的东西.我该如何进行相反的转换? 这是一个例子:var s = @"otehu""oeuhnoaoaehuoatehuoeu";var t = HttpUtility.JavaScriptStringEncode(s);var n = Decode(t);我需要这样的功能解码,这将使n == s;解决方法:我发现此功能发布在另一个论坛上:public static string JavaScriptStringDecode(string source) {// Replace some chars.var...

C#https登录并下载文件【代码】

我已经成功连接到登录页面,但是,我不确定如何登录并获取登录背后的文件.下面是我用来建立连接的代码.private static bool bypassAllCertificateStuff(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error){return true;}public static void Processing(){string url = "https://app/templat";HttpWebRequest request;HttpWebResponse response;CookieContainer cookies;ServicePoin...

C#-使用HttpWebRequest传输到ftp站点【代码】

我正在尝试将Excel文件传输到sftp站点,并且我的代码可以正确执行,但是在站点上看不到该文件.private static void SendFile(string FileName){FileStream rdr = new FileStream(FileName + ".csv", FileMode.Open);HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://sftp.somesite.com");HttpWebResponse resp;req.Method = "Post";req.Credentials = new NetworkCredential("UN", "PW", "Domain");req.ContentLengt...

c#-如何在asp.net应用程序中从jquery设置HttpPost终结点【代码】

我正在尝试使用Fine Uploader jQuery示例.基本上,这只是将文件从客户端页面上传到Web服务器的一种方法. 有一个示例,说明了如何在project’s GitHub page的服务器端设置文件流. 如何从脚本中调用此HttpPost端点?简单的jQuery示例如下所示:$(document).ready(function () {$('#jquery-wrapped-fine-uploader').fineUploader({request: {endpoint: 'WhatToWriteHere??'},debug: true});});那么您在端点中键入什么呢?我想它会像Name...

c#-使用httpResponse.End摆脱ThreadAbortException

有谁知道用不引发ThreadAbortException而不引起性能问题的东西替换httpResponse.End()的方法吗?有人建议做一个“ HttpContext.Current.ApplicationInstance.CompleteRequest()”,但这并不能完成httpResponse.End()所做的所有事情,例如将缓冲的数据发送给客户端,这对我来说是个问题.解决方法:首先,我怀疑这确实会引起重大问题.但是,总的来说,这并不是一个好主意……实际上,这是对异常的滥用. (无论如何,IMO.) 从the documentation开...

使用HttpContext.Current(C#)访问Global.asax.cs中的Public Static变量时遇到问题【代码】

在一个Web项目中,我在global.asax.cs中定义了一个公共静态变量(存储),需要在整个应用程序中对其进行访问.public class Global : HttpApplication {public static UserDataStore Store;void Application_Start(object sender, EventArgs e){Store = new UserDataStore();Store.CurrentUsers = new Hashtable();}void Session_Start(object sender, EventArgs e){if (!Store.UserExists(HttpContext.Current.Session.SessionID))Stor...

c#-单元测试以确保仅选定的HTTP动词适用于WebAPI【代码】

使用WebAPI. 我们已经创建的测试之一是确保对于特定控制器,仅允许GET动词. 编写了一个使用MVC帮助页面的测试HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress); config.Routes.MapHttpRoute("SearchAPI", "api/{controller}/{id}");HttpSelfHostServer server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); IApiExplorer apiExplorer = config.Services.GetApiExplorer(); var api...

c#-无法在Mono中加载类型’System.Web.Http.WebHost.Routing.HttpRouteExceptionHandler’【代码】

我尝试在Mono中使用最新的Asp.Net Web API,但错误显示如下:System.TypeLoadException Could not load type 'System.Web.Http.WebHost.Routing.HttpRouteExceptionHandler' from assembly 'System.Web.Http.WebHost, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): System...

c#-httpclient-如何在多部分中将Content-Disposition设置为“ application / json;”【代码】

我正在尝试使用System.Net.Http.Httpclient在C#和wp8中编写多篇文章. 这是我的代码的片段:varclient = new HttpClient();client.DefaultRequestHeaders.TryAddWithoutValidation( "Content-Type", "application/json");content = new MultipartFormDataContent(); content.Add(new StringContent(requestObj, Encoding.UTF8, "application/json"), "request");但是使用Fiddler,我注意到我发送的是: 内容处置:表单数据;名称...

C#-HTTPS的HttpWebRequest收到403禁止错误【代码】

我从C#项目中调用GetListCollection方法时收到错误消息“ 403 Forbidden”.在线2013和URL中的sharepoint版本以HTTPS开头. 我的HTTP标头请求的代码是:string _url = "https://my.sharepoint.com/"+ "_vti_bin/Lists.asmx";string soapStr =@"<?xml version=""1.0"" encoding=""utf-8""?><soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:...

C#-HttpResponseException的抛出未被ExceptionFilterAttribute捕获【代码】

我有一堂课:public class ApiExceptionFilterAttribute : ExceptionFilterAttribute,IExceptionFilter { public override void OnException(HttpActionExecutedContext context){// ... etc...} }…因此我已经在global.asax.cs中注册:public class WebApiApplication : System.Web.HttpApplication {protected void Application_Start(){var exceptionFilter = new ApiExceptionFilterAttribute();GlobalConfiguration.Co...

C#-Web API-为每个线程设置HttpRequestMessage ID吗?【代码】

我有一个用C#编码的Web API. Web API使用与其他内部组件共享的功能.它取决于单线程流,并使用线程本地存储来存储对象和会话信息.请不要说它是好是坏,这就是我要处理的. 在网络API中,我已使用SendAsync实现了自定义消息处理程序(DelagatingHandler)protected async override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)这是基于...

C#:System.Web.HttpResponse类在Intellisense中不可用【代码】

因此,我正在用C#Visual Studio 2013编写一个程序.在代码的顶部(包括用法),我有:using System.Web;但是当我尝试使用该行时:HttpResponse httpResp = (HttpResponse)response;然后Intellisense表示没有HttpResponse类,尽管根据此页面,HttpResponse是System.Web命名空间的一部分: 此外,它没有让我选择其他什么可以导入的使该类可用的选项.我在这里做错了什么?不推荐使用HttpResponse吗?如果是,是否有其他方法来获取http响应的状态...

Android Xamarin C#:带有ServiceStack和自签名证书的Https【代码】

因此,我正在使用自签名证书将所有Http Web服务更改为Https进行测试(对于我正在制作的android应用),并且它们在服务器端都可以正常运行,我知道这是因为我可以将证书添加到PC的证书存储中,并且完美访问该网站,涉及到我的android应用对其进行调用时,我在客户端遇到了什么麻烦. 我的Servicestack调用看起来像这样:var client = new JsonServiceClient(stubServicesBaseUrl);return client.Get(new GetLastStatusUpdate()).StatusUpdate...

C#进行异步HTTP调用【代码】

我希望我的网站能够调用URL,仅此而已.我不需要它来等待回复.我的ASP.Net项目以前使用的是webRequest.BeginGetResponse(null,requestState),但最近已停止工作.没有引发任何错误,但我已经确认从未调用过该URL. 当我使用webRequest.GetResponse()时,URL会被调用,但是这种方法不是异步的,我需要这样做. 这是我的代码,有什么错误的主意吗?HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url)); webRequest.Me...