Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
7.9 KiB

  1. <%@ Import Namespace='System.Data.SqlClient' %>
  2. <%@ Import Namespace='System.Security.Principal' %>
  3. <%@ Import Namespace='UDDI' %>
  4. <%@ Import Namespace='UDDI.Diagnostics' %>
  5. <%@ Import Namespace='UDDI.Web' %>
  6. <script language='C#' runat='server'>
  7. private const string publisherPages =
  8. "{/register.aspx}" +
  9. "{/validate.aspx}" +
  10. "{/admin/admin.aspx}" +
  11. "{/admin/categorization.aspx}" +
  12. "{/admin/changeowner.aspx}" +
  13. "{/admin/default.aspx}" +
  14. "{/admin/impersonate.aspx}" +
  15. "{/admin/statistics.aspx}" +
  16. "{/admin/taxonomy.aspx}" +
  17. "{/edit/default.aspx}" +
  18. "{/edit/edit.aspx}" +
  19. "{/edit/editbinding.aspx}" +
  20. "{/edit/editbusiness.aspx}" +
  21. "{/edit/editcontact.aspx}" +
  22. "{/edit/editinstanceinfo.aspx}" +
  23. "{/edit/editmodel.aspx}" +
  24. "{/edit/editservice.aspx}" +
  25. "{/edit/explorer.aspx}" +
  26. "{/edit/frames.aspx}" +
  27. "{/edit/help.aspx}";
  28. /// ***********************************************************************
  29. /// public Application_BeginRequest
  30. /// -----------------------------------------------------------------------
  31. /// <summary>
  32. /// Called when page processing is begun.
  33. /// </summary>
  34. /// ***********************************************************************
  35. ///
  36. public void Application_BeginRequest( object source, EventArgs eventArgs )
  37. {
  38. //
  39. // Get the virtual path to the script being executed.
  40. //
  41. string thisPage = Request.ServerVariables[ "SCRIPT_NAME" ];
  42. //
  43. // Don't do any further processing for SOAP Web Service files (asmx) and default discoveryURL HTTP handler files (ashx)
  44. // These interfaces handle their own database connections and SSL checks.
  45. //
  46. if( thisPage.IndexOf( ".asmx" ) >= 0 || thisPage.IndexOf( ".ashx" ) >= 0 )
  47. return;
  48. //
  49. // Initialize our context ONCE per request. This call is executeted for both our web site
  50. // as well as the SOAP API.
  51. //
  52. UDDI.Context.Current.Initialize();
  53. //
  54. // Do not remove this call, we need this log information to diagnose issues with
  55. // Context initialization.
  56. //
  57. Debug.Write(
  58. SeverityType.Info,
  59. CategoryType.Website,
  60. "Application_BeginRequest");
  61. //
  62. // Reset the Users Roles to make sure they weren't
  63. // revoked privlages between requests.
  64. //
  65. //
  66. // Don't do this, the Role will be set in the security control, or remain anonymous.
  67. //
  68. // UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  69. //
  70. // Get the virual application root path.
  71. // Handle special case when vdir is the root. In this case set it to a blank string to avoid an extra trailing "/".
  72. //
  73. string root = ( "/" == Request.ApplicationPath ) ? "" : Request.ApplicationPath;
  74. //
  75. // At this point we are only dealing with ASP.NET web pages (aspx)
  76. //
  77. Debug.Enter();
  78. thisPage = thisPage.Substring( root.Length );
  79. Debug.Write(
  80. SeverityType.Info,
  81. CategoryType.Website,
  82. "thisPage=" + thisPage );
  83. //
  84. // Determine whether transactions are required. Transactions are required for all publisher pages.
  85. //
  86. bool publisherPage = false;
  87. if( -1 != publisherPages.IndexOf( "{" + thisPage.ToLower() + "}" ) )
  88. publisherPage = true;
  89. //
  90. // If the System Web Server is set to Stop Mode, then write message and
  91. // Stop processing the Request.
  92. //
  93. if( 0==Config.GetInt( "Run", UDDI.Constants.Run ) )
  94. {
  95. Context.AddError( new UDDIException( ErrorType.E_fatalError,Localization.GetString( "ERROR_SITESTOP" ) ) );
  96. Response.End();
  97. }
  98. //
  99. // Check to see if SSL is required.
  100. //
  101. if( publisherPage && 1 == Config.GetInt( "Security.HTTPS", UDDI.Constants.Security.HTTPS ) && !Request.IsSecureConnection )
  102. {
  103. Context.AddError( new UDDIException( ErrorType.E_fatalError,Localization.GetString( "ERROR_HTTPSREQUIRED" ) ) );
  104. //Response.Write( "<h1>Access denied</h1>This page requires a HTTPS secure connection." );
  105. Response.End();
  106. }
  107. //
  108. // Open the write database (UI always goes through the write database).
  109. //
  110. ConnectionManager.Open( true, publisherPage );
  111. Debug.Leave();
  112. }
  113. /// ***********************************************************************
  114. /// public Application_EndRequest
  115. /// -----------------------------------------------------------------------
  116. /// <summary>
  117. /// Called when page processing is completed.
  118. /// </summary>
  119. /// ***********************************************************************
  120. ///
  121. public void Application_EndRequest( object source, EventArgs eventArgs )
  122. {
  123. //
  124. // Do not remove this call, we need this log information to diagnose issues with
  125. // Context initialization.
  126. //
  127. Debug.Write(
  128. SeverityType.Info,
  129. CategoryType.Website,
  130. "Application_EndRequest");
  131. //
  132. // Get the virtual path to the script being executed.
  133. //
  134. string thisPage = Request.ServerVariables["SCRIPT_NAME"];
  135. //
  136. // Don't do any further processing for SOAP Web Service files (asmx) and default discoveryURL HTTP handler files (ashx)
  137. // These interfaces handle their own database connections.
  138. //
  139. if( thisPage.IndexOf( ".asmx" ) >= 0 || thisPage.IndexOf( ".ashx" ) >= 0 )
  140. return;
  141. Debug.Enter();
  142. //
  143. // If there is an open database connection, close it. We'll also
  144. // check if there is an open transaction, and if there is, commit
  145. // it.
  146. //
  147. if( Context.Items.Contains( "Connection" ) )
  148. {
  149. if( null != ConnectionManager.GetTransaction() )
  150. {
  151. Debug.Write(
  152. SeverityType.Info,
  153. CategoryType.Website,
  154. "Committing database transaction" );
  155. ConnectionManager.Commit();
  156. }
  157. Debug.Write(
  158. SeverityType.Info,
  159. CategoryType.Website,
  160. "Closing database connection" );
  161. ConnectionManager.Close();
  162. }
  163. Debug.Leave();
  164. }
  165. /// ***********************************************************************
  166. /// public Application_Error
  167. /// -----------------------------------------------------------------------
  168. /// <summary>
  169. /// Called when an unhandled exception is encountered while processing
  170. /// the page.
  171. /// </summary>
  172. /// ***********************************************************************
  173. ///
  174. public void Application_Error( object source, EventArgs eventArgs )
  175. {
  176. //
  177. // Get the virtual path to the script being executed.
  178. //
  179. string thisPage = Request.ServerVariables["SCRIPT_NAME"];
  180. //
  181. // Don't do any further processing for SOAP Web Service files (asmx) and default discoveryURL HTTP handler files (ashx)
  182. // These interfaces handle their own errors and database connections.
  183. //
  184. if( thisPage.IndexOf( ".asmx" ) >= 0 || thisPage.IndexOf( ".ashx" ) >= 0 )
  185. return;
  186. Debug.Enter();
  187. //
  188. // Get the virual application root path.
  189. // Handle special case when vdir is the root. In this case set it to a blank string to avoid an extra trailing "/".
  190. //
  191. string root = ( "/" == Request.ApplicationPath ) ? "" : Request.ApplicationPath;
  192. //
  193. // If a database connection is open and there is a transaction
  194. // abort it.
  195. //
  196. if( Context.Items.Contains( "Connection" ) )
  197. {
  198. if( null != ConnectionManager.GetTransaction() )
  199. {
  200. Debug.Write(
  201. SeverityType.Info,
  202. CategoryType.Website,
  203. "Aborting database transaction" );
  204. ConnectionManager.Abort();
  205. }
  206. ConnectionManager.Close();
  207. }
  208. //
  209. // Transfer to an error page.
  210. //
  211. Debug.Write(
  212. SeverityType.Info,
  213. CategoryType.Website,
  214. "Exception was thrown: " + Context.Error.ToString() );
  215. bool frames = ( "true" == Request[ "frames" ] );
  216. Session[ "exception" ] = Context.Error;
  217. Context.ClearError();
  218. Response.Clear();
  219. HttpContext.Current.Response.ClearContent();
  220. Debug.Leave();
  221. Server.Transfer( root + "/error.aspx?frames=" + ( frames ? "true" : "false" ) );
  222. }
  223. </script>