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");

}

source: gockinhnghiem.com
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 nhận xét:

Đăng nhận xét