asp.net-web-api

Custom Verification Code/Token in Asp .Net Identity

∥☆過路亽.° 提交于 2020-01-07 02:44:11
问题 I need to create short code (6 digits) for Email Confirmation using Asp.Net Identity. Currently, if I use "GenerateEmailConfirmationTokenAsync" it provides me with very long code instead of this I want to generate a code which is only 6 digit in length. Is there any way to achieve this how can I extend identity to provide such a feature. any leads towards this will be helpful. Thanks 回答1: Yes you can. Check this SO answer for details. Basically you have to create a class inheriting

C# .net 4.0 Upload a file to .asp Web API

☆樱花仙子☆ 提交于 2020-01-07 02:01:27
问题 My .net 4.0 class library send HttpRequestMessage and receive HttpResponseMessage from .asp Web API (REST). When I sent a small class, I use JSON to parse it as string, then I send string by: request = new HttpRequestMessage(); request.RequestUri = new Uri(myRestAPI); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Method = method; if (method != HttpMethod.Get) request.Content = new StringContent(content, Encoding.UTF8, mthv); Next, use HttpClient

Formatting DateTime to string with timezone information for Date created in Javascript

℡╲_俬逩灬. 提交于 2020-01-06 21:08:30
问题 In this massively oversimplified example, I have a controller method that accepts a DateTime [Route("api/demo)] public IHttpActionResult Post(DateTime date) { // format dateTime here } We call this from the client with Javascript. var data = { date: new Date() }; $.ajax({ url: "/api/demo", type: 'POST', contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify(data), }); The new Date() part is what I feel is the important part, as we're trying to record the date

How to send XML in a URI for posting to a Web API app?

时间秒杀一切 提交于 2020-01-06 18:13:02
问题 I need to send a uri to a Controller method in my my Web API app which has the following signature: public HttpResponseMessage PostXMLFile(string serialNum, string siteNum, XElement xElement) Or should it be this instead: public HttpResponseMessage PostXMLFile(string serialNum, string siteNum, List<XElement> xElements) ? Anyway, as you can see, it can't be just the XML, but must have the serialNum and siteNum args, too. I'm assuming the uri can look like this: http://<machineName>:<port>/api/

acessing username in web api controller when database table stores user as integer

跟風遠走 提交于 2020-01-06 18:02:34
问题 Inside some web api controllers, I would like to access the User as indicated in this answer: https://stackoverflow.com/a/12705062/538962 sample code from answer... [Authorize] public List<Product> GetProductsFromId() { string username = User.Identity.Name; return _productService.GetProductsFromUsername(username); } The asp_net membership tables in my scenario are on a different database server than then the database server the application runs on. The database for the application has its own

Visual studio debug access to external database

夙愿已清 提交于 2020-01-06 16:29:30
问题 I have a question as to how the Visual Studio 2013 debug emulator for Web API works. I had built a Web API project in Visual Studio 2013 to access a database on an external server. The code was built using VS2013's ASP.NET Web Application project template for a Web API application. Once built, running debug opened a browser window for localhost port 56618, which allowed access from Fiddler to test Http requests. Once I had the project finished, I published it to a website using Web Deploy to

How can I add a Dependency that can be used as type parameter 'TImpl' for Castle Windsor?

僤鯓⒐⒋嵵緔 提交于 2020-01-06 15:32:51
问题 I was getting this runtime exception with a particular URL: " Missing dependency. Component NRBQ.Web.Controllers.DeliveryController has a dependency on SeaStore.Data.Legacy.Interfaces.INRBQDeliveryRepository, which could not be resolved. Make sure the dependency is correctly registered in the container as a service, or provided as inline argument." ExceptionType: "Castle.MicroKernel.Resolvers.DependencyResolverException " ...so I added this code (based on existing code that works) to the IOC

No connection string could be found in the application config file (But it Does Exist)

半世苍凉 提交于 2020-01-06 15:04:21
问题 I have a web API project I published to IIS and it complains there is no connection string with a specific name in my config file. I verified there is an entry in my web.config file of the web API project so it must not be picking it up. I was able to run this same web.config file locally using Visual Studio 2013. I am well aware the referenced start up project must have the connection string and that is the case for me. I verified my web API project has the connection string below (same one

Acheive Default model Binding working with custom model binder in WebPI and asp.net mVC 4

↘锁芯ラ 提交于 2020-01-06 14:54:33
问题 I created a custom Model binder working fine with all the properties. But the issue is I am missing the default modelbinding. I am using DataAnotations for my objects and I want to apply my custom model binder for Enums only. How can I achieve the custom Model binder along with default model binding. In the custom Model Binder, I have the code as following. public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext) { var json =

Loading library dynamically

可紊 提交于 2020-01-06 14:37:20
问题 I have the following project structure: Web API Class Library A Class Library B Class Library C These are the references between the projects Web API directly references A and B B directly references C C has a method which needs to ensure that A is loaded to use, by reflection, a type defined in it. My code actually is like the following public class C { public void MethodCallingBType( string fullClassName ) { //e.g. "MyNamespace.MyType, MyNamespace" string[] parts = fullClassName.Split( ','