PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/mcs/class/System.Web/System.Web.UI/Page.cs

https://bitbucket.org/danipen/mono
C# | 2709 lines | 2271 code | 387 blank | 51 comment | 557 complexity | 0fc39d3113e8ebf2085882fd59eab02a MD5 | raw file
Possible License(s): Unlicense, Apache-2.0, LGPL-2.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. //
  2. // System.Web.UI.Page.cs
  3. //
  4. // Authors:
  5. // Duncan Mak (duncan@ximian.com)
  6. // Gonzalo Paniagua (gonzalo@ximian.com)
  7. // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
  8. // Marek Habersack (mhabersack@novell.com)
  9. //
  10. // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  11. // Copyright (C) 2003-2010 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System;
  33. using System.Collections;
  34. using System.Collections.Generic;
  35. using System.Collections.Specialized;
  36. using System.ComponentModel;
  37. using System.ComponentModel.Design;
  38. using System.ComponentModel.Design.Serialization;
  39. using System.Globalization;
  40. using System.IO;
  41. using System.Security.Permissions;
  42. using System.Security.Principal;
  43. using System.Text;
  44. using System.Threading;
  45. using System.Web;
  46. using System.Web.Caching;
  47. using System.Web.Compilation;
  48. using System.Web.Configuration;
  49. using System.Web.Hosting;
  50. using System.Web.SessionState;
  51. using System.Web.Util;
  52. using System.Web.UI.Adapters;
  53. using System.Web.UI.HtmlControls;
  54. using System.Web.UI.WebControls;
  55. using System.Reflection;
  56. #if NET_4_0
  57. using System.Web.Routing;
  58. #endif
  59. namespace System.Web.UI
  60. {
  61. // CAS
  62. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  63. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  64. [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
  65. [ToolboxItem (false)]
  66. [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
  67. [DesignerSerializer ("Microsoft.VisualStudio.Web.WebForms.WebFormCodeDomSerializer, " + Consts.AssemblyMicrosoft_VisualStudio_Web, "System.ComponentModel.Design.Serialization.TypeCodeDomSerializer, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  68. public partial class Page : TemplateControl, IHttpHandler
  69. {
  70. // static string machineKeyConfigPath = "system.web/machineKey";
  71. bool _eventValidation = true;
  72. object [] _savedControlState;
  73. bool _doLoadPreviousPage;
  74. string _focusedControlID;
  75. bool _hasEnabledControlArray;
  76. bool _viewState;
  77. bool _viewStateMac;
  78. string _errorPage;
  79. bool is_validated;
  80. bool _smartNavigation;
  81. int _transactionMode;
  82. ValidatorCollection _validators;
  83. bool renderingForm;
  84. string _savedViewState;
  85. List <string> _requiresPostBack;
  86. List <string> _requiresPostBackCopy;
  87. List <IPostBackDataHandler> requiresPostDataChanged;
  88. IPostBackEventHandler requiresRaiseEvent;
  89. IPostBackEventHandler formPostedRequiresRaiseEvent;
  90. NameValueCollection secondPostData;
  91. bool requiresPostBackScript;
  92. bool postBackScriptRendered;
  93. bool requiresFormScriptDeclaration;
  94. bool formScriptDeclarationRendered;
  95. bool handleViewState;
  96. string viewStateUserKey;
  97. NameValueCollection _requestValueCollection;
  98. string clientTarget;
  99. ClientScriptManager scriptManager;
  100. bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
  101. PageStatePersister page_state_persister;
  102. CultureInfo _appCulture;
  103. CultureInfo _appUICulture;
  104. // The initial context
  105. HttpContext _context;
  106. // cached from the initial context
  107. HttpApplicationState _application;
  108. HttpResponse _response;
  109. HttpRequest _request;
  110. Cache _cache;
  111. HttpSessionState _session;
  112. [EditorBrowsable (EditorBrowsableState.Never)]
  113. public const string postEventArgumentID = "__EVENTARGUMENT";
  114. [EditorBrowsable (EditorBrowsableState.Never)]
  115. public const string postEventSourceID = "__EVENTTARGET";
  116. const string ScrollPositionXID = "__SCROLLPOSITIONX";
  117. const string ScrollPositionYID = "__SCROLLPOSITIONY";
  118. const string EnabledControlArrayID = "__enabledControlArray";
  119. internal const string LastFocusID = "__LASTFOCUS";
  120. internal const string CallbackArgumentID = "__CALLBACKPARAM";
  121. internal const string CallbackSourceID = "__CALLBACKID";
  122. internal const string PreviousPageID = "__PREVIOUSPAGE";
  123. int maxPageStateFieldLength = -1;
  124. string uniqueFilePathSuffix;
  125. HtmlHead htmlHeader;
  126. MasterPage masterPage;
  127. string masterPageFile;
  128. Page previousPage;
  129. bool isCrossPagePostBack;
  130. bool isPostBack;
  131. bool isCallback;
  132. List <Control> requireStateControls;
  133. HtmlForm _form;
  134. string _title;
  135. string _theme;
  136. string _styleSheetTheme;
  137. #if NET_4_0
  138. string _metaDescription;
  139. string _metaKeywords;
  140. Control _autoPostBackControl;
  141. bool frameworkInitialized;
  142. #endif
  143. Hashtable items;
  144. bool _maintainScrollPositionOnPostBack;
  145. bool asyncMode = false;
  146. TimeSpan asyncTimeout;
  147. const double DefaultAsyncTimeout = 45.0;
  148. List<PageAsyncTask> parallelTasks;
  149. List<PageAsyncTask> serialTasks;
  150. ViewStateEncryptionMode viewStateEncryptionMode;
  151. bool controlRegisteredForViewStateEncryption = false;
  152. #region Constructors
  153. public Page ()
  154. {
  155. scriptManager = new ClientScriptManager (this);
  156. Page = this;
  157. ID = "__Page";
  158. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  159. if (ps != null) {
  160. asyncTimeout = ps.AsyncTimeout;
  161. viewStateEncryptionMode = ps.ViewStateEncryptionMode;
  162. _viewState = ps.EnableViewState;
  163. _viewStateMac = ps.EnableViewStateMac;
  164. } else {
  165. asyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
  166. viewStateEncryptionMode = ViewStateEncryptionMode.Auto;
  167. _viewState = true;
  168. }
  169. #if NET_4_0
  170. this.ViewStateMode = ViewStateMode.Enabled;
  171. #endif
  172. }
  173. #endregion
  174. #region Properties
  175. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  176. [Browsable (false)]
  177. public HttpApplicationState Application {
  178. get { return _application; }
  179. }
  180. [EditorBrowsable (EditorBrowsableState.Never)]
  181. protected bool AspCompatMode {
  182. get { return false; }
  183. set {
  184. // nothing to do
  185. }
  186. }
  187. [EditorBrowsable (EditorBrowsableState.Never)]
  188. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  189. [BrowsableAttribute (false)]
  190. public bool Buffer {
  191. get { return Response.BufferOutput; }
  192. set { Response.BufferOutput = value; }
  193. }
  194. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  195. [Browsable (false)]
  196. public Cache Cache {
  197. get {
  198. if (_cache == null)
  199. throw new HttpException ("Cache is not available.");
  200. return _cache;
  201. }
  202. }
  203. [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
  204. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  205. [Browsable (false), DefaultValue ("")]
  206. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  207. public string ClientTarget {
  208. get { return (clientTarget == null) ? String.Empty : clientTarget; }
  209. set {
  210. clientTarget = value;
  211. if (value == String.Empty)
  212. clientTarget = null;
  213. }
  214. }
  215. [EditorBrowsable (EditorBrowsableState.Never)]
  216. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  217. [BrowsableAttribute (false)]
  218. public int CodePage {
  219. get { return Response.ContentEncoding.CodePage; }
  220. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  221. }
  222. [EditorBrowsable (EditorBrowsableState.Never)]
  223. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  224. [BrowsableAttribute (false)]
  225. public string ContentType {
  226. get { return Response.ContentType; }
  227. set { Response.ContentType = value; }
  228. }
  229. protected internal override HttpContext Context {
  230. get {
  231. if (_context == null)
  232. return HttpContext.Current;
  233. return _context;
  234. }
  235. }
  236. [EditorBrowsable (EditorBrowsableState.Advanced)]
  237. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  238. [BrowsableAttribute (false)]
  239. public string Culture {
  240. get { return Thread.CurrentThread.CurrentCulture.Name; }
  241. set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
  242. }
  243. [EditorBrowsable (EditorBrowsableState.Never)]
  244. [Browsable (false)]
  245. [DefaultValue ("true")]
  246. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  247. public virtual bool EnableEventValidation {
  248. get { return _eventValidation; }
  249. set {
  250. if (IsInited)
  251. throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
  252. _eventValidation = value;
  253. }
  254. }
  255. [Browsable (false)]
  256. public override bool EnableViewState {
  257. get { return _viewState; }
  258. set { _viewState = value; }
  259. }
  260. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  261. [BrowsableAttribute (false)]
  262. [EditorBrowsable (EditorBrowsableState.Never)]
  263. public bool EnableViewStateMac {
  264. get { return _viewStateMac; }
  265. set { _viewStateMac = value; }
  266. }
  267. internal bool EnableViewStateMacInternal {
  268. get { return _viewStateMac; }
  269. set { _viewStateMac = value; }
  270. }
  271. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  272. [Browsable (false), DefaultValue ("")]
  273. [WebSysDescription ("The URL of a page used for error redirection.")]
  274. public string ErrorPage {
  275. get { return _errorPage; }
  276. set {
  277. HttpContext ctx = Context;
  278. _errorPage = value;
  279. if (ctx != null)
  280. ctx.ErrorPage = value;
  281. }
  282. }
  283. [Obsolete ("The recommended alternative is HttpResponse.AddFileDependencies. http://go.microsoft.com/fwlink/?linkid=14202")]
  284. [EditorBrowsable (EditorBrowsableState.Never)]
  285. protected ArrayList FileDependencies {
  286. set {
  287. if (Response != null)
  288. Response.AddFileDependencies (value);
  289. }
  290. }
  291. [Browsable (false)]
  292. [EditorBrowsable (EditorBrowsableState.Never)]
  293. public override string ID {
  294. get { return base.ID; }
  295. set { base.ID = value; }
  296. }
  297. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  298. [Browsable (false)]
  299. public bool IsPostBack {
  300. get { return isPostBack; }
  301. }
  302. public bool IsPostBackEventControlRegistered {
  303. get { return requiresRaiseEvent != null; }
  304. }
  305. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  306. public bool IsReusable {
  307. get { return false; }
  308. }
  309. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  310. [Browsable (false)]
  311. public bool IsValid {
  312. get {
  313. if (!is_validated)
  314. throw new HttpException (Locale.GetText ("Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate."));
  315. foreach (IValidator val in Validators)
  316. if (!val.IsValid)
  317. return false;
  318. return true;
  319. }
  320. }
  321. [Browsable (false)]
  322. public IDictionary Items {
  323. get {
  324. if (items == null)
  325. items = new Hashtable ();
  326. return items;
  327. }
  328. }
  329. [EditorBrowsable (EditorBrowsableState.Never)]
  330. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  331. [BrowsableAttribute (false)]
  332. public int LCID {
  333. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  334. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  335. }
  336. [Browsable (false)]
  337. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  338. public bool MaintainScrollPositionOnPostBack {
  339. get { return _maintainScrollPositionOnPostBack; }
  340. set { _maintainScrollPositionOnPostBack = value; }
  341. }
  342. public PageAdapter PageAdapter {
  343. get {
  344. return Adapter as PageAdapter;
  345. }
  346. }
  347. string _validationStartupScript;
  348. string _validationOnSubmitStatement;
  349. string _validationInitializeScript;
  350. string _webFormScriptReference;
  351. internal string WebFormScriptReference {
  352. get {
  353. if (_webFormScriptReference == null)
  354. _webFormScriptReference = IsMultiForm ? theForm : "window";
  355. return _webFormScriptReference;
  356. }
  357. }
  358. internal string ValidationStartupScript {
  359. get {
  360. if (_validationStartupScript == null) {
  361. _validationStartupScript =
  362. @"
  363. " + WebFormScriptReference + @".Page_ValidationActive = false;
  364. " + WebFormScriptReference + @".ValidatorOnLoad();
  365. " + WebFormScriptReference + @".ValidatorOnSubmit = function () {
  366. if (this.Page_ValidationActive) {
  367. return this.ValidatorCommonOnSubmit();
  368. }
  369. return true;
  370. };
  371. ";
  372. }
  373. return _validationStartupScript;
  374. }
  375. }
  376. internal string ValidationOnSubmitStatement {
  377. get {
  378. if (_validationOnSubmitStatement == null)
  379. _validationOnSubmitStatement = "if (!" + WebFormScriptReference + ".ValidatorOnSubmit()) return false;";
  380. return _validationOnSubmitStatement;
  381. }
  382. }
  383. internal string ValidationInitializeScript {
  384. get {
  385. if (_validationInitializeScript == null)
  386. _validationInitializeScript = "WebFormValidation_Initialize(" + WebFormScriptReference + ");";
  387. return _validationInitializeScript;
  388. }
  389. }
  390. internal IScriptManager ScriptManager {
  391. get { return (IScriptManager) Items [typeof (IScriptManager)]; }
  392. }
  393. #if !TARGET_J2EE
  394. internal string theForm {
  395. get {
  396. return "theForm";
  397. }
  398. }
  399. internal bool IsMultiForm {
  400. get { return false; }
  401. }
  402. #endif
  403. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  404. [Browsable (false)]
  405. public HttpRequest Request {
  406. get {
  407. if (_request == null)
  408. throw new HttpException("Request is not available in this context.");
  409. return RequestInternal;
  410. }
  411. }
  412. internal HttpRequest RequestInternal {
  413. get { return _request; }
  414. }
  415. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  416. [Browsable (false)]
  417. public HttpResponse Response {
  418. get {
  419. if (_response == null)
  420. throw new HttpException ("Response is not available in this context.");
  421. return _response;
  422. }
  423. }
  424. [EditorBrowsable (EditorBrowsableState.Never)]
  425. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  426. [BrowsableAttribute (false)]
  427. public string ResponseEncoding {
  428. get { return Response.ContentEncoding.WebName; }
  429. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  430. }
  431. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  432. [Browsable (false)]
  433. public HttpServerUtility Server {
  434. get { return Context.Server; }
  435. }
  436. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  437. [Browsable (false)]
  438. public virtual HttpSessionState Session {
  439. get {
  440. if (_session != null)
  441. return _session;
  442. try {
  443. _session = Context.Session;
  444. } catch {
  445. // ignore, should not throw
  446. }
  447. if (_session == null)
  448. throw new HttpException ("Session state can only be used " +
  449. "when enableSessionState is set to true, either " +
  450. "in a configuration file or in the Page directive.");
  451. return _session;
  452. }
  453. }
  454. [Filterable (false)]
  455. [Obsolete ("The recommended alternative is Page.SetFocus and Page.MaintainScrollPositionOnPostBack. http://go.microsoft.com/fwlink/?linkid=14202")]
  456. [Browsable (false)]
  457. public bool SmartNavigation {
  458. get { return _smartNavigation; }
  459. set { _smartNavigation = value; }
  460. }
  461. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  462. [Filterable (false)]
  463. [Browsable (false)]
  464. public virtual string StyleSheetTheme {
  465. get { return _styleSheetTheme; }
  466. set { _styleSheetTheme = value; }
  467. }
  468. [Browsable (false)]
  469. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  470. public virtual string Theme {
  471. get { return _theme; }
  472. set { _theme = value; }
  473. }
  474. void InitializeStyleSheet ()
  475. {
  476. if (_styleSheetTheme == null) {
  477. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  478. if (ps != null)
  479. _styleSheetTheme = ps.StyleSheetTheme;
  480. }
  481. #if TARGET_JVM
  482. if (_styleSheetTheme != null && _styleSheetTheme != "")
  483. _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, Context);
  484. #else
  485. if (!String.IsNullOrEmpty (_styleSheetTheme)) {
  486. string virtualPath = "~/App_Themes/" + _styleSheetTheme;
  487. _styleSheetPageTheme = BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (PageTheme)) as PageTheme;
  488. }
  489. #endif
  490. }
  491. void InitializeTheme ()
  492. {
  493. if (_theme == null) {
  494. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  495. if (ps != null)
  496. _theme = ps.Theme;
  497. }
  498. #if TARGET_JVM
  499. if (_theme != null && _theme != "") {
  500. _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, Context);
  501. _pageTheme.SetPage (this);
  502. }
  503. #else
  504. if (!String.IsNullOrEmpty (_theme)) {
  505. string virtualPath = "~/App_Themes/" + _theme;
  506. _pageTheme = BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (PageTheme)) as PageTheme;
  507. if (_pageTheme != null)
  508. _pageTheme.SetPage (this);
  509. }
  510. #endif
  511. }
  512. #if NET_4_0
  513. public Control AutoPostBackControl {
  514. get { return _autoPostBackControl; }
  515. set { _autoPostBackControl = value; }
  516. }
  517. [BrowsableAttribute(false)]
  518. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  519. public RouteData RouteData {
  520. get {
  521. if (_request == null)
  522. return null;
  523. RequestContext reqctx = _request.RequestContext;
  524. if (reqctx == null)
  525. return null;
  526. return reqctx.RouteData;
  527. }
  528. }
  529. [Bindable (true)]
  530. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  531. [Localizable (true)]
  532. public string MetaDescription {
  533. get {
  534. if (_metaDescription == null) {
  535. if (htmlHeader == null) {
  536. if (frameworkInitialized)
  537. throw new InvalidOperationException ("A server-side head element is required to set this property.");
  538. return String.Empty;
  539. } else
  540. return htmlHeader.Description;
  541. }
  542. return _metaDescription;
  543. }
  544. set {
  545. if (htmlHeader == null) {
  546. if (frameworkInitialized)
  547. throw new InvalidOperationException ("A server-side head element is required to set this property.");
  548. _metaDescription = value;
  549. } else
  550. htmlHeader.Description = value;
  551. }
  552. }
  553. [Bindable (true)]
  554. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  555. [Localizable (true)]
  556. public string MetaKeywords {
  557. get {
  558. if (_metaKeywords == null) {
  559. if (htmlHeader == null) {
  560. if (frameworkInitialized)
  561. throw new InvalidOperationException ("A server-side head element is required to set this property.");
  562. return String.Empty;
  563. } else
  564. return htmlHeader.Keywords;
  565. }
  566. return _metaDescription;
  567. }
  568. set {
  569. if (htmlHeader == null) {
  570. if (frameworkInitialized)
  571. throw new InvalidOperationException ("A server-side head element is required to set this property.");
  572. _metaKeywords = value;
  573. } else
  574. htmlHeader.Keywords = value;
  575. }
  576. }
  577. #endif
  578. [Localizable (true)]
  579. [Bindable (true)]
  580. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  581. public string Title {
  582. get {
  583. if (_title == null) {
  584. if (htmlHeader != null && htmlHeader.Title != null)
  585. return htmlHeader.Title;
  586. return String.Empty;
  587. }
  588. return _title;
  589. }
  590. set {
  591. if (htmlHeader != null)
  592. htmlHeader.Title = value;
  593. else
  594. _title = value;
  595. }
  596. }
  597. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  598. [Browsable (false)]
  599. public TraceContext Trace {
  600. get { return Context.Trace; }
  601. }
  602. [EditorBrowsable (EditorBrowsableState.Never)]
  603. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  604. [BrowsableAttribute (false)]
  605. public bool TraceEnabled {
  606. get { return Trace.IsEnabled; }
  607. set { Trace.IsEnabled = value; }
  608. }
  609. [EditorBrowsable (EditorBrowsableState.Never)]
  610. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  611. [BrowsableAttribute (false)]
  612. public TraceMode TraceModeValue {
  613. get { return Trace.TraceMode; }
  614. set { Trace.TraceMode = value; }
  615. }
  616. [EditorBrowsable (EditorBrowsableState.Never)]
  617. protected int TransactionMode {
  618. get { return _transactionMode; }
  619. set { _transactionMode = value; }
  620. }
  621. [EditorBrowsable (EditorBrowsableState.Advanced)]
  622. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  623. [BrowsableAttribute (false)]
  624. public string UICulture {
  625. get { return Thread.CurrentThread.CurrentUICulture.Name; }
  626. set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
  627. }
  628. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  629. [Browsable (false)]
  630. public IPrincipal User {
  631. get { return Context.User; }
  632. }
  633. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  634. [Browsable (false)]
  635. public ValidatorCollection Validators {
  636. get {
  637. if (_validators == null)
  638. _validators = new ValidatorCollection ();
  639. return _validators;
  640. }
  641. }
  642. [MonoTODO ("Use this when encrypting/decrypting ViewState")]
  643. [Browsable (false)]
  644. public string ViewStateUserKey {
  645. get { return viewStateUserKey; }
  646. set { viewStateUserKey = value; }
  647. }
  648. [Browsable (false)]
  649. public override bool Visible {
  650. get { return base.Visible; }
  651. set { base.Visible = value; }
  652. }
  653. #endregion
  654. #region Methods
  655. CultureInfo GetPageCulture (string culture, CultureInfo deflt)
  656. {
  657. if (culture == null)
  658. return deflt;
  659. CultureInfo ret = null;
  660. if (culture.StartsWith ("auto", StringComparison.InvariantCultureIgnoreCase)) {
  661. #if TARGET_J2EE
  662. if (!Context.IsServletRequest)
  663. return deflt;
  664. #endif
  665. string[] languages = Request.UserLanguages;
  666. try {
  667. if (languages != null && languages.Length > 0)
  668. ret = CultureInfo.CreateSpecificCulture (languages[0]);
  669. } catch {
  670. }
  671. if (ret == null)
  672. ret = deflt;
  673. } else
  674. ret = CultureInfo.CreateSpecificCulture (culture);
  675. return ret;
  676. }
  677. [EditorBrowsable (EditorBrowsableState.Never)]
  678. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  679. AsyncCallback cb,
  680. object extraData)
  681. {
  682. throw new NotImplementedException ();
  683. }
  684. [EditorBrowsable (EditorBrowsableState.Never)]
  685. [MonoNotSupported ("Mono does not support classic ASP compatibility mode.")]
  686. protected void AspCompatEndProcessRequest (IAsyncResult result)
  687. {
  688. throw new NotImplementedException ();
  689. }
  690. [EditorBrowsable (EditorBrowsableState.Advanced)]
  691. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  692. {
  693. if (Request.BrowserMightHaveSpecialWriter)
  694. return Request.Browser.CreateHtmlTextWriter(tw);
  695. else
  696. return new HtmlTextWriter (tw);
  697. }
  698. [EditorBrowsable (EditorBrowsableState.Never)]
  699. public void DesignerInitialize ()
  700. {
  701. InitRecursive (null);
  702. }
  703. [EditorBrowsable (EditorBrowsableState.Advanced)]
  704. protected internal virtual NameValueCollection DeterminePostBackMode ()
  705. {
  706. // if request was transfered from other page such Transfer
  707. if (_context.IsProcessingInclude)
  708. return null;
  709. HttpRequest req = Request;
  710. if (req == null)
  711. return null;
  712. NameValueCollection coll = null;
  713. if (0 == String.Compare (Request.HttpMethod, "POST", true, Helpers.InvariantCulture)
  714. #if TARGET_J2EE
  715. || !_context.IsServletRequest
  716. #endif
  717. )
  718. coll = req.Form;
  719. else {
  720. string query = Request.QueryStringRaw;
  721. if (query == null || query.Length == 0)
  722. return null;
  723. coll = req.QueryString;
  724. }
  725. WebROCollection c = (WebROCollection) coll;
  726. allow_load = !c.GotID;
  727. if (allow_load)
  728. c.ID = GetTypeHashCode ();
  729. else
  730. allow_load = (c.ID == GetTypeHashCode ());
  731. if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
  732. return null;
  733. #if TARGET_J2EE
  734. if (getFacesContext () != null && _context.Handler != _context.CurrentHandler) {
  735. // check if it is PreviousPage
  736. string prevViewId = coll [PreviousPageID];
  737. if (!String.IsNullOrEmpty (prevViewId)) {
  738. string appPath = VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
  739. prevViewId = prevViewId.Substring (appPath.Length);
  740. isCrossPagePostBack = String.Compare (prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), StringComparison.OrdinalIgnoreCase) == 0;
  741. }
  742. }
  743. #endif
  744. return coll;
  745. }
  746. public override Control FindControl (string id) {
  747. if (id == ID)
  748. return this;
  749. else
  750. return base.FindControl (id);
  751. }
  752. Control FindControl (string id, bool decode) {
  753. #if TARGET_J2EE
  754. if (decode)
  755. id = DecodeNamespace (id);
  756. #endif
  757. return FindControl (id);
  758. }
  759. [Obsolete ("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202")]
  760. [EditorBrowsable (EditorBrowsableState.Advanced)]
  761. public string GetPostBackClientEvent (Control control, string argument)
  762. {
  763. return scriptManager.GetPostBackEventReference (control, argument);
  764. }
  765. [Obsolete ("The recommended alternative is ClientScript.GetPostBackClientHyperlink. http://go.microsoft.com/fwlink/?linkid=14202")]
  766. [EditorBrowsable (EditorBrowsableState.Advanced)]
  767. public string GetPostBackClientHyperlink (Control control, string argument)
  768. {
  769. return scriptManager.GetPostBackClientHyperlink (control, argument);
  770. }
  771. [Obsolete ("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202")]
  772. [EditorBrowsable (EditorBrowsableState.Advanced)]
  773. public string GetPostBackEventReference (Control control)
  774. {
  775. return scriptManager.GetPostBackEventReference (control, String.Empty);
  776. }
  777. [Obsolete ("The recommended alternative is ClientScript.GetPostBackEventReference. http://go.microsoft.com/fwlink/?linkid=14202")]
  778. [EditorBrowsable (EditorBrowsableState.Advanced)]
  779. public string GetPostBackEventReference (Control control, string argument)
  780. {
  781. return scriptManager.GetPostBackEventReference (control, argument);
  782. }
  783. internal void RequiresFormScriptDeclaration ()
  784. {
  785. requiresFormScriptDeclaration = true;
  786. }
  787. internal void RequiresPostBackScript ()
  788. {
  789. if (requiresPostBackScript)
  790. return;
  791. ClientScript.RegisterHiddenField (postEventSourceID, String.Empty);
  792. ClientScript.RegisterHiddenField (postEventArgumentID, String.Empty);
  793. requiresPostBackScript = true;
  794. RequiresFormScriptDeclaration ();
  795. }
  796. [EditorBrowsable (EditorBrowsableState.Never)]
  797. public virtual int GetTypeHashCode ()
  798. {
  799. return 0;
  800. }
  801. [MonoTODO ("The following properties of OutputCacheParameters are silently ignored: CacheProfile, SqlDependency")]
  802. [EditorBrowsable (EditorBrowsableState.Never)]
  803. protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
  804. {
  805. if (cacheSettings.Enabled) {
  806. InitOutputCache(cacheSettings.Duration,
  807. cacheSettings.VaryByContentEncoding,
  808. cacheSettings.VaryByHeader,
  809. cacheSettings.VaryByCustom,
  810. cacheSettings.Location,
  811. cacheSettings.VaryByParam);
  812. HttpResponse response = Response;
  813. HttpCachePolicy cache = response != null ? response.Cache : null;
  814. if (cache != null && cacheSettings.NoStore)
  815. cache.SetNoStore ();
  816. }
  817. }
  818. [MonoTODO ("varyByContentEncoding is not currently used")]
  819. [EditorBrowsable (EditorBrowsableState.Never)]
  820. protected virtual void InitOutputCache(int duration,
  821. string varyByContentEncoding,
  822. string varyByHeader,
  823. string varyByCustom,
  824. OutputCacheLocation location,
  825. string varyByParam)
  826. {
  827. if (duration <= 0)
  828. // No need to do anything, cache will be ineffective anyway
  829. return;
  830. HttpResponse response = Response;
  831. HttpCachePolicy cache = response.Cache;
  832. bool set_vary = false;
  833. HttpContext ctx = Context;
  834. DateTime timestamp = ctx != null ? ctx.Timestamp : DateTime.Now;
  835. switch (location) {
  836. case OutputCacheLocation.Any:
  837. cache.SetCacheability (HttpCacheability.Public);
  838. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  839. cache.SetLastModified (timestamp);
  840. set_vary = true;
  841. break;
  842. case OutputCacheLocation.Client:
  843. cache.SetCacheability (HttpCacheability.Private);
  844. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  845. cache.SetLastModified (timestamp);
  846. break;
  847. case OutputCacheLocation.Downstream:
  848. cache.SetCacheability (HttpCacheability.Public);
  849. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  850. cache.SetLastModified (timestamp);
  851. break;
  852. case OutputCacheLocation.Server:
  853. cache.SetCacheability (HttpCacheability.Server);
  854. set_vary = true;
  855. break;
  856. case OutputCacheLocation.None:
  857. break;
  858. }
  859. if (set_vary) {
  860. if (varyByCustom != null)
  861. cache.SetVaryByCustom (varyByCustom);
  862. if (varyByParam != null && varyByParam.Length > 0) {
  863. string[] prms = varyByParam.Split (';');
  864. foreach (string p in prms)
  865. cache.VaryByParams [p.Trim ()] = true;
  866. cache.VaryByParams.IgnoreParams = false;
  867. } else {
  868. cache.VaryByParams.IgnoreParams = true;
  869. }
  870. if (varyByHeader != null && varyByHeader.Length > 0) {
  871. string[] hdrs = varyByHeader.Split (';');
  872. foreach (string h in hdrs)
  873. cache.VaryByHeaders [h.Trim ()] = true;
  874. }
  875. if (PageAdapter != null) {
  876. if (PageAdapter.CacheVaryByParams != null) {
  877. foreach (string p in PageAdapter.CacheVaryByParams)
  878. cache.VaryByParams [p] = true;
  879. }
  880. if (PageAdapter.CacheVaryByHeaders != null) {
  881. foreach (string h in PageAdapter.CacheVaryByHeaders)
  882. cache.VaryByHeaders [h] = true;
  883. }
  884. }
  885. }
  886. response.IsCached = true;
  887. cache.Duration = duration;
  888. cache.SetExpires (timestamp.AddSeconds (duration));
  889. }
  890. [EditorBrowsable (EditorBrowsableState.Never)]
  891. protected virtual void InitOutputCache (int duration,
  892. string varyByHeader,
  893. string varyByCustom,
  894. OutputCacheLocation location,
  895. string varyByParam)
  896. {
  897. InitOutputCache (duration, null, varyByHeader, varyByCustom, location, varyByParam);
  898. }
  899. [Obsolete ("The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). http://go.microsoft.com/fwlink/?linkid=14202")]
  900. public bool IsClientScriptBlockRegistered (string key)
  901. {
  902. return scriptManager.IsClientScriptBlockRegistered (key);
  903. }
  904. [Obsolete ("The recommended alternative is ClientScript.IsStartupScriptRegistered(string key). http://go.microsoft.com/fwlink/?linkid=14202")]
  905. public bool IsStartupScriptRegistered (string key)
  906. {
  907. return scriptManager.IsStartupScriptRegistered (key);
  908. }
  909. public string MapPath (string virtualPath)
  910. {
  911. return Request.MapPath (virtualPath);
  912. }
  913. protected internal override void Render (HtmlTextWriter writer)
  914. {
  915. if (MaintainScrollPositionOnPostBack) {
  916. ClientScript.RegisterWebFormClientScript ();
  917. ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
  918. ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
  919. StringBuilder script = new StringBuilder ();
  920. script.AppendLine ("<script type=\"text/javascript\">");
  921. script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_START);
  922. script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
  923. script.AppendLine (theForm + ".submit = function () { " + WebFormScriptReference + ".WebForm_SaveScrollPositionSubmit(); }");
  924. script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
  925. script.AppendLine (theForm + ".onsubmit = function () { " + WebFormScriptReference + ".WebForm_SaveScrollPositionOnSubmit(); }");
  926. if (IsPostBack) {
  927. script.AppendLine (theForm + ".oldOnLoad = window.onload;");
  928. script.AppendLine ("window.onload = function () { " + WebFormScriptReference + ".WebForm_RestoreScrollPosition (); };");
  929. }
  930. script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_END);
  931. script.AppendLine ("</script>");
  932. ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
  933. }
  934. #if TARGET_J2EE
  935. if (bool.Parse (WebConfigurationManager.AppSettings [RenderBodyContentOnlyKey] ?? "false")) {
  936. for (Control c = this.Form; c != null; c = c.Parent) {
  937. HtmlGenericControl ch = (c as HtmlGenericControl);
  938. if (ch != null && ch.TagName == "body") {
  939. ch.RenderChildren (writer);
  940. return;
  941. }
  942. }
  943. }
  944. #endif
  945. base.Render (writer);
  946. }
  947. void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  948. {
  949. writer.WriteLine ();
  950. ClientScriptManager.WriteBeginScriptBlock (writer);
  951. RenderClientScriptFormDeclaration (writer, formUniqueID);
  952. writer.WriteLine (WebFormScriptReference + "._form = " + theForm + ";");
  953. writer.WriteLine (WebFormScriptReference + ".__doPostBack = function (eventTarget, eventArgument) {");
  954. writer.WriteLine ("\tif(" + theForm + ".onsubmit && " + theForm + ".onsubmit() == false) return;");
  955. writer.WriteLine ("\t" + theForm + "." + postEventSourceID + ".value = eventTarget;");
  956. writer.WriteLine ("\t" + theForm + "." + postEventArgumentID + ".value = eventArgument;");
  957. writer.WriteLine ("\t" + theForm + ".submit();");
  958. writer.WriteLine ("}");
  959. ClientScriptManager.WriteEndScriptBlock (writer);
  960. }
  961. void RenderClientScriptFormDeclaration (HtmlTextWriter writer, string formUniqueID)
  962. {
  963. if (formScriptDeclarationRendered)
  964. return;
  965. if (PageAdapter != null) {
  966. writer.WriteLine ("\tvar {0} = {1};\n", theForm, PageAdapter.GetPostBackFormReference(formUniqueID));
  967. } else {
  968. writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
  969. writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
  970. }
  971. #if TARGET_J2EE
  972. // TODO implement callback on portlet
  973. string serverUrl = Request.RawUrl;
  974. writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl));
  975. writer.WriteLine ("\twindow.TARGET_J2EE = true;");
  976. writer.WriteLine ("\twindow.IsMultiForm = {0};", IsMultiForm ? "true" : "false");
  977. #endif
  978. formScriptDeclarationRendered = true;
  979. }
  980. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  981. {
  982. if (renderingForm)
  983. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  984. renderingForm = true;
  985. writer.WriteLine ();
  986. if (requiresFormScriptDeclaration || (scriptManager != null && scriptManager.ScriptsPresent) || PageAdapter != null) {
  987. ClientScriptManager.WriteBeginScriptBlock (writer);
  988. RenderClientScriptFormDeclaration (writer, formUniqueID);
  989. ClientScriptManager.WriteEndScriptBlock (writer);
  990. }
  991. if (handleViewState)
  992. #if TARGET_J2EE
  993. if (getFacesContext () != null) {
  994. javax.faces.application.ViewHandler viewHandler = getFacesContext ().getApplication ().getViewHandler ();
  995. javax.faces.context.ResponseWriter oldFacesWriter = SetupResponseWriter (writer);
  996. try {
  997. viewHandler.writeState (getFacesContext ());
  998. }
  999. finally {
  1000. getFacesContext ().setResponseWriter (oldFacesWriter);
  1001. }
  1002. } else
  1003. #endif
  1004. scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
  1005. scriptManager.WriteHiddenFields (writer);
  1006. if (requiresPostBackScript) {
  1007. RenderPostBackScript (writer, formUniqueID);
  1008. postBackScriptRendered = true;
  1009. }
  1010. scriptManager.WriteWebFormClientScript (writer);
  1011. scriptManager.WriteClientScriptBlocks (writer);
  1012. }
  1013. internal IStateFormatter GetFormatter ()
  1014. {
  1015. return new ObjectStateFormatter (this);
  1016. }
  1017. internal string GetSavedViewState ()
  1018. {
  1019. return _savedViewState;
  1020. }
  1021. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  1022. {
  1023. scriptManager.SaveEventValidationState ();
  1024. scriptManager.WriteExpandoAttributes (writer);
  1025. scriptManager.WriteHiddenFields (writer);
  1026. if (!postBackScriptRendered && requiresPostBackScript)
  1027. RenderPostBackScript (writer, formUniqueID);
  1028. scriptManager.WriteWebFormClientScript (writer);
  1029. scriptManager.WriteArrayDeclares (writer);
  1030. scriptManager.WriteStartupScriptBlocks (writer);
  1031. renderingForm = false;
  1032. postBackScriptRendered = false;
  1033. }
  1034. void ProcessPostData (NameValueCollection data, bool second)
  1035. {
  1036. NameValueCollection requestValues = _requestValueCollection == null ? new NameValueCollection (SecureHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant) : _requestValueCollection;
  1037. if (data != null && data.Count > 0) {
  1038. var used = new Dictionary <string, string> (StringComparer.Ordinal);
  1039. foreach (string id in data.AllKeys) {
  1040. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID || id == ClientScriptManager.EventStateFieldName)
  1041. continue;
  1042. if (used.ContainsKey (id))
  1043. continue;
  1044. used.Add (id, id);
  1045. Control ctrl = FindControl (id, true);
  1046. if (ctrl != null) {
  1047. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  1048. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  1049. if (pbdh == null) {
  1050. if (pbeh != null)
  1051. formPostedRequiresRaiseEvent = pbeh;
  1052. continue;
  1053. }
  1054. if (pbdh.LoadPostData (id, requestValues) == true) {
  1055. if (requiresPostDataChanged == null)
  1056. requiresPostDataChanged = new List <IPostBackDataHandler> ();
  1057. requiresPostDataChanged.Add (pbdh);
  1058. }
  1059. if (_requiresPostBackCopy != null)
  1060. _requiresPostBackCopy.Remove (id);
  1061. } else if (!second) {
  1062. if (secondPostData == null)
  1063. secondPostData = new NameValueCollection (SecureHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant);
  1064. secondPostData.Add (id, data [id]);
  1065. }
  1066. }
  1067. }
  1068. List <string> list1 = null;
  1069. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  1070. string [] handlers = (string []) _requiresPostBackCopy.ToArray ();
  1071. foreach (string id in handlers) {
  1072. IPostBackDataHandler pbdh = FindControl (id, true) as IPostBackDataHandler;
  1073. if (pbdh != null) {
  1074. _requiresPostBackCopy.Remove (id);
  1075. if (pbdh.LoadPostData (id, requestValues)) {
  1076. if (requiresPostDataChanged == null)
  1077. requiresPostDataChanged = new List <IPostBackDataHandler> ();
  1078. requiresPostDataChanged.Add (pbdh);
  1079. }
  1080. } else if (!second) {
  1081. if (list1 == null)
  1082. list1 = new List <string> ();
  1083. list1.Add (id);
  1084. }
  1085. }
  1086. }
  1087. _requiresPostBackCopy = second ? null : list1;
  1088. if (second)
  1089. secondPostData = null;
  1090. }
  1091. [EditorBrowsable (EditorBrowsableState.Never)]
  1092. public virtual void ProcessRequest (HttpContext context)
  1093. {
  1094. SetContext (context);
  1095. #if TARGET_J2EE
  1096. bool wasException = false;
  1097. IHttpHandler jsfHandler = getFacesContext () != null ? EnterThread () : null;
  1098. #endif
  1099. if (clientTarget != null)
  1100. Request.ClientTarget = clientTarget;
  1101. WireupAutomaticEvents ();
  1102. //-- Control execution lifecycle in the docs
  1103. // Save culture information because it can be modified in FrameworkInitialize()
  1104. _appCulture = Thread.CurrentThread.CurrentCulture;
  1105. _appUICulture = Thread.CurrentThread.CurrentUICulture;
  1106. FrameworkInitialize ();
  1107. #if NET_4_0
  1108. frameworkInitialized = true;
  1109. #endif
  1110. context.ErrorPage = _errorPage;
  1111. try {
  1112. InternalProcessRequest ();
  1113. #if TARGET_J2EE
  1114. } catch (Exception ex) {
  1115. wasException = true;
  1116. HandleException (ex);
  1117. #else
  1118. } catch (ThreadAbortException taex) {
  1119. if (FlagEnd.Value == taex.ExceptionState)
  1120. Thread.ResetAbort ();
  1121. else
  1122. throw;
  1123. } catch (Exception e) {
  1124. ProcessException (e);
  1125. #endif
  1126. } finally {
  1127. #if TARGET_J2EE
  1128. if (getFacesContext () != null)
  1129. ExitThread (jsfHandler);
  1130. else if (!wasException)
  1131. #endif
  1132. ProcessUnload ();
  1133. }
  1134. }
  1135. void ProcessException (Exception e) {
  1136. // We want to remove that error, as we're rethrowing to stop
  1137. // further processing.
  1138. Trace.Warn ("Unhandled Exception", e.ToString (), e);
  1139. _context.AddError (e); // OnError might access LastError
  1140. OnError (EventArgs.Empty);
  1141. if (_context.HasError (e)) {
  1142. _context.ClearError (e);
  1143. #if TARGET_JVM
  1144. vmw.common.TypeUtils.Throw (e);
  1145. #else
  1146. throw new HttpUnhandledException (null, e);
  1147. #endif
  1148. }
  1149. }
  1150. void ProcessUnload () {
  1151. try {
  1152. RenderTrace ();
  1153. UnloadRecursive (true);
  1154. } catch {}
  1155. #if TARGET_J2EE
  1156. if (getFacesContext () != null) {
  1157. if(IsCrossPagePostBack)
  1158. _context.Items [CrossPagePostBack] = this;
  1159. }
  1160. #endif
  1161. if (Thread.CurrentThread.CurrentCulture.Equals (_appCulture) == false)
  1162. Thread.CurrentThread.CurrentCulture = _appCulture;
  1163. if (Thread.CurrentThread.CurrentUICulture.Equals (_appUICulture) == false)
  1164. Thread.CurrentThread.CurrentUICulture = _appUICulture;
  1165. _appCulture = null;
  1166. _appUICulture = null;
  1167. }
  1168. delegate void ProcessRequestDelegate (HttpContext context);
  1169. sealed class DummyAsyncResult : IAsyncResult
  1170. {
  1171. readonly object state;
  1172. readonly WaitHandle asyncWaitHandle;
  1173. readonly bool completedSynchronously;
  1174. readonly bool isCompleted;
  1175. public DummyAsyncResult (bool isCompleted, bool completedSynchronously, object state)
  1176. {
  1177. this.isCompleted = isCompleted;
  1178. this.completedSynchronously = completedSynchronously;
  1179. this.state = state;
  1180. if (isCompleted) {
  1181. asyncWaitHandle = new ManualResetEvent (true);
  1182. }
  1183. else {
  1184. asyncWaitHandle = new ManualResetEvent (false);
  1185. }
  1186. }
  1187. #region IAsyncResult Members
  1188. public object AsyncState {
  1189. get { return state; }
  1190. }
  1191. public WaitHandle AsyncWaitHandle {
  1192. get { return asyncWaitHandle; }
  1193. }
  1194. public bool CompletedSynchronously {
  1195. get { return completedSynchronously; }
  1196. }
  1197. public bool IsCompleted {
  1198. get { return isCompleted; }
  1199. }
  1200. #endregion
  1201. }
  1202. [EditorBrowsable (EditorBrowsableState.Never)]
  1203. protected IAsyncResult AsyncPageBeginProcessRequest (HttpContext context, AsyncCallback callback, object extraData)
  1204. {
  1205. ProcessRequest (context);
  1206. DummyAsyncResult asyncResult = new DummyAsyncResult (true, true, extraData);
  1207. if (callback != null) {
  1208. callback (asyncResult);
  1209. }
  1210. return asyncResult;
  1211. }
  1212. [EditorBrowsable (EditorBrowsableState.Never)]
  1213. protected void AsyncPageEndProcessRequest (IAsyncResult result)
  1214. {
  1215. }
  1216. void InternalProcessRequest ()
  1217. {
  1218. if (PageAdapter != null)
  1219. _requestValueCollection = PageAdapter.DeterminePostBackMode();
  1220. else
  1221. _requestValueCollection = this.DeterminePostBackMode();
  1222. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1223. if (_requestValueCollection != null) {
  1224. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1225. _doLoadPreviousPage = true;
  1226. } else {
  1227. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1228. // LAMESPEC: on Callback IsPostBack is set to false, but true.
  1229. //isPostBack = !isCallback;
  1230. isPostBack = true;
  1231. }
  1232. string lastFocus = _requestValueCollection [LastFocusID];
  1233. if (!String.IsNullOrEmpty (lastFocus))
  1234. _focusedControlID = UniqueID2ClientID (lastFocus);
  1235. }
  1236. if (!isCrossPagePostBack) {
  1237. if (_context.PreviousHandler is Page)
  1238. previousPage = (Page) _context.PreviousHandler;
  1239. }
  1240. Trace.Write ("aspx.page", "Begin PreInit");
  1241. OnPreInit (EventArgs.Empty);
  1242. Trace.Write ("aspx.page", "End PreInit");
  1243. InitializeTheme ();
  1244. ApplyMasterPage ();
  1245. Trace.Write ("aspx.page", "Begin Init");
  1246. InitRecursive (null);
  1247. Trace.Write ("aspx.page", "End Init");
  1248. Trace.Write ("aspx.page", "Begin InitComplete");
  1249. OnInitComplete (EventArgs.Empty);
  1250. Trace.Write ("aspx.page", "End InitComplete");
  1251. renderingForm = false;
  1252. #if TARGET_J2EE
  1253. if (getFacesContext () != null)
  1254. if (IsPostBack || IsCallback)
  1255. return;
  1256. #endif
  1257. RestorePageState ();
  1258. ProcessPostData ();
  1259. ProcessRaiseEvents ();
  1260. if (ProcessLoadComplete ())
  1261. return;
  1262. #if TARGET_J2EE
  1263. if (getFacesContext () != null) {
  1264. getFacesContext ().renderResponse ();
  1265. return;
  1266. }
  1267. #endif
  1268. RenderPage ();
  1269. }
  1270. void RestorePageState ()
  1271. {
  1272. if (IsPostBack || IsCallback) {
  1273. if (_requestValueCollection != null)
  1274. scriptManager.RestoreEventValidationState (
  1275. _requestValueCollection [ClientScriptManager.EventStateFieldName]);
  1276. Trace.Write ("aspx.page", "Begin LoadViewState");
  1277. LoadPageViewState ();
  1278. Trace.Write ("aspx.page", "End LoadViewState");
  1279. }
  1280. }
  1281. void ProcessPostData ()
  1282. {
  1283. if (IsPostBack || IsCallback) {
  1284. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1285. ProcessPostData (_requestValueCollection, false);
  1286. Trace.Write ("aspx.page", "End ProcessPostData");
  1287. }
  1288. ProcessLoad ();
  1289. if (IsPostBack || IsCallback) {
  1290. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1291. ProcessPostData (secondPostData, true);
  1292. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1293. }
  1294. }
  1295. void ProcessLoad ()
  1296. {
  1297. Trace.Write ("aspx.page", "Begin PreLoad");
  1298. OnPreLoad (EventArgs.Empty);
  1299. Trace.Write ("aspx.page", "End PreLoad");
  1300. Trace.Write ("aspx.page", "Begin Load");
  1301. LoadRecursive ();
  1302. Trace.Write ("aspx.page", "End Load");
  1303. }
  1304. void ProcessRaiseEvents ()
  1305. {
  1306. if (IsPostBack || IsCallback) {
  1307. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1308. RaiseChangedEvents ();
  1309. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1310. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1311. RaisePostBackEvents ();
  1312. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1313. }
  1314. }
  1315. bool ProcessLoadComplete ()
  1316. {
  1317. Trace.Write ("aspx.page", "Begin LoadComplete");
  1318. OnLoadComplete (EventArgs.Empty);
  1319. Trace.Write ("aspx.page", "End LoadComplete");
  1320. if (IsCrossPagePostBack)
  1321. return true;
  1322. if (IsCallback) {
  1323. #if TARGET_J2EE
  1324. if (getFacesContext () != null) {
  1325. _callbackTarget = GetCallbackTarget ();
  1326. ProcessRaiseCallbackEvent (_callbackTarget, ref _callbackEventError);
  1327. return true;
  1328. }
  1329. #endif
  1330. string result = ProcessCallbackData ();
  1331. HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
  1332. callbackOutput.Write (result);
  1333. callbackOutput.Flush ();
  1334. return true;
  1335. }
  1336. Trace.Write ("aspx.page", "Begin PreRender");
  1337. PreRenderRecursiveInternal ();
  1338. Trace.Write ("aspx.page", "End PreRender");
  1339. ExecuteRegisteredAsyncTasks ();
  1340. Trace.Write ("aspx.page", "Begin PreRenderComplete");
  1341. OnPreRenderComplete (EventArgs.Empty);
  1342. Trace.Write ("aspx.page", "End PreRenderComplete");
  1343. Trace.Write ("aspx.page", "Begin SaveViewState");
  1344. SavePageViewState ();
  1345. Trace.Write ("aspx.page", "End SaveViewState");
  1346. Trace.Write ("aspx.page", "Begin SaveStateComplete");
  1347. OnSaveStateComplete (EventArgs.Empty);
  1348. Trace.Write ("aspx.page", "End SaveStateComplete");
  1349. return false;
  1350. }
  1351. internal void RenderPage ()
  1352. {
  1353. scriptManager.ResetEventValidationState ();
  1354. //--
  1355. Trace.Write ("aspx.page", "Begin Render");
  1356. HtmlTextWriter output = CreateHtmlTextWriter (Response.Output);
  1357. RenderControl (output);
  1358. Trace.Write ("aspx.page", "End Render");
  1359. }
  1360. internal void SetContext (HttpContext context)
  1361. {
  1362. _context = context;
  1363. _application = context.Application;
  1364. _response = context.Response;
  1365. _request = context.Request;
  1366. _cache = context.Cache;
  1367. }
  1368. void RenderTrace ()
  1369. {
  1370. TraceManager traceManager = HttpRuntime.TraceManager;
  1371. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1372. return;
  1373. Trace.SaveData ();
  1374. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1375. return;
  1376. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1377. HtmlTextWriter output = new HtmlTextWriter (Response.Output);
  1378. Trace.Render (output);
  1379. }
  1380. }
  1381. void RaisePostBackEvents ()
  1382. {
  1383. if (requiresRaiseEvent != null) {
  1384. RaisePostBackEvent (requiresRaiseEvent, null);
  1385. return;
  1386. }
  1387. if (formPostedRequiresRaiseEvent != null) {
  1388. RaisePostBackEvent (formPostedRequiresRaiseEvent, null);
  1389. return;
  1390. }
  1391. NameValueCollection postdata = _requestValueCollection;
  1392. if (postdata == null)
  1393. return;
  1394. string eventTarget = postdata [postEventSourceID];
  1395. IPostBackEventHandler target;
  1396. if (String.IsNullOrEmpty (eventTarget)) {
  1397. #if NET_4_0
  1398. target = AutoPostBackControl as IPostBackEventHandler;
  1399. if (target != null)
  1400. RaisePostBackEvent (target, null);
  1401. else
  1402. #endif
  1403. if (formPostedRequiresRaiseEvent != null)
  1404. RaisePostBackEvent (formPostedRequiresRaiseEvent, null);
  1405. else
  1406. Validate ();
  1407. return;
  1408. }
  1409. target = FindControl (eventTarget, true) as IPostBackEventHandler;
  1410. #if NET_4_0
  1411. if (target == null)
  1412. target = AutoPostBackControl as IPostBackEventHandler;
  1413. #endif
  1414. if (target == null)
  1415. return;
  1416. string eventArgument = postdata [postEventArgumentID];
  1417. RaisePostBackEvent (target, eventArgument);
  1418. }
  1419. internal void RaiseChangedEvents ()
  1420. {
  1421. if (requiresPostDataChanged == null)
  1422. return;
  1423. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1424. ipdh.RaisePostDataChangedEvent ();
  1425. requiresPostDataChanged = null;
  1426. }
  1427. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1428. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1429. {
  1430. sourceControl.RaisePostBackEvent (eventArgument);
  1431. }
  1432. [Obsolete ("The recommended alternative is ClientScript.RegisterArrayDeclaration(string arrayName, string arrayValue). http://go.microsoft.com/fwlink/?linkid=14202")]
  1433. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1434. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1435. {
  1436. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1437. }
  1438. [Obsolete ("The recommended alternative is ClientScript.RegisterClientScriptBlock(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202")]
  1439. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1440. public virtual void RegisterClientScriptBlock (string key, string script)
  1441. {
  1442. scriptManager.RegisterClientScriptBlock (key, script);
  1443. }
  1444. [Obsolete]
  1445. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1446. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1447. {
  1448. scriptM

Large files files are truncated, but you can click here to view the full file