Tag: asp.net mvc 5

DependencyResolver.SetResolver不工作

我正在尝试使用Dependency.SetResolver方法在新应用程序上设置容器,并使用autofac与autofac mvc 5集成。 问题是设置解析器似乎没有做任何事情。 将始终使用默认解析程序,并始终需要默认构造函数。 有任何想法吗? 编辑 – global.asax.cs ,我把它简化为: var b = new ContainerBuilder(); b.RegisterType().As().InstancePerHttpRequest(); var container = b.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); HomeController在其构造函数中使用IUserSession 。 抛出的exception是“ No parameterless constructor defined for this object.” Thrown from “System.Web.Mvc.DefaultControllerActivator.Create” No parameterless constructor defined for this object.” Thrown from “System.Web.Mvc.DefaultControllerActivator.Create”

删除发送到Json MVC的对象的null属性

namespace Booking.Areas.Golfy.Models { public class Time { public string time { get; set; } public int holes { get; set; } public int slots_available { get; set; } public decimal? price { get; set; } public int? Nextcourseid { get; set; } public bool ShouldSerializeNextcourseid { get { return this.Nextcourseid != null; } } public […]

使用结构图dependency injection时,“没有注册IUserTokenProvider”

我有一个MVC 5项目,该项目已被修改为使用int作为身份的主键,如本指南所示 然后我按照本指南中的说明启用了电子邮件确认 一切都按预期工作正常。 然后我安装了structuremap.mvc5用于dependency injection,并添加了修改后的DefaultRegistry.cs public DefaultRegistry() { Scan( scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.AssemblyContainingType(typeof(MyProject.Data.MyDbContext)); scan.With(new ControllerConvention()); }); //For().Use(); For<IUserStore>().Use().LifecycleIs(); For().Use(() => HttpContext.Current.GetOwinContext().Authentication); } 该项目构建正常但在尝试在站点上注册新用户时,发送电子邮件确认现在抛出exceptionSystem.NotSupportedException:在调用UserManager.GenerateEmailConfirmationTokenAsync(userID)时没有注册IUserTokenProvider。 private async Task SendEmailConfirmationTokenAsync(int userID, string subject) { string code = await UserManager.GenerateEmailConfirmationTokenAsync(userID); var callbackUrl = Url.Action(“ConfirmEmail”, “Account”, new { userId = userID, code = code }, protocol: Request.Url.Scheme); […]

如何在ASP.NET MVC 5项目中获得“添加控制器”和“添加视图”菜单选项?

我使用本教程将我的解决方案从MVC 4升级到Visual Studio 2012中的MVC 5 。 在最后一步中,我从.csproj文件中删除了MVC 4的ProjectTypeGuid。 现在的问题是,当我想创建新的控制器/视图时,我没有看到添加控制器 ,在Visual Studio中添加视图 。 我读了MVC 4的这个答案所以我知道我需要为MVC 5获得正确的ProjectTypeGuid才能重新获得该function。 我想知道是否有人知道那是什么,以便我可以将它们添加到我的.csproj文件中?

ASP.Net MVC 5图像上传到文件夹

我有一个非常简单的MVC5应用程序,它有一个客户端的产品页面,我也在使用MVC 5中已经搭建的基本CRUD操作。 我有一个名为Cakes.cs的模型,因为客户销售蛋糕。 很简单。 以下是该模型的代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace TastyCakes.Models { public class Cakes { public int CakesID { get; set; } public string Name { get; set; } public string Description { get; set; } public decimal Price { get; set; } public string CakeImage { get { return […]

通过VS 2015 RC进行非Azure部署

我正在尝试在VS 2015 Enterprise RC上使用ASP.NET 5及其所有新function。 为了确保顺利的端到端部署,我尝试通过VS Publishfunction将应用程序部署到非Azure私有服务器。 但是,我错过了一个非常重要的function:发布到非Azure服务器的能力。 在早期版本的Visual Studio中(我使用的是VS 2013),自定义选项就在那里。 我尝试过修改项目属性,但没有尝试如何将我的ASP.NET 5应用程序部署到自定义服务器。 有任何想法吗?

身份2.1 – 未找到UserId但之前正在使用

此代码在很多次之前有效,但在为Identity 2.1中的用户添加了几个新属性后,它已经停止工作。 我收到UserId未找到错误,尽管在UserId的调试器中可以看到值。 任何人都知道为什么会突然发生这种情况? 至少看到它是非常令人沮丧的。 这是代码:(控制器) // POST: /Account/Register [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Register(RegisterViewModel model) { model.BackgroundOnFile = false; if (ModelState.IsValid) { var userDetails = new ApplicationUser { UserName = model.Email, Title = model.Title, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, LEAID = model.LEAID, SchoolID = model.SchoolID, Address1 = model.Address1, Address2 […]

有没有办法让每个类运行一次SetUpFixture而不是每个名称空间运行一次?

脚本 首先,我是新手测试 – 所以请耐心等待。 在我的测试项目中 ,有一个Controllers文件夹。 Controllers文件夹可能包含ControllerATest.cs,ControllerBTest.cs和ControllerCTest.cs。 因为我的命名空间与我的文件夹结构一致,所以它们共享命名空间MyProject.Tests.Controllers。 根据我在NUnit SetUpFixture文档中读到的内容,此命名空间内的[SetUpFixture]将为整个命名空间运行一次。 也就是说,如果我一次运行所有控制器测试 – SetUpFixture将只执行一次。 问题 正如我所说,每个控制器测试共享一个命名空间。 SetUpFixtures适用于整个命名空间。 如果我希望每个控制器都有自己的 SetUpFixture怎么办? 当SetUpFixtures应用于整个名称空间时,这是一个问题。 我想要的是执行一次的东西,而不是每次测试。 我在SetUpFixture的SetUp中做的一件事就是实例化一个控制器。 当然,我可以在SetUpFixture中实例化所有3个控制器,但是当我可能只测试ControllerC时,这看起来很难看。 这真的不干净。 因此,我想要一个仅适用于它出现的类的SetUpFixture,例如ControllerCTests。 根据我的阅读,NUnit似乎无法实现这一特定function。 如果NUnit无法实现,那么我认为这不是常见的情况。 如果这不是一个常见的情况,我做错了。 我的问题是,什么? 也许我的测试结构已关闭,需要更改。 或者NUnit可能有可能吗? 码 我想要的结构的一个例子: namespace MyProject.Tests.Controllers { public class ControllerATests { private static IMyProjectRepository _fakeRepository; private static ControllerA _controllerA; [SetUpFixture] public class before_tests_run { [SetUp] public void […]

在AppPool循环后重新连接时,MVC5挂起在MapSignalR上

我在Startup.SignalR.cs中有以下代码: using Microsoft.AspNet.SignalR; using Owin; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Admin { public partial class Startup { public void ConfigureSignalR(IAppBuilder app) { var Config = new HubConfiguration() { EnableDetailedErrors = false, Resolver = new DefaultDependencyResolver() }; #if DEBUG Config.EnableDetailedErrors = true; #endif // Any connection or hub wire up […]

Web API中的MVC-6与MVC-5 BearerAuthentication

我有一个Web API项目,使用UseJwtBearerAuthentication到我的身份服务器。 启动时的配置方法如下所示: public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseJwtBearerAuthentication(options => { options.AutomaticAuthentication = true; options.Authority = “http://localhost:54540/”; options.Audience = “http://localhost:54540/”; }); // Configure the HTTP request pipeline. app.UseStaticFiles(); // Add MVC to the request pipeline. app.UseMvc(); } 这是有效的,我想在MVC5项目中做同样的事情。 我试着这样做: Web api: public class SecuredController : ApiController { [HttpGet] [Authorize] public IEnumerable<Tuple> Get() { […]