asp.net-web-api

.NET MVC 4 WebAPI POST not working

你离开我真会死。 提交于 2020-01-01 09:24:08
问题 Core problem: GET works, POST doesn't. I'm new to WebAPI so I'm probably doing something stupid, but I've poked around quite a bit on the 'net trying to figure out why this isn't working. Fairly simple WebAPI C# app. I've tried to get this down to very simple routes: config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // Add a route where action is supplied, i.e. api/csv/LoadToSQL config.Routes.MapHttpRoute(

Implementing Authentication and role based authorization in ASP.NET MVC web API service and MVC client architecture

北战南征 提交于 2020-01-01 09:12:05
问题 I'm having hard time in deciding an approach while implementing Authentication/Authorization scenario for my Web API (Service) - MVC (client) architecture project. Even though i have implemented Custom token based authentication in Web API project, I'm finding it hard where exactly i should implement the authorization (In Client or in API itself). Architecture Overview : Projects Solution - | | __ ASP.NET Web API based REST service (Independently hosted on IIS at M/C 1) | | __ ASP.NET MVC

Can my ASP.Net Code get confirmation from sendgrid that an email has been sent?

女生的网名这么多〃 提交于 2020-01-01 08:53:43
问题 I have this code that I am using in my application: private async Task configSendGridasync(IdentityMessage message) { var myMessage = new SendGridMessage(); myMessage.AddTo(message.Destination); myMessage.From = new System.Net.Mail.MailAddress( "a@b.com", "AB Registration"); myMessage.Subject = message.Subject; myMessage.Text = message.Body; myMessage.Html = message.Body; var credentials = new NetworkCredential( ConfigurationManager.AppSettings["mailAccount"], ConfigurationManager.AppSettings

Can my ASP.Net Code get confirmation from sendgrid that an email has been sent?

徘徊边缘 提交于 2020-01-01 08:53:01
问题 I have this code that I am using in my application: private async Task configSendGridasync(IdentityMessage message) { var myMessage = new SendGridMessage(); myMessage.AddTo(message.Destination); myMessage.From = new System.Net.Mail.MailAddress( "a@b.com", "AB Registration"); myMessage.Subject = message.Subject; myMessage.Text = message.Body; myMessage.Html = message.Body; var credentials = new NetworkCredential( ConfigurationManager.AppSettings["mailAccount"], ConfigurationManager.AppSettings

Web API ModelBinding From URI

谁说胖子不能爱 提交于 2020-01-01 08:42:38
问题 So I have a custom Model Binder implemented for DateTime type and I register it like below: void Application_Start(object sender, EventArgs e) { // Code that runs on application startup GlobalConfiguration.Configuration.BindParameter(typeof(DateTime), new CurrentCultureDateTimeAPI()); } and then I have setup 2 sample actions to see if my custom model binding takes place: [HttpGet] public void BindDateTime([FromUri]DateTime datetime) { //http://localhost:26171/web/api/BindDateTime?datetime=09

Using DTO's with OData & Web API

你。 提交于 2020-01-01 08:41:06
问题 Using Web API and OData, I have a service which exposes Data Transfer Objects instead of the Entity Framework entities. I use AutoMapper to transform the EF Entities into their DTO counter parts using ProjectTo() : public class SalesOrdersController : ODataController { private DbContext _DbContext; public SalesOrdersController(DbContext context) { _DbContext = context; } [EnableQuery] public IQueryable<SalesOrderDto> Get(ODataQueryOptions<SalesOrderDto> queryOptions) { return _DbContext

Instantiate new System.Web.Http.OData.Query.ODataQueryOptions in nunit test of ASP.NET Web API controller

风流意气都作罢 提交于 2020-01-01 08:14:34
问题 I have an ASP.NET MVC4 Web API project with an ApiController-inheriting controller that accepts an ODataQueryOptions parameter as one of its inputs. I am using NUnit and Moq to test the project, which allow me to setup canned responses from the relevant repository methods used by the ApiController. This works, as in: [TestFixture] public class ProjectControllerTests { [Test] public async Task GetById() { var repo = new Mock<IManagementQuery>(); repo.Setup(a => a.GetProjectById(2)).Returns

ASP.Net Web API model binding not working like it does in MVC 3

£可爱£侵袭症+ 提交于 2020-01-01 07:30:22
问题 I was under the impression that model binding in the ASP.Net Web API was supposed to support binding with the same minimum level of functionality supported by MVC. Take the following controller: public class WordsController : ApiController { private string[] _words = new [] { "apple", "ball", "cat", "dog" }; public IEnumerable<string> Get(SearchModel searchSearchModel) { return _words .Where(w => w.Contains(searchSearchModel.Search)) .Take(searchSearchModel.Max); } } public class SearchModel

Unity Container - Dependency Injection of Dynamic DbContext into Service

帅比萌擦擦* 提交于 2020-01-01 07:12:32
问题 I'm building a .Net Web API which uses a Service+Repository pattern w/ Entity Framework. Each controller's CRUD actions relay data retrieved by calls to a Service. I have a SomeContext that extends DbContext: public class SomeContext : DbContext { public SomeContext(string connString) : base(connString) { } // DbSets ... } The Service is initialized w/ a constructor that accepts an ISomeContext: public class Service : IService { public Service(ISomeContext ctx) : base(ctx) { _alpha = new

How do you prevent replay attacks with Thinktecture IdentityModel token?

China☆狼群 提交于 2020-01-01 07:11:53
问题 I have two sites on separate domains. I'm implementing SSO using the Thinktecture IdentityModel. A user logs into Site A. At some point they click a link to take them to site B. Site A redirects the user to site B/Login.aspx?token=< token > with a JWT token. Site B then validates the token by calling an API on Site A to authenticate the user. If authenticated, the user is automatically logged into site B. By default Thinktecture tokens last for 10 hours, with no way to kill a token(as far as