Difference Between HttpMethod And RequestType Of HttpRequest?
Jan 28, 2010
The HttpRequest class defines two properties:
HttpMethod:
Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.
public string HttpMethod { get; }
The HTTP data transfer method used by the client.
and RequestType:
Gets or sets the HTTP data transfer method (GET or POST) used by the client. public string RequestType { get; set; } A string representing the HTTP invocation type sent by the client.What is the difference between these two properties? When would i want to use one over the other? Which is the proper one to inspect to see what data transfer method was used by the client?The documentation indicates that HttpMethod will return whatever verb was used: such as GET, POST, or HEAD while the documentation on RequestType seems to indicate only one of two possible values: i test with a random sampling of verbs, and both properties seem to support all verbs, and both return the same values:
Testing:
Client Used HttpMethod RequestType
GET GET GET
POST POST POST
HEAD HEAD HEAD
CONNECT CONNECT CONNECT
MKCOL MKCOL MKCOL
PUT PUT PUT
FOOTEST FOOTEST FOOTEST
What is the difference between:
HttpRequest.HttpMethod
HttpRequest.RequestType
and when should i use one over the other? Keywords: iis asp.net http httprequest httphandler
I'm writing unit tests in ASP.NET 4.0 web application (ASP.NET Forms, not MVC). There are several spots in the code where I call the ServerVariables collection to call variables like REMOTE_ADDR. Since my unit tests do not actually initiate HttpRequests when executing my code, things like ServerVariables are Null and therefore error when I try to call HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
All the solutions I've found to address this issue refer to MVC and so they assume that HttpRequest derives from HttpRequestBase, which it does in MVC but not in ASP.NET Forms.I tried using Moq but you can't mock a sealed class, and HttpRequest is unfortunately sealed with no interface.
The problem is.....the request.HttpMethod is GET and not POST and for this reason the "query" string is empty.
there aren´t any other request to this page, but only the "RequestSend" function.
The same code.....run on a test project.....but in the real project....not run.
ps. in the same project not run the Webclient.UploadValue with method=POST and not save in a session ( session["value"]=par ) the string that I want to pass.
We have to ASP.NET applications, one in 1.1 and one in 3.5. In order to log our errors in the same location we are going to create a WebService that the 1.1 app can call. If I include an HttpRequest as one of the parameters to the webservice, will there be a versioning problem?
I'm want to run a "background job" in my ASP.NET application (periodically, as separate thread). And I need host name (DNS name or IP) to do my tasks. The problem - HttpContext.Current may be not available here (it's NULL).
Is there any way to get a host name in not using HttpContext.Current.Request.Url.Host.
I'm going to try to use the WebClient object in .NET to grab the response querystring values sent back by the resource.
I'm familiar with grabbing xml, json, etc. but typically I haven't worked with many NVP type of APIs in terms of grabbing the query immediately from an response sent back from a resource server-side. So how is a query sent back, in the body of a response, header, what? How do you grab it, with the stream object just like you do anything else? This questions relates to the environment I work in C# but really it relates to the web as a whole as well which is why I tagged this in multiple categories as a Request/Response is not MS specific however I am also at the same time trying to utilize the .NET WebClient object.
I have a page web method, and I need to get access to the headers, and particularly the uploaded files. Is this possible? Can a web method receive a file?If not, what would you recommend to upload files without post back? I am using the jQuery forms library that has support for this (and I have had it working with Django), however, I am having a hard time finding answers on how to do this with ASP.NET.
I'm creating HttpContext "by hands" (see [URL]. Does somebody know how can I populate HttpRequest.Browser class's properties (the HttpRequest.Browser.Browser one)? Unfortunately, the HttpBrowserCapabilities class has no the appropriate setter and adding the corresponding http header to the request gives no result.
I have a form on an HTML page that a user needs to use to upload a file which posts to an ASPX page. In the code behind, I want to test if a file has actually been loaded.
if (Request.Files.Count > 0) { DoStuff(Request.Files[0]); } else { throw new Exception("A CSV file must be selected for upload."); }
I am never getting to the else. Is this just how ASP.NET operates? If I have a input element of type file, is it always going to upload a "file" even if one is not selected? What's the proper way to do this? Maybe this?
if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0) { DoStuff(Request.Files[0]); } else { throw new Exception("A CSV file must be selected for upload."); }
I'm trying to fix an issue with an application I'm supporting (I didn't write the code). The code takes an SSRS report and renders it in pdf format. Users are sporadically getting the error indicated in the title. There is no rhyme or reason to when the error is generated (a particular report will run one time and throw the error the next). The code is below.
Public Sub OpenReport() Dim MyParms As New Generic.List(Of ReportParameter) Dim mimeType As String = Nothing Dim encoding As String = Nothing Dim extension As String = Nothing Dim deviceInfo As String = Nothing Dim streamids() As String = Nothing Dim warnings As Microsoft.Reporting.WebForms.Warning() = Nothing Dim bytes() As Byte Dim format As String = "PDF" ''#to open the report in pdf; report viewer invisible Try If dropReports.SelectedItem.Value = "1" Then If Session("IsBDAP") = True Then MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False)) Else MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False)) End If MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False)) If dropVisit.Visible = True Then MyParms.Add(New ReportParameter("VisitId", dropVisit.SelectedItem.Value, False)) End If MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False)) ReportViewer1.ProcessingMode = ProcessingMode.Remote ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI")) ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "MReport" ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials() ReportViewer1.ServerReport.SetParameters(MyParms) ''#Code to convert the report to pdf deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>" bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings) Dim size As Integer = bytes.Length ReportViewer1.ServerReport.Refresh() Response.Buffer = True Response.Clear() Response.ContentType = mimeType Response.AddHeader("content-disposition", "attachment; filename=MReport." + extension) Response.BinaryWrite(bytes) ElseIf dropReports.SelectedItem.Value = "2" Then If Session("IsBDAP") = True Then MyParms.Add(New ReportParameter("SCAId", dropSCA.SelectedItem.Value, False)) Else MyParms.Add(New ReportParameter("SCAId", Server.UrlEncode(Session("SCAId")), False)) End If MyParms.Add(New ReportParameter("ProviderId", dropProvider.SelectedItem.Value, False)) If dropVisit.Visible = True Then MyParms.Add(New ReportParameter("FollowUpVisitId", dropVisit.SelectedItem.Value, False)) End If MyParms.Add(New ReportParameter("FY", dropContractFY.SelectedItem.Value, False)) ReportViewer1.ProcessingMode = ProcessingMode.Remote ReportViewer1.ServerReport.ReportServerUrl = New Uri(System.Configuration.ConfigurationManager.AppSettings("ReportServerURI")) ReportViewer1.ServerReport.ReportPath = Session("ReportsFolder") & "FReport" ReportViewer1.ServerReport.ReportServerCredentials = New MyReportServerCredentials() ReportViewer1.ServerReport.SetParameters(MyParms) ''#Code to convert the report to pdf deviceInfo = "<DeviceInfo>" + "<SimplePageHeaders>True</SimplePageHeaders>" + "</DeviceInfo>" bytes = ReportViewer1.ServerReport.Render(format, deviceInfo, mimeType, encoding, extension, streamids, warnings) ReportViewer1.ServerReport.Refresh() Response.Buffer = True Response.Clear() Response.ContentType = mimeType Response.AddHeader("content-disposition", "attachment; filename=FReport." + extension) Response.BinaryWrite(bytes)
I read that the default length limit is 4MB. None of the reports by themselves are even over 350K. I'm wondering if this could be caused by a caching issue. I'm not an expert, so I need some guidance as to how best to solve the problem. I also want to understand why the issue is happening. note that only 2 reports are shown in the snippet - there are about 30+ reports in the full sub. edit - I tried the proposed solution, but it didn't help (I also tried the Fiddler route, but did not see anything glaring). I thought it might be best to clarify. The reports will run fine for a while, but the execution time gradually gets slower and slower until the application eventually displays the error.
Anyway I can get the object of HTTPRequest? From View or Action? What I want is to read the logon user name and its email address from active directory.
I use HttpRequest, when there is a SOAP fault, I get 500 error. I read that you can get the SOAP fault info in the response stream, but when there is a 500 error, how do you get the response stream?
im writing a whois lookup page for a clients website and the whois query for .com .biz etc is handled by internic,
i create a HTTPRequest and get the response and it returns a whole webpage with the doctype, head tags and body tags, all i want is the data between the tags <pre> and </pre> how would i get just this from the string that is returned?
Is it possible to change or remove http request form inputs in an httpmodule? My goal is to create a security IHttpmodule that will check the request for reasonable values, such as limits on acceptable input and query parameter length, or use the AntiXSS Sanitizer to remove threats, log potential hack attempts, etc. before a request is passed on to a processor.
Because this is a cross cutting concern I'd prefer to find a solution that applies to all requests and affects all ways request values could be accessed, Reqest.Form, Action(model), Action(FormCollection), HttpContext.Current.Request.Form, etc. I'm using MVC and have considered creating custom model binders to clean the data before creating the model instance. But that would be application specific, require remembering to register every model binder and only apply to Action(model).
I develop an asmx web service (i.e. ASP.NET 2.0). There's a piece of code that may read the contents of the HTTP request (via HttpContext.Current.Request.InputStream) while processing it. I realise that InputStream may only be read once for a request, and I make sure I never try to read it more than once.
The problem seems to be that if InputStream happens to be read during the early stages of the application's lifecycle (e.g. after pskill w3wp, during Application_Start), the HTTP request fails with a HTTP 400 - Bad Request error, with no explanation given, no exception thrown and no entry in the httperr log. If it is read later (e.g. within the web method itself), requests run fine whether InputStream is read or not. Application_Start runs fine if InputStream isn't read.
Is this some sort of ASP.NET bug? IIS bug? Or am I doing something wrong by daring to read InputStream? And if so, is there another way to get a look at the "raw" contents of the request without disturbing the inner workings of IIS/ASP.NET? In short, adding this code within Application_Start is enough to reproduce this error: using (StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream))reader.ReadToEnd();
I've been developing classic ASP pages at the job for the past five years and now we are moving to ASP.NET. I'm trying to understand how to get form field values from one page to another and it seems like there is more than one way to do it. In classic ASPI just called request.form collection and got the information. Which way is recommended in .net? Cross Page, Transfer, or HttpRequest?
I thought that <%: had replaced <%=, since mentions on [URL]Prior to ASP.NET 4, the <%= %> syntax was used to execute code and write it out to the page. Starting with ASP.NET 4, you should always use the <%: %> syntax instead..."
I hope this isn't too much of a newbie question. I seem to always use the correct syntax, but I don't really understand why I'm using the <%: and <%= in ASP.NET, and I was hoping someone could clarify for me. I found this article which explains <%= and <%#, but wasn't able to find anything in Google on <%:.