In my web API, I am using a filter. On authorization, I am checking a valid time interval and if not inside this interval I am giving a response as follows. I wonder if I can return web.http.results instead of httpresponsemessage?
var response = new HttpResponseMessage
{
StatusCode = (HttpStatusCode)429,
ReasonPhrase = "Invalid Request Time",
Content = new StringContent("Requests are permitted between " + WebConfigurationManager.AppSettings["TimeStart"].ToString() + " AM and " + WebConfigurationManager.AppSettings["TimeEnd"].ToString() + " PM.")
};
The response is like this;
{
"Message": "Requests are permitted between 11:00 AM and 22:30 PM."
}
Best Regards.
Keep your friends close and your enemies even closer
{
"Message": "Requests are permitted between 11:00 AM and 22:30 PM."
}
The result type is json, you can just return like below:
public IHttpActionResult Get()
{
return Json(new { Message = "Requests are permitted between 10 AM and 10 PM." });
}
Best Regards,
Jiadong Meng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Content = new StringContent("{\"Message\":\"Requests are permitted between " +
WebConfigurationManager.AppSettings["TimeStart"].ToString() +
" AM and " + WebConfigurationManager.AppSettings["TimeEnd"].ToString() +
" PM.\"}", System.Text.Encoding.UTF8, "application/json"),
Keep your friends close and your enemies even closer
Member
527 Points
2729 Posts
Web.Http.Results
Apr 13, 2020 05:55 PM|cenk1536|LINK
Hi there,
In my web API, I am using a filter. On authorization, I am checking a valid time interval and if not inside this interval I am giving a response as follows. I wonder if I can return web.http.results instead of httpresponsemessage?
The response is like this;
Best Regards.
Participant
1320 Points
491 Posts
Re: Web.Http.Results
Apr 14, 2020 10:08 AM|jiadongm|LINK
Hi cenk1536,
The result type is json, you can just return like below:
Best Regards,
Jiadong Meng
Member
527 Points
2729 Posts
Re: Web.Http.Results
Apr 14, 2020 11:26 AM|cenk1536|LINK
I mean here;
Member
527 Points
2729 Posts
Re: Web.Http.Results
Apr 14, 2020 12:08 PM|cenk1536|LINK
This solved my problem,