title: $http call twice when calling web api
body: <p>I have create a <code>WEB API</code> using <code>ASP.NET MVC WEB API 2.0</code>. Web API contain methods like <code>login</code>, <code>register</code>, etc.
  <br/>
  I am using <code>AngularJS</code> to call the <code>WEB API</code> methods, But it call twice. For e.g. when I call <code>POST</code> method it first call <code>OPTION</code> (I have not created any <code>OPTION</code> method) and then it call the <code>POST</code> method.
  <br/>
  My Code: (for login)
  <br/>
  HTML:</p>
  
  <pre><code>&lt;div class="container" ng-controller="UserAccount"&gt;
      &lt;form ng-submit="loginNow(user)"&gt;
          &lt;input type="email" placeholder="Enter Email" required ng-model="user.email" id="txtEmail" class="form-control" /&gt;
          &lt;br /&gt;
          &lt;input type="password" placeholder="Enter Password" required ng-model="user.password" id="txtPwd" class="form-control" /&gt;
          &lt;br /&gt;
          &lt;button type="submit" class="btn btn-primary"&gt;Login&lt;/button&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><br/>
  AngularJS Controller:
  <br/></p>
  
  <pre><code>$scope.loginNow = function (user) {
          $http.post(rootURL + "login", { email: user.email, password: user.password })
              .success(function (data) {
                  if (data.id &gt; 0) {
                      sessionStorage.setItem('userid', data.id);
                      window.location = '/';
                  }
              });
  }
  </code></pre>
  
  <p><br/>
  WEB API:
  <br/></p>
  
  <pre><code>public class UsersController : ApiController
      {
          private UserEntities db = new UserEntities();
  
          // GET: api/Users
          public IQueryable&lt;Users_tbl&gt; GetUsers_tbl()
          {
              return db.Users_tbl;
          }
  
          [ActionName("login")]
          public IHttpActionResult PostUser_Login(string email, string password)
          {
              int id = db.Users_tbl.Where(a =&gt; a.email == email &amp;&amp; a.password == password).Select(a =&gt; a.id).SingleOrDefault();
              if(id &lt;= 0)
              {
                  return NotFound();
              }
              return Ok(id);
          }
  
          [ActionName("register")]
          public int PostUser_Register(string email, string password)
          {
              int id = db.Users_tbl.Where(a =&gt; a.email == email).Select(a =&gt; a.id).SingleOrDefault();
              if(id &gt; 0)
              {
                  return 1;
              }
              Users_tbl user = new Users_tbl();
              user.email = email;
              user.password = password;
              try
              {
                  db.Users_tbl.Add(user);
                  db.SaveChanges();
              }
              catch
              {
                  return 2;
              }
              return 0;
          }
  
  
          // GET: api/Users/5
          [ResponseType(typeof(Users_tbl))]
          public IHttpActionResult GetUsers_tbl(int id)
          {
              Users_tbl users_tbl = db.Users_tbl.Find(id);
              if (users_tbl == null)
              {
                  return NotFound();
              }
  
              return Ok(users_tbl);
          }
  
  
          // PUT: api/Users/5
          [ResponseType(typeof(void))]
          public IHttpActionResult PutUsers_tbl(int id, Users_tbl users_tbl)
          {
              if (!ModelState.IsValid)
              {
                  return BadRequest(ModelState);
              }
  
              if (id != users_tbl.id)
              {
                  return BadRequest();
              }
  
              db.Entry(users_tbl).State = EntityState.Modified;
  
              try
              {
                  db.SaveChanges();
              }
              catch (DbUpdateConcurrencyException)
              {
                  if (!Users_tblExists(id))
                  {
                      return NotFound();
                  }
                  else
                  {
                      throw;
                  }
              }
  
              return StatusCode(HttpStatusCode.NoContent);
          }
  
          [ActionName("profile")]
          // POST: api/Users
          [ResponseType(typeof(Users_tbl))]
          public IHttpActionResult PostUsers_tbl(Users_tbl users_tbl)
          {
              if (!ModelState.IsValid)
              {
                  return BadRequest(ModelState);
              }
  
              db.Users_tbl.Add(users_tbl);
              db.SaveChanges();
  
              return CreatedAtRoute("DefaultApi", new { id = users_tbl.id }, users_tbl);
          }
  
          // DELETE: api/Users/5
          [ResponseType(typeof(Users_tbl))]
          public IHttpActionResult DeleteUsers_tbl(int id)
          {
              Users_tbl users_tbl = db.Users_tbl.Find(id);
              if (users_tbl == null)
              {
                  return NotFound();
              }
  
              db.Users_tbl.Remove(users_tbl);
              db.SaveChanges();
  
              return Ok(users_tbl);
          }
  
          protected override void Dispose(bool disposing)
          {
              if (disposing)
              {
                  db.Dispose();
              }
              base.Dispose(disposing);
          }
  
          private bool Users_tblExists(int id)
          {
              return db.Users_tbl.Count(e =&gt; e.id == id) &gt; 0;
          }
      }
  </code></pre>