무슨 일인지 모르겠지만 라우팅에 문제가있는 것 같습니다. 여기 웹 API JSON 404가 발견되지 않음
는 JSON$("form").submit(function() {
if (api.validateForm()) {
var pid = '1198';
var image = document.getElementById("myCanvas").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
async: false,
url: 'https://localhost:44301/webapi/SaveImage/SaveSignature',
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
window.location.replace("success.aspx");
}
});
}
return false;
});
응용 프로그램 시작 여기
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "webapi/{controller}/{action}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
에게 내 컨트롤러는
public class SaveImageController : ApiController
{
public class CrossDomainActionFilter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
bool needCrossDomain = true;
if (needCrossDomain)
{
actionExecutedContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
}
base.OnActionExecuted(actionExecutedContext);
}
}
[AcceptVerbs("GET", "POST")]
[CrossDomainActionFilter]
public bool SaveSignature(string imageData)
{
string uploadPath = HttpContext.Current.Server.MapPath("Files") + "\\1198\\";
if (!System.IO.Directory.Exists(uploadPath))
{
System.IO.Directory.CreateDirectory(uploadPath);
}
string fileNameWitPath = uploadPath + DateTime.Now.ToString().Replace("/", "-").Replace(" ", "- ").Replace(":", "") + ".png";
using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
return true;
}
[AcceptVerbs("Get")]
public string SayHello(string aye)
{
return "Say Hello from Test Controller";
}
}
방화범 오류 응답
{"Message":"No HTTP resource was found that matches the request URI 'https://localhost:44301/webapi/SaveImage/SaveSignature'.","MessageDetail":"No action was found on the controller 'SaveImage' that matches the request."}
으로 다른 사람을 도움이 될 것입니다,하지만 컨트롤러 조치는 아무 것도 반환하지 않습니다. 액션에 중단 점을 넣으면 트리거됩니까? 그렇다면 무언가를 반환하고 여전히이 문제가 있는지 확인하십시오. –
SaveSignature 메서드가 포함 된 컨트롤러의 이름은 무엇입니까? – mga911
@ mga911 SaveImageController – prospector