// This copy constructor is used by the granular request validation feature. Since these collections are immutable // once created, it's ok for us to have two collections containing the same data. internal HttpValueCollection(HttpValueCollection col) : base(StringComparer.OrdinalIgnoreCase) { // We explicitly don't copy validation-related fields, as we want the copy to "reset" validation state. But we // do need to go against the underlying NameObjectCollectionBase directly while copying so as to avoid triggering // validation. for (int i = 0; i < col.Count; i++) { ThrowIfMaxHttpCollectionKeysExceeded(); string key = col.BaseGetKey(i); object value = col.BaseGet(i); BaseAdd(key, value); } IsReadOnly = col.IsReadOnly; }
public VirtualEnvironmentMock(string currentVirtualFilePath, string pathInfo, string queryText, string applicationVirtualPath, bool autoInitialize) { _currentVirtualFilePath = currentVirtualFilePath; _currentExecutionFilePath = currentVirtualFilePath; _pathInfo = (pathInfo == null || pathInfo.Length == 0) ? "" : "/" + pathInfo.TrimStart('/'); // prevent null string and ensure '/' prefixed _query = new HttpValueCollection(queryText); _applicationVirtualPath = "/" + ("" + applicationVirtualPath).Trim('/'); if (!_applicationVirtualPath.EndsWith("/")) _applicationVirtualPath = _applicationVirtualPath + "/"; // if (!_currentVirtualFilePath.StartsWith(_applicationVirtualPath)) // { // throw new ArgumentException("currentVirtualFilePath must begin with applicationVirtualPath"); // } _prevEnvironment = VirtualEnvironment.SetInstance(this); if (autoInitialize) { VirtualEnvironment.SetInitialized(); } }
// Forces reevaluation of the QueryString, e.g. as the result of Server.Execute replacing it internal void InvalidateQueryString() { _queryString = null; }
/// <include file='doc\HttpDebugHandler.uex' path='docs/doc[@for="HttpDebugHandler.ProcessRequest"]/*' /> /// <devdoc> /// <para>Drives web processing execution.</para> /// </devdoc> public void ProcessRequest(HttpContext context) { // Debugging must be enabled try { HttpDebugHandlerTimeLog.PrintTickDelta("Entered HttpDebugHandler"); if (!HttpRuntime.DebuggingEnabled) { context.Response.Write(HttpRuntime.FormatResourceString(SR.Debugging_forbidden, context.Request.Path)); context.Response.StatusCode = 403; return; } // Check to see if it's a valid debug command. string command = context.Request.Headers["Command"]; if (command == null) { Debug.Trace("AutoAttach", "No debug command!!"); context.Response.Write(HttpRuntime.FormatResourceString(SR.Invalid_Debug_Request)); context.Response.StatusCode = 500; return; } Debug.Trace("AutoAttach", "Debug command: " + command); if (string.Compare(command, "stop-debug", true, CultureInfo.InvariantCulture) == 0) { context.Response.Write("OK"); return; } if (string.Compare(command, "start-debug", true, CultureInfo.InvariantCulture) != 0) { context.Response.Write(HttpRuntime.FormatResourceString(SR.Invalid_Debug_Request)); context.Response.StatusCode = 500; return; } // Request must be NTLM authenticated string authType = context.WorkerRequest.GetServerVariable("AUTH_TYPE"); // go the metal string logonUser = context.WorkerRequest.GetServerVariable("LOGON_USER"); Debug.Trace("AutoAttach", "Authentication type string: " + ((authType != null) ? authType : "NULL")); Debug.Trace("AutoAttach", "Logon user string: " + ((logonUser != null) ? logonUser : "******")); if (logonUser == null || logonUser.Length == 0 || authType == null || authType.Length == 0 || String.Compare(authType, "basic", true, CultureInfo.InvariantCulture) == 0) { Debug.Trace("AutoAttach", "Invalid logon_user or auth_type string."); context.Response.Write(HttpRuntime.FormatResourceString(SR.Debug_Access_Denied, context.Request.Path)); context.Response.StatusCode = 401; return; } // Get the session ID String sessId = context.Request.Form["DebugSessionID"]; Debug.Trace("AutoAttach", "DebugSessionID: " + ((sessId != null) ? sessId : "NULL")); if (sessId == null || sessId.Length == 0) { context.Response.Write(HttpRuntime.FormatResourceString(SR.Invalid_Debug_ID)); context.Response.StatusCode = 500; return; } string s = sessId.Replace(';', '&'); HttpValueCollection valCol = new HttpValueCollection(s, true, true, Encoding.UTF8); string clsId = (string)valCol["autoattachclsid"]; // Verify clsId bool isClsIdOk = false; if (clsId != null) { for (int i = 0; i < validClsIds.Length; i++) { if (clsId.ToLower(System.Globalization.CultureInfo.InvariantCulture) == validClsIds[i]) { isClsIdOk = true; break; } } } if (isClsIdOk == false) { context.Response.Write(HttpRuntime.FormatResourceString(SR.Debug_Access_Denied, context.Request.Path)); context.Response.StatusCode = 401; Debug.Trace("AutoAttach", "Debug attach not attempted because of invalid CLSID."); return; } // Attach the debugger HttpDebugHandlerTimeLog.PrintTickDelta("About to call into MDM"); int rc = UnsafeNativeMethods.AttachDebugger(clsId, sessId, context.WorkerRequest.GetUserToken()); HttpDebugHandlerTimeLog.PrintTickDelta("Returned from call to MDM"); // If it's not S_OK, then we got a problem if (rc != 0) { Debug.Trace("AutoAttach", "Debug attach failed! Return code: " + rc); context.Response.Write(HttpRuntime.FormatResourceString(SR.Error_Attaching_with_MDM, "0x" + rc.ToString("X8"))); context.Response.StatusCode = 500; return; } Debug.Trace("AutoAttach", "Debug attach successful!"); // Everything ok -- increment counter, return something (not 204) PerfCounters.IncrementCounter(AppPerfCounter.DEBUGGING_REQUESTS); context.Response.Write("OK"); // Set global flag for us HttpRuntime.VSDebugAttach = true; } finally { Debug.Trace("AutoAttach", "Http Debug attach done!"); HttpDebugHandlerTimeLog.PrintTickDelta("Leaving HttpDebugHandler"); HttpDebugHandlerTimeLog.Close(); } }
public HttpRequest(string Filename, string Url, string Querystring) { _iContentLength = -1; _iTotalBytes = -1; _WorkerRequest = null; _sPathTranslated = Filename; _sRequestType = "GET"; _oUrl = new Uri(Url); _sPath = _oUrl.AbsolutePath; _sQueryStringRaw = Querystring; _oQueryString = new HttpValueCollection(Querystring, true, Encoding.ASCII); }
internal HttpValueCollection SwitchForm(HttpValueCollection form) { HttpValueCollection oldForm = _form; _form = form; Unvalidated.InvalidateForm(); return oldForm; }
// Used in integrated pipeline mode to invalidate the params collection // after a change is made to the headers or server variables internal void InvalidateParams() { _params = null; }
// Populates the QueryString property but does not hook up validation. internal HttpValueCollection EnsureQueryString() { if (_queryString == null) { _queryString = new HttpValueCollection(); if (_wr != null) FillInQueryStringCollection(); _queryString.MakeReadOnly(); } return _queryString; }
public IDisposable RewritePath(string newVirtualPath, bool rebaseClientPath) { IDisposable ctx = new RewriteContext(CurrentVirtualPathAndQuery, false, this); int index = newVirtualPath.IndexOf('?'); if (index >= 0) { string newQueryString = (index < (newVirtualPath.Length - 1)) ? newVirtualPath.Substring(index + 1) : string.Empty; _query = new HttpValueCollection(newQueryString); newVirtualPath = newVirtualPath.Substring(0, index); } _currentVirtualFilePath = newVirtualPath; return ctx; }
/* * Public constructor for request that come from arbitrary place * * @param filename physical file name * @param queryString query string */ /// <devdoc> /// <para> /// Initializes an HttpRequest object. /// </para> /// </devdoc> public HttpRequest(String filename, String url, String queryString) { _wr = null; _pathTranslated = filename; _httpMethod = "GET"; _url = new Uri(url); _path = VirtualPath.CreateAbsolute(_url.AbsolutePath); _queryStringText = queryString; _queryStringOverriden = true; _queryString = new HttpValueCollection(_queryStringText, true, true, Encoding.Default); PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_EXECUTING); }
// Forces reevaluation of the Form, e.g. as the result of Server.Execute replacing it internal void InvalidateForm() { _form = null; }
public void ProcessRequest(HttpContext context) { if (!HttpRuntime.DebuggingEnabled) { context.Response.Write(System.Web.SR.GetString("Debugging_forbidden", new object[] { context.Request.Path })); context.Response.StatusCode = 0x193; } else { string str = context.Request.Headers["Command"]; if (str == null) { context.Response.Write(System.Web.SR.GetString("Invalid_Debug_Request")); context.Response.StatusCode = 500; } else if (StringUtil.EqualsIgnoreCase(str, "stop-debug")) { context.Response.Write("OK"); } else if (!StringUtil.EqualsIgnoreCase(str, "start-debug")) { context.Response.Write(System.Web.SR.GetString("Invalid_Debug_Request")); context.Response.StatusCode = 500; } else { string serverVariable = context.WorkerRequest.GetServerVariable("AUTH_TYPE"); if ((string.IsNullOrEmpty(context.WorkerRequest.GetServerVariable("LOGON_USER")) || string.IsNullOrEmpty(serverVariable)) || StringUtil.EqualsIgnoreCase(serverVariable, "basic")) { context.Response.Write(System.Web.SR.GetString("Debug_Access_Denied", new object[] { context.Request.Path })); context.Response.StatusCode = 0x191; } else { string str4 = context.Request.Form["DebugSessionID"]; if (string.IsNullOrEmpty(str4)) { context.Response.Write(System.Web.SR.GetString("Invalid_Debug_ID")); context.Response.StatusCode = 500; } else { HttpValueCollection values = new HttpValueCollection(str4.Replace(';', '&'), true, true, Encoding.UTF8); string str6 = values["autoattachclsid"]; bool flag = false; if (str6 != null) { for (int i = 0; i < validClsIds.Length; i++) { if (StringUtil.EqualsIgnoreCase(str6, validClsIds[i])) { flag = true; break; } } } if (!flag) { context.Response.Write(System.Web.SR.GetString("Debug_Access_Denied", new object[] { context.Request.Path })); context.Response.StatusCode = 0x191; } else { int num2 = UnsafeNativeMethods.AttachDebugger(str6, str4, context.WorkerRequest.GetUserToken()); if (num2 != 0) { context.Response.Write(System.Web.SR.GetString("Error_Attaching_with_MDM", new object[] { "0x" + num2.ToString("X8", CultureInfo.InvariantCulture) })); context.Response.StatusCode = 500; } else { PerfCounters.IncrementCounter(AppPerfCounter.DEBUGGING_REQUESTS); context.Response.Write("OK"); } } } } } } }
private void ParseFormData () { string content_type = ContentType; if (content_type == null) return; content_type = content_type.ToLower (CultureInfo.InvariantCulture); if (content_type == "application/x-www-form-urlencoded") { byte [] arrData = GetRawContent (); Encoding enc = ContentEncoding; string data = enc.GetString (arrData); _oFormData = new HttpValueCollection (data, true, enc); return; } _oFormData = new HttpValueCollection (); if (StrUtils.StartsWith (content_type, "multipart/form-data")) { MultipartContentElement [] parts = GetMultipartFormData (); if (parts == null) return; Encoding content_encoding = ContentEncoding; foreach (MultipartContentElement p in parts) { if (p.IsFormItem) { _oFormData.Add (p.Name, p.GetString (content_encoding)); } } } }
private void ParseServerVariables() { if (null == _WorkerRequest) { return; } if (_oServerVariables == null){ _oServerVariables = new ServerVariablesCollection (this); _oServerVariables.MakeReadOnly (); } }
internal void SetForm (HttpValueCollection form) { _oFormData = form; }
/// <devdoc> /// <para>Drives web processing execution.</para> /// </devdoc> public void ProcessRequest(HttpContext context) { // Debugging must be enabled try { #if PERF HttpDebugHandlerTimeLog.PrintTickDelta("Entered HttpDebugHandler"); #endif if (!HttpRuntime.DebuggingEnabled) { context.Response.Write(SR.GetString(SR.Debugging_forbidden, context.Request.Path)); context.Response.StatusCode = 403; return; } // Check to see if it's a valid debug command. string command = context.Request.Headers["Command"]; if (command == null) { Debug.Trace("AutoAttach", "No debug command!!"); context.Response.Write(SR.GetString(SR.Invalid_Debug_Request)); context.Response.StatusCode = 500; return; } Debug.Trace("AutoAttach", "Debug command: " + command); if (StringUtil.EqualsIgnoreCase(command, "stop-debug")) { context.Response.Write("OK"); return; } if (!StringUtil.EqualsIgnoreCase(command, "start-debug")) { context.Response.Write(SR.GetString(SR.Invalid_Debug_Request)); context.Response.StatusCode = 500; return; } // Request must be NTLM authenticated string authType = context.WorkerRequest.GetServerVariable("AUTH_TYPE"); // go the metal string logonUser = context.WorkerRequest.GetServerVariable("LOGON_USER"); Debug.Trace("AutoAttach", "Authentication type string: " + ((authType != null) ? authType : "NULL")); Debug.Trace("AutoAttach", "Logon user string: " + ((logonUser != null) ? logonUser : "******")); if (String.IsNullOrEmpty(logonUser) || String.IsNullOrEmpty(authType) || StringUtil.EqualsIgnoreCase(authType, "basic")) { Debug.Trace("AutoAttach", "Invalid logon_user or auth_type string."); context.Response.Write(SR.GetString(SR.Debug_Access_Denied, context.Request.Path)); context.Response.StatusCode = 401; return; } // Get the session ID String sessId = context.Request.Form["DebugSessionID"]; Debug.Trace("AutoAttach", "DebugSessionID: " + ((sessId != null) ? sessId : "NULL")); if (String.IsNullOrEmpty(sessId)) { context.Response.Write(SR.GetString(SR.Invalid_Debug_ID)); context.Response.StatusCode = 500; return; } string s = sessId.Replace(';', '&'); HttpValueCollection valCol = new HttpValueCollection(s, true, true, Encoding.UTF8); string clsId = (string) valCol["autoattachclsid"]; // Verify clsId bool isClsIdOk = false; if (clsId != null) { for (int i = 0; i < validClsIds.Length; i++) { if (StringUtil.EqualsIgnoreCase(clsId, validClsIds[i])) { isClsIdOk = true; break; } } } if (isClsIdOk == false) { context.Response.Write(SR.GetString(SR.Debug_Access_Denied, context.Request.Path)); context.Response.StatusCode = 401; Debug.Trace("AutoAttach", "Debug attach not attempted because of invalid CLSID."); return; } // Attach the debugger #if PERF HttpDebugHandlerTimeLog.PrintTickDelta("About to call into MDM"); #endif int rc = UnsafeNativeMethods.AttachDebugger(clsId, sessId, context.WorkerRequest.GetUserToken()); #if PERF HttpDebugHandlerTimeLog.PrintTickDelta("Returned from call to MDM"); #endif // If it's not S_OK, then we got a problem if (rc != 0) { Debug.Trace("AutoAttach", "Debug attach failed! Return code: " + rc); context.Response.Write(SR.GetString(SR.Error_Attaching_with_MDM, "0x" + rc.ToString("X8", CultureInfo.InvariantCulture))); context.Response.StatusCode = 500; return; } Debug.Trace("AutoAttach", "Debug attach successful!"); // Everything ok -- increment counter, return something (not 204) PerfCounters.IncrementCounter(AppPerfCounter.DEBUGGING_REQUESTS); context.Response.Write("OK"); } finally { Debug.Trace("AutoAttach","Http Debug attach done!"); #if PERF HttpDebugHandlerTimeLog.PrintTickDelta("Leaving HttpDebugHandler"); HttpDebugHandlerTimeLog.Close(); #endif } }
internal HttpRequest(VirtualPath virtualPath, String queryString) { _wr = null; _pathTranslated = virtualPath.MapPath(); _httpMethod = "GET"; _url = new Uri("http://localhost" + virtualPath.VirtualPathString); _path = virtualPath; _queryStringText = queryString; _queryStringOverriden = true; _queryString = new HttpValueCollection(_queryStringText, true, true, Encoding.Default); PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_EXECUTING); }
private void ExecuteInternal(IHttpHandler handler, TextWriter writer, bool preserveForm, bool setPreviousPage, VirtualPath path, VirtualPath filePath, string physPath, Exception error, string queryStringOverride) { if (handler == null) { throw new ArgumentNullException("handler"); } HttpRequest request = this._context.Request; HttpResponse response = this._context.Response; HttpApplication applicationInstance = this._context.ApplicationInstance; HttpValueCollection form = null; VirtualPath path2 = null; string queryStringText = null; TextWriter writer2 = null; AspNetSynchronizationContext syncContext = null; this.VerifyTransactionFlow(handler); this._context.PushTraceContext(); this._context.SetCurrentHandler(handler); bool enabled = this._context.SyncContext.Enabled; this._context.SyncContext.Disable(); try { try { this._context.ServerExecuteDepth++; path2 = request.SwitchCurrentExecutionFilePath(filePath); if (!preserveForm) { form = request.SwitchForm(new HttpValueCollection()); if (queryStringOverride == null) { queryStringOverride = string.Empty; } } if (queryStringOverride != null) { queryStringText = request.QueryStringText; request.QueryStringText = queryStringOverride; } if (writer != null) { writer2 = response.SwitchWriter(writer); } Page page = handler as Page; if (page != null) { if (setPreviousPage) { page.SetPreviousPage(this._context.PreviousHandler as Page); } Page page2 = this._context.Handler as Page; if ((page2 != null) && page2.SmartNavigation) { page.SmartNavigation = true; } if (page is IHttpAsyncHandler) { syncContext = this._context.InstallNewAspNetSynchronizationContext(); } } if (((handler is StaticFileHandler) || (handler is DefaultHttpHandler)) && !DefaultHttpHandler.IsClassicAspRequest(filePath.VirtualPathString)) { try { response.WriteFile(physPath); } catch { error = new HttpException(0x194, string.Empty); } } else if (!(handler is Page)) { error = new HttpException(0x194, string.Empty); } else { if (handler is IHttpAsyncHandler) { bool isInCancellablePeriod = this._context.IsInCancellablePeriod; if (isInCancellablePeriod) { this._context.EndCancellablePeriod(); } try { IHttpAsyncHandler handler2 = (IHttpAsyncHandler)handler; IAsyncResult result = handler2.BeginProcessRequest(this._context, null, null); if (!result.IsCompleted) { bool flag3 = false; try { try { } finally { Monitor.Exit(applicationInstance); flag3 = true; } WaitHandle asyncWaitHandle = result.AsyncWaitHandle; if (asyncWaitHandle == null) { goto Label_0210; } asyncWaitHandle.WaitOne(); goto Label_0226; Label_020A: Thread.Sleep(1); Label_0210: if (!result.IsCompleted) { goto Label_020A; } } finally { if (flag3) { Monitor.Enter(applicationInstance); } } } Label_0226: try { handler2.EndProcessRequest(result); } catch (Exception exception) { error = exception; } goto Label_0306; } finally { if (isInCancellablePeriod) { this._context.BeginCancellablePeriod(); } } } using (new DisposableHttpContextWrapper(this._context)) { try { handler.ProcessRequest(this._context); } catch (Exception exception2) { error = exception2; } } } } finally { this._context.ServerExecuteDepth--; this._context.RestoreCurrentHandler(); if (writer2 != null) { response.SwitchWriter(writer2); } if ((queryStringOverride != null) && (queryStringText != null)) { request.QueryStringText = queryStringText; } if (form != null) { request.SwitchForm(form); } request.SwitchCurrentExecutionFilePath(path2); if (syncContext != null) { this._context.RestoreSavedAspNetSynchronizationContext(syncContext); } if (enabled) { this._context.SyncContext.Enable(); } this._context.PopTraceContext(); } } catch { throw; } Label_0306: if (error == null) { return; } if ((error is HttpException) && (((HttpException)error).GetHttpCode() != 500)) { error = null; } if (path != null) { throw new HttpException(System.Web.SR.GetString("Error_executing_child_request_for_path", new object[] { path }), error); } throw new HttpException(System.Web.SR.GetString("Error_executing_child_request_for_handler", new object[] { handler.GetType().ToString() }), error); }
private NameValueCollection GetParams() { if (_params == null) { _params = new HttpValueCollection(64); FillInParamsCollection(); _params.MakeReadOnly(); } return _params; }
internal HttpValueCollection SwitchForm(HttpValueCollection form) { HttpValueCollection values = this._form; this._form = form; return values; }
// Populates the Form property but does not hook up validation. internal HttpValueCollection EnsureForm() { if (_form == null) { _form = new HttpValueCollection(); if (_wr != null) FillInFormCollection(); _form.MakeReadOnly(); } return _form; }
private NameValueCollection GetParams() { if (this._params == null) { this._params = new HttpValueCollection(0x40); this.FillInParamsCollection(); this._params.MakeReadOnly(); } return this._params; }
private void ValidateHttpValueCollection(HttpValueCollection collection, RequestValidationSource requestCollection) { if (GranularValidationEnabled) { // Granular request validation is enabled - validate collection entries only as they're accessed. collection.EnableGranularValidation((key, value) => ValidateString(value, key, requestCollection)); } else { // Granular request validation is disabled - eagerly validate all collection entries. int c = collection.Count; for (int i = 0; i < c; i++) { String key = collection.GetKey(i); // Certain fields shouldn't go through validation - see comments in KeyIsCandidateForValidation for more information. if (!HttpValueCollection.KeyIsCandidateForValidation(key)) { continue; } String val = collection.Get(i); if (!String.IsNullOrEmpty(val)) ValidateString(val, key, requestCollection); } } }