小编Kom*_*gem的帖子

MVC 4 Web Api控制器没有默认构造函数?

这是跟踪:

<Error>
   <Message>An error has occurred.</Message>

   <ExceptionMessage>
      Type 'ProjectName.Web.Api.Controllers.ContinentsController' does not have a default constructor
   </ExceptionMessage>

   <ExceptionType>System.ArgumentException</ExceptionType>

   <StackTrace>
      at System.Linq.Expressions.Expression.New(Type type)

      at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)

      at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)

      at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
   </StackTrace>
</Error>
Run Code Online (Sandbox Code Playgroud)

我觉得这很奇怪,public class UsersController : ApiController { ... }工作得很好.我比较了2个控制器,所有设置和结构都相似.

我正在使用Ninject我的系统设置类似于Jamie Kurtz Asp.Net Mvc 4和Web Api:从开始到完成构建REST服务.

从堆栈跟踪,是否有人能够发现问题以及如何解决它?谢谢!

按照要求.

ContinentsController

[LoggingNHibernateSession]
public class ContinentsController : ApiController
{
    private readonly ISession _session;
    private readonly IContinentMapper _continentMapper;
    private readonly …
Run Code Online (Sandbox Code Playgroud)

c# ninject inversion-of-control asp.net-mvc-4 asp.net-web-api

17
推荐指数
3
解决办法
4万
查看次数

如何在EF Code First中更改主键的名称?

我有一个场景,我想更改实体中的主键名称,并能够运行update-database -force.当我尝试时,请参阅下面的代码和错误.

实体是:

public class Team
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    public virtual int Id { get; set; }

    [Display(Name = "Full Name:")]
    public virtual string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

实体更改为:

public class Team
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    public virtual int TeamId { get; set; }

    [Display(Name = "Full Name:")]
    public virtual string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我运行时,Update-database -Force我得到以下错误.

Multiple identity columns specified for table 'Teams'. Only one identity column per table is …

c# ef-migrations entity-framework-5

12
推荐指数
1
解决办法
1万
查看次数

是什么原因INSERT语句与FOREIGN KEY约束冲突?

这段代码以前对我有用,但我不确定是什么导致了这个错误.我唯一的猜测是,当我尝试创建一个播放器时,团队数据将被发送回Team表并尝试复制,但由于TeamId是唯一的,因此出现此错误.

错误

INSERT语句与FOREIGN KEY约束"FK_dbo.Players_dbo.Teams_TeamId"冲突.冲突发生在数据库"Web",表"dbo.Teams",列'TeamId'中.该语句已终止.

播放机

public class Player
{
    ...
    ...

    [HiddenInput(DisplayValue = false)]
    [ForeignKey("Team")]
    public int TeamId { get; set; }        

    public virtual Team Team { get; set; }

    ...
}
Run Code Online (Sandbox Code Playgroud)

球队

public class Team
{
    [Key]
    [HiddenInput(DisplayValue = false)]
    public int TeamId { get; set; }

    ....

