asp.net-web-api2

Implementing role based authorization in MVC and Web API with custom table

纵饮孤独 提交于 2021-02-20 04:21:05
问题 I have inherited an application with database. The database has following tables related to authentication and authorization. User Table UserName Password UserTypeId UserType Table UserTypeId UserTypeDesc The User Type table stores the roles for the user e.g. Admin, Editor, etc. If I want to implement authorization like below [Authorize(Roles="Admin, Editor")] public IHttpActionResult GetOrders() { //Code here } Where and what should I code so that the roles are available to the authorize

Using ninject with Ninject.Web.Api for Web Api 2 is not working in ASP.NET MVC 5

℡╲_俬逩灬. 提交于 2021-02-18 07:06:20
问题 I am developing an Asp.NET MVC project. My project has web api as well. I am using ASP.NET MVC5 and Web Api 2 with Visual Studio 3. I am doing dependency injection using ninject. I know ninject for web is not working for Web Api 2. So I tried to use Ninject for Web Api. I installed ninject for web api 2 package using nuget package manager Then I installed Ninject.Web using nuget package manager Then in NinjectWebCommon, I added this line in RegisterServices private static void

ExceptionMessage: "Can't bind multiple parameters ('tenant' and 'certificateFile') to the request's content

孤街浪徒 提交于 2021-02-17 05:14:03
问题 I am trying to call a webapi from react and I get this error responseJson = {Message: "An error has occurred.", ExceptionMessage: "Can't bind multiple parameters ('tenant' and 'certificateFile') to the request's content.", ExceptionType: "System.InvalidOperationException", StackTrace: " at System.Web.Http.Controllers.HttpActionBindin…tpControllerDispatcher.d__1.MoveNext()"} my react code is like this: import React, { Component } from 'react'; import { Row, Col } from 'antd'; import PageHeader

ExceptionMessage: "Can't bind multiple parameters ('tenant' and 'certificateFile') to the request's content

你说的曾经没有我的故事 提交于 2021-02-17 05:11:12
问题 I am trying to call a webapi from react and I get this error responseJson = {Message: "An error has occurred.", ExceptionMessage: "Can't bind multiple parameters ('tenant' and 'certificateFile') to the request's content.", ExceptionType: "System.InvalidOperationException", StackTrace: " at System.Web.Http.Controllers.HttpActionBindin…tpControllerDispatcher.d__1.MoveNext()"} my react code is like this: import React, { Component } from 'react'; import { Row, Col } from 'antd'; import PageHeader

How to solve MVC 5 Update and Delete Error

前提是你 提交于 2021-02-11 14:16:01
问题 I have built MVC 5 Web application in .net 4.7.2. It runs fine in my local machine. Update and Delete commands were failing, which I have now sorted out thanks to this post: DELETE/PUT verbs result in 404 Not Found in WebAPI, only when running locally, I added this line to the web.config and all the CRUD now works: <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0 However,

SignalR 2, Autofac, OWIN WebAPI will not pass message from server to hub

天大地大妈咪最大 提交于 2021-02-11 13:10:12
问题 I have tried several variations over the past several weeks and so far all I can do is pass a message from the UI to the server and back. I am unable to pass a message from my controller or other method outside the hub to the UI. It seems like I am not getting an instance of the HubContext. I've created a basic demo app from scratch and uploaded here: https://github.com/cdecinkoKnight/SignalRDemo-help I have a basic hub (MessageHub): [HubName("messages")] public class MessageHub : Hub,

SignalR 2, Autofac, OWIN WebAPI will not pass message from server to hub

牧云@^-^@ 提交于 2021-02-11 13:10:05
问题 I have tried several variations over the past several weeks and so far all I can do is pass a message from the UI to the server and back. I am unable to pass a message from my controller or other method outside the hub to the UI. It seems like I am not getting an instance of the HubContext. I've created a basic demo app from scratch and uploaded here: https://github.com/cdecinkoKnight/SignalRDemo-help I have a basic hub (MessageHub): [HubName("messages")] public class MessageHub : Hub,

Web API 2 DataMember naming not working in FromUri parameters

随声附和 提交于 2021-02-11 08:55:07
问题 I'm having issues with DataMember-naming in UriParameters. [DataContract] public class testobj { [DataMember(Name = "Test")] public string a {get; set; } [DataMember(Name = "Test1")] public string b {get; set; } } Then i have my controller: public IHttpActionResult test([FromUri] testobj testparams) { return testparams; } In the response i get Test and Test1 , that's correct. However i have to use a and b in the uriParameters, why can't i use Test and Test1 there? How can i fix this? 回答1: You

Google reCaptcha in Web API 2 c#

混江龙づ霸主 提交于 2021-02-07 20:22:12
问题 I have an ASP.NET Web API 2 Project. I am trying to read Google Captcha from the form. I tried this Code: public string Post(FoundingRequest model) { var response = Request["g-recaptcha-response"]; string secretKey = "my key"; var client = new WebClient(); var result = client.DownloadString( $"https://www.google.com/recaptcha/api/siteverify?secret={secretKey}&response={response}"); var obj = JObject.Parse(result); model.Captcha = (bool)obj.SelectToken("success"); .... } but I am receiving an

Shorten access token returned by OWIN in ASP.NET WebAPI 2

此生再无相见时 提交于 2021-02-07 09:30:02
问题 We've developed a REST API using ASP.NET WebAPI 2 & secured it using ASP.NET Identity. The client required that their token be set to a long expiration time, as they store the access token in their database. During testing, they requested that we reduce the length of the token, as their database can only handle strings up to 250 characters. Our implementation is pretty "vanilla". Below are the options we're currently setting for the bearer token: OAuthOptions = new