asp.net-mvc-5

How to configure Ninject so that it creates a single instance per Controller

走远了吗. 提交于 2019-12-29 01:44:09
问题 I'm trying to use Ninject for an MVC5 application and I want to know if there's any way I can configure it so that instantiate a single object per Controller (I'm not sure if it the same as per request), use that instance in any Action of the controller and once the Action has finished release all the resources that the object utilized. The class that I want Ninject to inject in my controllers implements the IDisposable interface. So far I have tried this: private static void RegisterServices

How to obtain a list of Users from ASP.NET Identity?

南楼画角 提交于 2019-12-28 08:07:21
问题 Edit: This question is outdated The Identity Framework was a moving target at the moment I asked this. The authors changed quite a few things and they have decoupled several others, making everything easier. Have a look at the Asp.NET Identity Sample project on github. I'm creating a small application that requires user management. Registration is not allowed, instead there is a super user that will create and modify login information. I'm using the new ASP.NET Identity membership system, and

Dependency Injection in HtmlHelper extension method?

人盡茶涼 提交于 2019-12-28 06:28:10
问题 I want to implement property renderers as handlers. I am using Autofac as a DI container in the app. How can I get objects implementing IPropertyHandler in HtmlHelper extension without using globally accessible container (service location)? Is it a way to register own HtmlHelper in Autofac? Maybe MVC framework provide another way? public static class HtmlHelperExtensions { public static MvcHtmlString Editor(this HtmlHelper html, object model) { return new Renderer(new List<IPropertyHandler>()

ASP.NET identity use email instead of user name [duplicate]

感情迁移 提交于 2019-12-28 06:18:19
问题 This question already has answers here : ASP.Net UserName to Email (7 answers) Closed 3 years ago . How can I use email instead of user name in the new ASP.NET identity system? I tried to change the RegisterViewModel class: [Display(Name = "Email address")] [Required(ErrorMessage = "The email address is required")] [EmailAddress(ErrorMessage = "Invalid Email Address")] public string UserName { get; set; } but when I enter an mail adress I am getting the error: User name fsdfsd@fsdfsd.de is

GlobalConfiguration.Configure() not present after Web API 2 and .NET 4.5.1 migration

ε祈祈猫儿з 提交于 2019-12-28 03:23:10
问题 I recently started following this guide to migrate my project to .NET 4.5.1 and Web Api 2. The very first thing MS developer Rick Anderson asks you to do is change: WebApiConfig.Register(GlobalConfiguration.Configuration); to GlobalConfiguration.Configure(WebApiConfig.Register); in the global.asax file. Yet this is giving me an error when I try to build: Error 1 'System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure' My project is currently on MVC 5 and Web Api 2

MVC 5 Owin Facebook Auth results in Null Reference Exception

为君一笑 提交于 2019-12-28 02:51:08
问题 I'm trying to setup integrated OWIN Facebook authentication in a new MVC 5 project in Visual Studio 2013. I have configured apps and keys as per this tutorial: http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on However, I'm getting a NullReferenceException thrown from this call in the AccountController: [AllowAnonymous] public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { var loginInfo = await

ASP.NET MVC 5 error handling

巧了我就是萌 提交于 2019-12-27 17:29:30
问题 We want to handle 403 errors, 404 errors, all errors due to a MySpecialDomainException and provide a default error page for all other errors (including errors in the IIS configuration!). All errors should return proper Razor views, it would be very nice to have an ErrorController in front of the views. E.g. something like this: public class ErrorController : Controller { public ViewResult NotFound () { return View(); } public ViewResult Forbidden () { return View(); } public ViewResult

How to add claims in ASP.NET Identity

本小妞迷上赌 提交于 2019-12-27 11:57:48
问题 I am trying to find a document or example of how you would add custom claims to the user identity in MVC 5 using ASP.NET Identity. The example should show where to insert the claims in the OWIN security pipeline and how to persist them in a cookie using forms authentication. 回答1: Perhaps the following article can help: var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, "Brock")); claims.Add(new Claim(ClaimTypes.Email, "brockallen@gmail.com")); var id = new ClaimsIdentity

Custom Attribute null reference exception

落爺英雄遲暮 提交于 2019-12-25 18:21:19
问题 I have an view model public class fooViewModel { public int Id { get; set; } [Required] public string Name { get; set; } [Required] [CustomAttribute] public float foo1{ get; set; } [Required] [CustomAttribute] public decimal foo2 { get; set; } } I made a custom server side validation attribute. [AttributeUsage(AttributeTargets.Property)] public class CustomAttribute : RequiredAttribute { public CustomAttribute() { ErrorMessage = "Some message"; } public override bool IsValid(object value) {

MVC Website - ServerGotRequest ServerBeginResponse

前提是你 提交于 2019-12-25 18:19:28
问题 Been building a website in MVC 5, Framework 4.6.1. but I'm having a problem with the loading speeds. After running fiddler (never used it), i found the delay is between ServerGotRequest and ServerBeginResponse, and this is running in localhost. Request Count: 1 Bytes Sent: 545 (headers:545; body:0) Bytes Received: 6,263 (headers:428; body:5,835) ACTUAL PERFORMANCE -------------- ClientConnected: 16:24:37.533 ClientBeginRequest: 16:24:37.533 GotRequestHeaders: 16:24:37.533 ClientDoneRequest: