Is there a way to use Swagger to decorate the ASP.NET MVC 5 controllers?
It does work for Web API controllers. However, we have ASP.NET MVC 5 controllers that return JSON results and we would like to document those endpoints using Swagger and expose the /swagger endpoint to display them.
Related
I'm testing out ServiceStack to see how much faster the development is with this product rather than with Asp.Net Core's Web API or similar products.
I have successfully set up Service Stack with my own configuration of IdentityServer4 and everything runs fine.
My confusion is whether working with IdentityServer4 means I am required to now maintain a Web Api project along with ServiceStack? What's the reason the API is there?
I can see that I can make direct calls to the endpoints (requiring Authentication, roles, etc.) and that works in conjunction with IdentityServer4.
Would love some insight on why the Web Api project is needed and whether I can just completely get rid of it, as I was under the impression ServiceStack was a replacement for WCF/Web Api?
ServiceStack's mvcidentityserver project template that's used in the documentation of ServiceStack's integration with IdentityServer4 was an enhanced version of Identity Server's "OpenID Connect Hybrid Flow Authentication and API Access Tokens" example project that used to be maintained at https://github.com/IdentityServer/IdentityServer4.Samples/
The project template contains Auth integration examples with ServiceStack, MVC & Web API. The Web API examples were inherited from the existing IdentityServer's example project, which is optional and can be completely removed.
I have a test project based on the .Net 5 ServiceStack mvcidentity sample. For web-based access, the authentication works as expected.
Accessing the API directly from another app for the hello sample works as no authentication is required. However, if I try to connect to one of the API Methods that requires Authentication, I receive an error message that no auth providers are defined.
Based on this sample, what is the correct way to access one of the authentication required methods from an application on another computer, where there would not be a user to login? I presume we would need to add a basic authentication or something similar in the authentication pipeline?
If you're using the mvcidenity project template you're using ASP .NET Core Identity for authentication (as opposed to ServiceStack Auth) which you'll need to use for any authorization, e.g. you can use a IAuthorizationFilter to implement HTTP Basic Auth.
I have a WebApi 2 API whose URL I want to keep private/internal. I also have an ASP.NET MVC 5 project which will use this API using JavaScript. What I would like to do is create a single controller action for every API request made by AJAX. The AJAX request should be made to this controller action, the action should decide which API endpoint it should call, make the request and return the result. I want to accomplish this with a single action since I don't want to have duplicates of the endpoints in the API in the MVC project. Very similar to what System.ServiceModel.Routing.RoutingService does for WCF. How can I accomplish this?
If it was WCF Project,I usually see all avalible service methods by typing url
....some.svc/help
But in WEB API 2 how I get all such possible methods.
My ASP.NET MVC application is using Forms authentication with [System.Web.Mvc.Authorize] . I would like to use [System.Web.Http.Authorize] attribute to protect my Web API controller and because i'm calling it with HttpClient from my MVC controller I've have implemented a custom delegating handler like the one in the following post:
ASP.NET MVC 4 Web API Authentication with Membership Provider
When debugging i can see that the principal is set and the user has right roles but still I'm being redirected to the login page?
So basically when i log in and visit the WebAPI action with browser everything works (as would if i use AJAX from my views), but when i use HttpClient inside my controller (which i know is a new request with different context) with Basic authentication and set the principal i always get redirected.
I've tried so many solutions/workarounds and i'm always redirected to login page.
Anyone has an idea.
Here's an explanation:
System-web-http-authorize x System-web-mvc-authorize
Another interesting point is you use your custom authorization. I did it and it worked. Following example:
Customized authorization Mvc 4
Good Luck