Cannot resolve symbol Services when using Configuration.Services.GetContentNegotiator() - asp.net-mvc-4

I wanted to retrieve conneg by using following line of code.
Configuration.Services.GetContentNegotiator
It gives me an error "Cannot resolve symbol Services". I am building ASP.NET Web API using ASP.NET MVC 4. Services is a public property of System.Web.Http.HttpConfiguration but I can't get a reference of that object.

Related

Cannot add a WCF Service Referance on a .Net5 Project

I'm trying to add a service reference to a .NET5 project, and I'm following the directives given on the Microsoft page here, but I run into an error message which is not explanatory at all.
Here are my steps:
I click Next:
Next again:
And at last, I hit Finish and there's the error:
The steps are simple and straightforward, I can add the service through a WebForms application so how can I get past this error with a .NET5 application?
Is your service running successfully?
Do you add an external service or an internal service, and whether the url is automatically generated or manually entered. You can check out this tutorial for more details.
https://learn.microsoft.com/en-us/visualstudio/data-tools/how-to-add-update-or-remove-a-wcf-data-service-reference?view=vs-2022
You can choose to use the dotnet-svcutil tool.
https://learn.microsoft.com/en-us/dotnet/core/additional-tools/dotnet-svcutil-guide?tabs=dotnetsvcutil2x

How to resolve 500 Message:An error has occurred while Accessing API from Azure?

I am working with Azure Mobile Services API, my API on the local host running well. I have checked with the help of Swagger UI. but when I publish my API to azure then after that by accessing the API with Swagger I got this error.
500 : {"Message":"An error has occurred."} http://xxxxxxxxxxx.azurewebsites.net/swagger/docs/v1
Now if I type this route http://xxxxxxxxxxx.azurewebsites.net/tables/doctor?ZUMO-API-VERSION=2.0.0
to any table then I got the result,
why not with swagger?
help me to get on the right path.
Please make sure your XML file is available on the same location as you have defined in the swagger UI properties on Azure.
I would highly recommend to generate your swagger xml file
Steps :
Right click on webapi project
Properties => build tab
Output section - in different folder other than bin.
For example : App_Start\\{ProjectName}.xml

EnableDependencyInjection in OData extension library

Our service has been using ApiController with EnableQuery attribute and we were using System.web.http.odata (odata < 6). When we moved to new ODataControllers in Odata 6.0 dlls, we started getting error no non-odata route registered.
This got solved by using EnableDependencyInjection which apparently creates non-odataroutes containers.
My question is what could be the other side effect (security, route configuration) of calling this method.

Error management in ASP.NET Core using a BaseController

In previous ASP.NET versions I was used to create a BaseController inherited from the other controllers and there intercepting the general error and logging each error with a simple logging method and passing the ExceptionContext filterContext.
Should I do the same in ASP.NET 5?
I see in file Startup.cs that there is a if/else statement that basically separate the debug/live condition, with line
app.UseErrorHandler("/Home/Error");
for a production application.
How am I supposed to hook in the process and log the errors?
Handling and logging errors in ASP.NET 5 involves a few elements.
To handle the error in a production scenario and show an error page, the app.UseExceptionHandler() method is the way to go. The Diagnostics repository on the ASP.NET GitHub organisation includes a sample that shows this. For development-time scenarios where you want to see a full stack trace and other diagnostic information, use app.UseDeveloperExceptionPage() as seen in this sample.
If the application is using ASP.NET MVC 6, then there is an MVC-specific way of handling errors, much as there was in earlier versions of ASP.NET MVC. In ASP.NET MVC 6, a filter (or the Controller itself, which is also a filter) can handle/override the OnActionExecuted method and inspect the ActionExecutedContext parameter to attempt to handle the error.
When it comes to logging, there's a new logging infrastructure in ASP.NET 5 that reports a great deal of information to any registered ILogger. The default project templates in Visual Studio 2015 register some loggers that log errors (and other data) to the console and the Visual Studio debug output window. However, when running in IIS or IIS Express there is no console window (yet!). But if you run from the command line (using dnx web) then you'll see the error. Or, of course, you can register a different logger that writes to a log file or database and see the logs there.
To register a custom ILogger in a web app:
Write a logger that implements the ILogger interface. See the DNX implementations for how to do this.
Add a parameter of type ILoggerFactory to your app's Startup class's Configure method.
In the Configure method call loggerFactory.AddProvider(<some provider>) and pass in an instance of your logger.

Error when calling MvcHttpHandler.ExecuteRequest from custom IHttpHandler

I have a custom IHttpHandler that calls MvcHttpHandler implemented as described in this answer.
It worked well in asp.net MVC2, but after I migrate the code to MVC4 with IISExpress 7.5, I start getting InvalidOperationException on the line:
httpHandler.ProcessRequest(HttpContext.Current);
with message:
'HttpContext.SetSessionStateBehavior' can only be invoked before
'HttpApplication.AcquireRequestState' event is raised.
ASP.NET Development Server does not make any problems.
Does anyone know what's going on here, and how to solve it?
I believe you need to use httpContext.Server.TransferRequest with the MVC update.
See this question: MVC3 Application Inside Webforms Application Routing is throwing a HttpContext.SetSessionStateBehavior Error in IIS7.5