asp.net-web-api

WebAPI : 403 Forbidden after publish website

£可爱£侵袭症+ 提交于 2020-01-13 10:13:09
问题 Alright, I'm having a tough time locating the problem since it works locally but after doing a publish the results are simply: Error Code: 403 Forbidden. The server denied the specified Uniform Resource Locator (URL). Contact the server administrator. (12202) The code: [RoutePrefix("api/v1/project")] public class ProjectController : BaseApiController { [HttpGet] public HttpResponseMessage GetProjects() { HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK); if(User.Identity

How to stop HttpClient.GetAsync(uri) from hanging? [duplicate]

冷暖自知 提交于 2020-01-13 09:58:10
问题 This question already has answers here : C# asynchronous method - help needed (3 answers) Closed 5 years ago . I have the following code that I'm using to call a uri: var uri = string.Format("Helpers/ProfileList/Online/?locationId=0&skip=0&take={0}", numProfiles); HttpResponseMessage response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); The uri is pointing at a custom web api uri (which I can debug and follow through). However, when the last return statement in the api

A route named 'DefaultApi' is already in the route collection

我只是一个虾纸丫 提交于 2020-01-13 09:19:08
问题 This question may seems duplicate but this is slightly different. In all other question in SO I had noticed that they have multiple routes registered. but in my case I have just one route. I am creating asp.net webapi (framework 4.5) and have just one route in RegisterRoutes() method - public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "DefaultApi", url: "rest/{controller}/{id}", defaults: new { id =

WCF vs WebAPI and native mobile devices

拟墨画扇 提交于 2020-01-13 09:01:27
问题 I've been working on a single-page web app that is entirely ajax-based (no POSTs) and for now I'm using ASMX for the web services while it's in development. The web services work with JSON data. For the release, I know I'll need to upgrade to either WCF or WebAPI. Eventually, I plan to build native mobile applications that will work with the same web services as the web app. All things being equal, if I have to choose between the two, which option should I go with so that the web services can

Errors are logged twice when using Elmah with WebApi

寵の児 提交于 2020-01-13 08:55:42
问题 I'm trying to log exceptions from my asp.net web api project using elmah. I am having an issue where each error is logged twice. I am using Elmah.Contrib.Web-Api and my Application class is as follows: public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { GlobalConfiguration.Configuration.Filters.Add(new ElmahHandleErrorApiAttribute()); RouteTable.Routes.MapHubs(); RouteConfig.RegisterRoutes(RouteTable.Routes); #if DEBUG EntityFrameworkProfiler

Autofac Exception: Cannot resolve parameter of constructor 'Void .ctor

筅森魡賤 提交于 2020-01-13 08:28:07
问题 I have the following error: ExceptionMessage=None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'RestAPI.DevelopersController' can be invoked with the available services and parameters: Cannot resolve parameter 'Services.DevelopersService userService' of constructor 'Void .ctor(Services.DevelopersService)'. Global.asax.cs protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); AutoMapperConfig

ASP.NET Web APi - Passing an object as parameter

那年仲夏 提交于 2020-01-13 07:34:27
问题 MakeUser method in the User controller for creating a username and password. [HttpGet] public string MakeUser(UserParameters p) { const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; string pass = ""; Random r = new Random(); for (int i = 0; i < p.Number; i++) { pass += chars[r.Next(0, 62)]; } string firstTwoo = p.Name.Substring(0, 2); string firstThree = p.Surname.Substring(0, 3); return "Your username is: " + firstTwoo + firstThree + "\nYour password is: "

Best way to provide the fingerprint comparison in the server side

南笙酒味 提交于 2020-01-13 06:48:06
问题 I'm going to provide the fingerprint authentication from server side via WebAPI. The below code is the fingerprint comparison part. var allFingerprints = container.Fingerprints.OrderByDescending(p=>p.FingerprintID); List<Fmd> fmdList = new List<Fmd>(); foreach (var fp in allFingerprints) { fmdList.Add(Fmd.DeserializeXml(fp.FMD)); } IdentifyResult identifyResult = Comparison.Identify(customerFmd, 0, fmdList, thresholdScore, 2); If the small amount(<3000) fingerprints are in the DB, I think it

Service Resolver for Stateless Services in Service Fabric

家住魔仙堡 提交于 2020-01-13 06:28:10
问题 I seem to keep getting "Service Not Found" whenever I try to resolve an endpoint for a stateless service. I have tried using the service partition resolver and also the service proxy but they both yield same results. Is there a restriction on Service Fabric or am I misunderstanding how stateless services should be used? I could not find any documentation stating either way. To give more detail on what I am attempting to do. I am building an Api Gateway. The Api Gateway is comprised of

Write to ServiceEventSource from Service Fabric WebAPI controller

一笑奈何 提交于 2020-01-13 04:50:09
问题 In my Stateful service, I can write to the ServiceEventSource by calling this: ServiceEventSource.Current.ServiceMessage(this.Context, "this is my log message"); Does anyone know how I can make that same call in my Stateless WebAPI controller? It seems like I'm unable to get the context into the controller. I noticed it's only available in my OwinCommunicationListener . Basically, I want to be able to log my controllers like this: public async Task<IHttpActionResult> Get(string id) {