Trả về lỗi và HTTP code trong ASP.Net MVC

1. Trả về 404

public HttpStatusCodeResult StatusCode() {
return HttpNotFound();
}

2. Trả về 401

public HttpStatusCodeResult StatusCode() {
    return new HttpUnauthorizedResult();
}

3. Dùng lớp HttpStatusCodeResult để trả về lỗi

public HttpStatusCodeResult StatusCode() {
return new HttpStatusCodeResult(404, "URL cannot be serviced");
}

Leave a Reply

Your email address will not be published. Required fields are marked *