Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am calling WebMethod using angularjs call. I got response when WebMethod inside .aspx.cs but not getting response if WebMethod inside class file(class1.cs).

Call return 403 Forbidden error.

Class file::

using System.Web.Services;
using System.IO;

public class done
{
  [WebMethod]
  public static string test()
  {
      string x = File.ReadAllText(@"C:/Users/Admin/Desktop/live.json");
      return x;
  }
}

How to get response when WebMethod inside class file.

share|improve this question

I could be wrong, but I had issues using WebMethod in .cs files as it is normally used for aspx.cs files. Instead I used HttpPost attribute in my .cs file. I haven't used AngularJS (jQuery guy here) but I can imagine it would have the same issue. This is how I solved my error if you still need help.

CS Controller

    [HttpPost]
    public ReturnType MethodName(ParamType param1, ParamType param1)
    {
       obj = new ReturnType();
       // do something
       return obj;
    }

Ajax call

     $.ajax({
        type: 'POST',
        url: "@Url.Action("MethodName", "Contoller")",
        //if not MVC, just <path to file>/MethodName
        error: function () {
            console.log("=(");
        },
        success: function () {
            console.log("hi");
        }
    })

Hopefully this helps you!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.