title: Is it possible to host WebMethods and an ASP.NET app on the same AppDomain?
body: <p>I have added some <a href="http://msdn.microsoft.com/en-us/library/byxd99hx%28v=vs.90%29.aspx" rel="nofollow">web methods</a> to my ASP.NET page like the following to enable <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">AJAX calls using jQuery</a> on the client side of my application:</p>
  
  <pre><code>public partial class MyPage : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          // Page load logic...
      }
  
      [WebMethod]
      [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
      public static string MyWebMethod()
      {
          // web method logic...
      }
  }
  </code></pre>
  
  <p>However, I noticed using the debugger that my web methods are being processed on a different <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.aspx" rel="nofollow">AppDomain</a> than my ASP.NET Page's AppDomain, hence each one of them has its own set of static variables which is causing me some trouble.</p>
  
  <p>So I would like to know if it's somehow possible to host WebMethods (or a web-service) and an ASP.NET app on the same AppDomain, enabling both of them access to the same set of static variables?</p>
  
  <p>Thanks in advance! </p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>I'm hosting my app on IIS 7.0</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>As Jupaol's answer clearly shows it is possible to host WebMethods and an ASP.NET page on the same appDomain, nevertheless here is what I found after running more tests:</p>
  
  <p>If my jQuery.ajax call sets its URL like this:</p>
  
  <pre><code>$.ajax({
           url: "/MyFolder/MyPage.aspx/MyWebMethod",
           contentType: "application/json; charset=utf-8",
           success: AjaxSuccess,
           error: AjaxError
  });
  </code></pre>
  
  <p>IIS creates two appDomains on my Web site (same <a href="http://msdn.microsoft.com/en-us/library/ms524661%28v=vs.90%29.aspx" rel="nofollow">web site key</a>), one for the page request and another for the WebMethod request. Their <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.friendlyname.aspx" rel="nofollow">FriendlyNames</a> are showed below:</p>
  
  <ul>
  <li>"/LM/W3SVC/1/ROOT-6-129872125368848248" (WebMethod)</li>
  <li>"/LM/W3SVC/1/ROOT/WebApp-5-129872125273487796" (ASP.NET page request)</li>
  </ul>
  
  <p>However, if the jQuery.ajax call URL is set like this:</p>
  
  <pre><code>$.ajax({
           url: "MyPage.aspx/MyWebMethod",
           contentType: "application/json; charset=utf-8",
           success: AjaxSuccess,
           error: AjaxError
  });
  </code></pre>
  
  <p>Only one appDomain gets created to serve both requests:</p>
  
  <ul>
  <li>"/LM/W3SVC/1/ROOT/WebApp-7-129872126989518526"</li>
  </ul>
  
  <p>Unfortunately I wasn't able to find an explanation for this behaviour, and the only thing I can think of that may be related to this issue is that my web site uses <a href="http://en.wikipedia.org/wiki/HTTP_Secure" rel="nofollow">https</a> on some pages and not in others.</p>