asp.net-web-api

Override Message “the value {0} is invalid for {1}” in case of int in WebAPI

我与影子孤独终老i 提交于 2020-01-04 06:11:42
问题 I have a variable name CountryId (Integer Type). If user provides a string or any random input to CountryId , the In-built DefaultBindingModel in ASP.Net throws an error : The value '<script>gghghg</script>' is not valid for CountryId. I want to override this message and provide my own text if the ModelState fails. I want a generic solution. I've searched and tried many solutions, but they only worked for MVC applications, not webAPI . public class IntegerModelBinder : DefaultModelBinder {

SignalR and IIS recycle

限于喜欢 提交于 2020-01-04 05:31:09
问题 i want to create a server that send notifications to client using SignalR - using groups suppose that my site was recycled - what will happen to the groups as they are not persist 回答1: You would need to persist your groups in external permanent storage. Look for more details here: http://www.asp.net/signalr/overview/hubs-api/working-with-groups 来源: https://stackoverflow.com/questions/18111304/signalr-and-iis-recycle

Asp.net MVC Web Api Http put and delete requests failing

我的梦境 提交于 2020-01-04 05:05:50
问题 I am using Asp.net MVC 4 Web Api project. MY application uses mvc to implement a web site. It makes http requests to the web api to implement server functionality. Regular page requests to controllers work fine and it is able to display web pages. The application is able to make get and post requests to the api. But when it tries to to put or delete web requests it gets "Failed to load resource: the server responded with a status of 501 (Not Implemented) " The application is hosted on iis 6.

Asp.net MVC Web Api Http put and delete requests failing

回眸只為那壹抹淺笑 提交于 2020-01-04 05:05:10
问题 I am using Asp.net MVC 4 Web Api project. MY application uses mvc to implement a web site. It makes http requests to the web api to implement server functionality. Regular page requests to controllers work fine and it is able to display web pages. The application is able to make get and post requests to the api. But when it tries to to put or delete web requests it gets "Failed to load resource: the server responded with a status of 501 (Not Implemented) " The application is hosted on iis 6.

Azure AD OAuth client credentials grant flow with Web API AuthorizeAttribute Roles

时光毁灭记忆、已成空白 提交于 2020-01-04 03:18:23
问题 Given We have a .NET Web API service. It secures access to controllers and actions using the AuthorizeAttribute with Roles . For example: [Authorize(Roles = "Reader,Requester,Editor,Approver,Administrator")] There is an App Registration within Azure Active Directory for this application. It uses OAuth for user impersonation, and users are authenticating correctly. There are many tutorials available on getting to this point. Intent We wish to have an unattended scheduled process (a script)

WebApi custom JsonConverter not called

*爱你&永不变心* 提交于 2020-01-04 02:55:16
问题 I implemented a custom JsonConverter for Guids. If I declare it on the properties (of type Guid) of the class serialized like so [JsonConverter(typeof(JsonGuidConverter))] then it gets called and works fine. However, I'd like to use it "automatically", without needed the attributes, so I do this: var formatters = GlobalConfiguration.Configuration.Formatters; var jsonFormatter = formatters.JsonFormatter; jsonFormatter.SerializerSettings.Converters.Add(new JsonGuidConverter()); Unfortunately

No MediaTypeFormatter is available 'text/html'

时间秒杀一切 提交于 2020-01-04 01:19:08
问题 I have written a ServiceHelper class that will assist with POST's to a C# Web API controller public class ServiceHelper<TResponse, TRequest> : IServiceHelper<TResponse, TRequest> { public TResponse Execute ( string endpoint, string controller, string action, TRequest request, string format = "application/json" ) { using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(endpoint); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add

How to generate ATOM and RSS2 feeds with ASP.NET Web API?

女生的网名这么多〃 提交于 2020-01-03 21:50:08
问题 What steps are needed to adjust the default XML output of the ASP.NET Web API to generate ATOM and RSS2 feeds? 回答1: You will need to implement a custom MediaTypeFormatter. You might want to check Filip's blog post on RSS & Atom MediaTypeFormatter for ASP.NET WebAPI. 来源: https://stackoverflow.com/questions/12750905/how-to-generate-atom-and-rss2-feeds-with-asp-net-web-api

How to generate ATOM and RSS2 feeds with ASP.NET Web API?

…衆ロ難τιáo~ 提交于 2020-01-03 21:50:03
问题 What steps are needed to adjust the default XML output of the ASP.NET Web API to generate ATOM and RSS2 feeds? 回答1: You will need to implement a custom MediaTypeFormatter. You might want to check Filip's blog post on RSS & Atom MediaTypeFormatter for ASP.NET WebAPI. 来源: https://stackoverflow.com/questions/12750905/how-to-generate-atom-and-rss2-feeds-with-asp-net-web-api

Asp.NET WebApi Convention based approach Url/Route query

為{幸葍}努か 提交于 2020-01-03 19:37:30
问题 I'm not sure of the 'best practice' way forward for an asp.net webapi convention based rest service that needs to return a 'sub property' of a resource. eg: UsersController public User Get(int id) { ... } //returns named user via /api/v1/Users/23 but if I want to return a given users role collection I think I'd like a url of /api/v1/Users/23/Roles If you were using my api would you consider this acceptable? If it is acceptable, what would my routeTemplate and method signature look like (sorry