37,950 questions
0
votes
3
answers
141
views
Resolving a circular/recursive dependency with dependency injection
Say I have this interface:
public interface IExample
{
string GetSupportedExtension();
void DoWork(Stream input);
}
a concrete implementation like:
public class PdfExample : IExample
{
...
2
votes
1
answer
930
views
How to temporarily disable [JsonIgnore] attribute?
I am working on a ASP.NET WebApi project. I have a model class that has a property that I don't want to serialize in public calls. For this purpose I am usin [JsonIgnore] for that property and it is ...
9
votes
2
answers
22k
views
The route template cannot start with a '/' or > '~' character and it cannot contain a '?' character
I am getting the an exception with the following route attribute:
[Route("{id}?action=decline")]
Exception:
An exception of type 'System.ArgumentException' occurred in
System.Web.Http.dll but was ...
10
votes
1
answer
14k
views
How to debug JWT and AuthorizeAttribute
I am following this Microsoft Docs tutorial and everything appears to work upto the point where I call the web api with the access token using Postman.
To be specific:
I request a token, Azure AD ...
2
votes
1
answer
10k
views
Adding Authorize Headers and validate in controller
In my ASP.Net Web API Project, i added [Authorize] attribute to the controller. So when i call the method it is returning error as
"Message": "Authorization has been denied for this request."
How to ...
29
votes
5
answers
16k
views
Web Api Model Binding and Polymorphic Inheritance
I am asking if anyone knows if it is possible to to pass into a Web Api a concrete class that inherits from a abstract class.
For example:
public abstract class A
{
A();
}
public class B : A
{
}
...
1
vote
1
answer
281
views
VS 2015 / WebAPI Fiddler 200--Code Executes--Solid Breakpoint not hit
I have cleaned and rebuilt numerous times as well as closed and reopened VS 2015. I have solid red break point and the code executes, other controllers with breakpoints are hit. I don't understand ...
2
votes
4
answers
19k
views
Error: ConnectionRefused (0x274d). System.Net.Sockets.SocketException No connection could be made because the target machine
I had same issue ( link https://superuser.com/questions/394223/iis-cannot-access-folder-for-website-hosting)
I hosted web api service in iis when i hosted i got internal server error i found solution ...
8
votes
8
answers
27k
views
Swagger UI freezes after API fetch and browser crashes
I have an ASP.NET WebAPI project where I am attempting to replace our old XmlDocumentationProvider page with Swagger UI. I am using the swashbuckle swagger for webAPI 5.3.1 nuget package.
I am able ...
26
votes
3
answers
14k
views
What is the difference between AddSerilog and UseSerilog in .NET 6 Web API?
I'm trying to configure Serilog for a Web API project in .NET 6.
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
....
0
votes
0
answers
57
views
Autofac: ObjectDisposedException when resolving dependencies from factory delegate in ASP.NET Web API
I have an ASP.NET Web API project using Autofac for dependency injection.
I register a factory for creating ICommandExecutor based on an enum:
builder.Register<Func<CommandType, ICommandExecutor&...
92
votes
11
answers
245k
views
Getting "error": "unsupported_grant_type" when trying to get a JWT by calling an OWIN OAuth secured Web Api via Postman
I have followed this article to implement an OAuth Authorization server. However when I use post man to get a token, I get an error in the response:
"error": "unsupported_grant_type"
I read ...
2
votes
2
answers
3k
views
Unable to access swagger despite cors enabled Asp.NET WebAPI
I have a WebAPI - .NET framework 4.6.2
I am getting below error on the accessing the webapi via swagger:
Can't read from server. It may not have the appropriate
access-control-origin settings.
I ...
4
votes
1
answer
2k
views
WebApi2 ResponseType attribute of a generic type
I have a generic WebApi controller with CRUD operations like this:
public abstract class BaseController<TEntity> : ApiController where TEntity : class
{
protected abstract DbSet<TEntity&...
1
vote
3
answers
703
views
WebAPI and Azure AD - works fine with obsolete setup, but not when updated to new setup
I have an existing Web API project, which uses Azure AD for authentication.
Prior to my joining the organisation, I understand that this was an ASP.Net 3.1 project, that has since been upgraded to ASP....
0
votes
1
answer
4k
views
WebAPI Put returns HTTPResponseMessage null
I have a requirement to implement simple edit functionality. I am using webapi service to update my test object.
I am calling the below method from the controller post request.
This is the controller ...
1
vote
0
answers
76
views
ASP.NET MVC Date Input Not Binding Correctly in AJAX Post Request
I have built a form which take checkInDate and nights as input. But in the backend when I am debugging it is not showing the date correctly. It is displaying nights correctly but checkInDate is shown ...
3
votes
1
answer
1k
views
Getting confusing "ambiguous reference" error
(Disclaimer): I know what an ambiguous reference is and how to solve it. I am just confused why this appears here
I have the following code:
using SMBLibrary;
namespace SquirrelCam
{
public class ...
1
vote
0
answers
142
views
How can post a xml to an API get way by RestEase?
I did a research in the official page of the RestEase but I don't find a way to post a xml data to a Web API controller.
Is any one have experience to do it?
thank you very much
1
vote
1
answer
2k
views
Install the Web API Client Libraries
I want to install Install-Package Microsoft.AspNet.WebApi.Client. Using From the Tools menu, select Library Package Manager, then select Package Manager Console. In the Package Manager Console window, ...
0
votes
3
answers
1k
views
I am trying to send Email using gmail in ASP.NET C# account but always getting error
I am sending email using gmail and getting the following error:
Error sending email: A connection attempt failed because the connected party did not properly respond after a period of time, or ...
8
votes
3
answers
9k
views
DbSet<> Does not Contain A Definition For 'ToListAsync()' Although I'm Using .NET 3.1 with EF Core
So I tried to add async methods to my routes and to the interfaces, repositories etc and I coded everything properly. Everything looks great but when I try to run the app I get that error:
Error ...
2
votes
5
answers
3k
views
Web API 2 return simple string without quotation mark when return type is IHttpActionResult
My question is referring to this question.
The answer shows only solutions where you would have to change the type of the method to HttpResponseMessage or string.
This is my method:
public ...
48
votes
2
answers
80k
views
Using HttpClient.GetFromJsonAsync(), how to handle HttpRequestException based on HttpStatusCode without extra SendAsync calls?
System.Net.Http.Json's HttpClient extension methods such as GetFromJsonAsync() greatly simplifies the routine codes to retrieve json objects from a web API. It's a pleasure to use.
But because of the ...
1
vote
1
answer
106
views
T5ManagerAPI fails to initialize after .NET 8 publish (works fine locally)
I'm building a .NET 8 Web API that connects to MetaTrader 5 using the MT5 Manager API.
Everything works perfectly when running locally from Visual Studio.
However, after publishing and deploying the ...