    public virtual ICollection<Player> Players { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

调节器

//
    // GET: /Player/
    [HttpGet]
    public ActionResult Create()
    {
        PopulateTeamsDropDownList();
        return View();
    }

    //
    // POST: /Player/
    [HttpPost]
    public ActionResult Create(Player …
Run Code Online (Sandbox Code Playgroud)

c# ef-code-first entity-framework-ctp5 asp.net-mvc-4 visual-studio-2012

11
推荐指数
2
解决办法
2万
查看次数

使用Razor引擎在MVC 5和Select2多值中进行数据绑定

通常我在应用程序的html方面做的很少,因为在大多数情况下我只是让它为我生成.

我正在开发一个带有帖子标签和评论的博客的应用程序.我想要做的是在创建新帖子时,我应该能够将现有标签添加到新帖子中.我正在尝试使用Select2,但我无法弄清楚如何将所选值传递给post控制器中的Create方法,以便它们可以存储在数据库中.

这是我正在使用的:

namespace Blog.Data.Entities
{
    public class Post
    {
        public virtual long PostId { get; set; }

        -------------------

        public virtual ICollection<Tag> Tags { get; set; }
    }

    public class Tag
    {
        public virtual long TagId { get; set; }
        public virtual string Name { get; set; }
        public virtual string Description { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

后控制器

// POST: /Post/Create
    [HttpPost]
    public ActionResult Create(PostsCreateViewModel postModel)
    {
        if (ModelState.IsValid)
        {
            Post post = new Post
            {
                Title = postModel.Title, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc html5 razor jquery-select2

10
推荐指数
2
解决办法
1万
查看次数

libgit2引发了一个错误.Category = Os(错误)

我现在已经碰到过几次了:

 An error was raised by libgit2. Category = Os (Error). 
Run Code Online (Sandbox Code Playgroud)

在编写代码时,有时会导致此错误或类似错误:

Failed to open '.../App_Data/....mdf': 
The process cannot access the file because it is being used by another process.
Run Code Online (Sandbox Code Playgroud)

当发生这种情况时,如果不重新启动我就无法编码Visaul Studio 2012.

我认为这是由于Source Control - Git我在安装Visual Studio和Team Foundation的Git扩展之前不记得遇到此问题.

有没有其他人遇到这个,他们是如何解决的?

git version-control libgit2 visual-studio-2012 azure-devops

7
推荐指数
1
解决办法
7402
查看次数

git push时团队基础服务致命

我已添加Source Control (git)到我的项目中.我也创建了一个项目Team Foundation Service with git.该项目Team Foundation Service与我的相关Visual Studio.我有Enabled alternate credentials.参考文献Ref1Ref 2

当我跑;

git remote add origin https://yourname.visualstudio.com/DefaultCollection/_git/ProjectName
Run Code Online (Sandbox Code Playgroud)

然后:

git push origin master
Run Code Online (Sandbox Code Playgroud)

我明白了:

" https://yourname.visualstudio.com "的用户名:`

输入用户名后:

Password for 'https://username@hotmail.com@yourname.visualstudio.com':
Run Code Online (Sandbox Code Playgroud)

输入密码后:

致命: 找不到https://yourname.visualstudio.com/DefaultCollection/ProjectName/info/refs:您是否在服务器上运行了git update-server-info?

我似乎无法找到解决方案,我怎么能成功呢?

git visual-studio-2012 azure-devops

5
推荐指数
1
解决办法
1515
查看次数

Fluent NHibernate 中的 schemaExport 是什么?

我很想了解更多有关此代码的方式以及执行时的预期结果的信息。

        /// <summary>
        /// Sets up NHibernate, and adds an ISessionFactory to the given
        /// container.
        /// </summary>
        private void ConfigureNHibernate(IKernel container)
        {
            // Build the NHibernate ISessionFactory object
            var sessionFactory = FluentNHibernate
                .Cfg.Fluently.Configure()
                .Database(
                    MsSqlConfiguration.MsSql2008.ConnectionString(
                        c => c.FromConnectionStringWithKey("ServicesDb")))
                .CurrentSessionContext("web")
                .Mappings(m => m.FluentMappings.AddFromAssemblyOf<SqlCommandFactory>())
                //.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(true, true))
                .ExposeConfiguration(cfg =>
                                         {
                                             var schemaExport = new SchemaExport(cfg);
                                             schemaExport.Drop(true, true);
                                             schemaExport.Create(true, true);
                                         })
                .BuildSessionFactory();

            // Add the ISessionFactory instance to the container
            container.Bind<ISessionFactory>().ToConstant(sessionFactory);

            // Configure a resolver method to be used for …
Run Code Online (Sandbox Code Playgroud)

c# sql-server nhibernate fluent-nhibernate

5
推荐指数
1
解决办法
8130
查看次数

如何远程验证电子邮件或检查电子邮件是否存在

我正在尝试检查注册时是否存在电子邮件,以便数据库中没有重复的电子邮件.我使用MVC4默认Internet应用程序执行此操作,但我已向RegisterviewModel添加了电子邮件字段.我也注意到,使用UserName字段做得很好,但我不知道他们是如何做到的.我尝试按照下面的博客但没有运气,因为当我点击创建时没有回应.Tug Berk.当我使用Firebug我收到Status: 302 Found的时候Json action excutes

这就是我所拥有的:

用户资料

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Email { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

RegisterViewModel

public class RegisterModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email")]
    [Remote("DoesUserEmailExist", "Account", HttpMethod = "POST", ErrorMessage = "Email address already exists. Please enter a different Email …
Run Code Online (Sandbox Code Playgroud)

c# email-validation remote-validation asp.net-mvc-4 asp.net-4.5

4
推荐指数
1
解决办法
8707
查看次数

如何在MVC4中使确认链接激活帐户?

我正在构建一个MVC 4应用程序,从默认的Internet应用程序开始.我的目标是在用户注册到网站时向用户发送确认电子邮件,我已设法发送确认电子邮件,但是当我点击它时,帐户未被确认.

注意:我知道注册操作很拥挤,当我使其工作时,我会将各个文件分开.

*这就是我所做的:*

注册行动

[HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            try //CreateUserAndAccount
            {
                var token = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
                if (token != null)
                {
                    var hosturl =
                        System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) +
                        "/Account/ConfirmAccount?token=" + token;

                    var confirmationLink = string.Format("<a href=\"{0}\">Clink to confirm your registration</a>",
                                                         hosturl);




                    var message = new MailMessage("komengem@gmail.com", model.UserName)
                    {
                        Subject = "Please confirm your email",
                        Body = confirmationLink
                    };

                    var client = new SmtpClient();
                    client.EnableSsl = true;
                    client.Send(message);
                }

                TempData["message"] = …
Run Code Online (Sandbox Code Playgroud)

c# security email-confirmation ef-code-first asp.net-mvc-4

4
推荐指数
1
解决办法
1万
查看次数

程序集中不存在System.Web.Security

要么我迟到了党,要么我做错了什么.我正在使用Visual Studio 2013,我试图使用Membership类,但是using System.Web.Security;我的程序集中不存在名称空间.

我该怎么做才能解决这个问题?

注意:System.Web存在

目标:.NET Framework 4.5.1

security membership-provider visual-studio-2013

4
推荐指数
2
解决办法
6667
查看次数