小编998*_*823的帖子

无法为媒体类型'application/x-www-form-urlencoded'生成样本

我最近开始创建一个ASP.net Web API

出于某种原因,在查看自动生成的帮助文档时,我一直收到此错误:

在此输入图像描述

这是一个POST方法

样本显示适用于application/json和application/xml

我不太确定,但应用程序/ -x-www-form-urlencoded一直出现

我已经搜索了相当多的错误,但无法找到可能导致此问题的原因

我非常感谢您提供的任何帮助,如果您有任何疑问,请告诉我.

c# asp.net asp.net-web-api

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

无法检索元数据

MVC4 +实体框架4.4 + MySql + POCO /代码优先

我正在设置上面的配置..这是我的课程:

namespace BTD.DataContext
{
public class BTDContext : DbContext
{

    public BTDContext()
        : base("name=BTDContext")
    {

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        //modelBuilder.Conventions.Remove<System.Data.Entity.Infrastructure.IncludeMetadataConvention>();
    }

    public DbSet<Product> Products { get; set; }

    public DbSet<ProductImage> ProductImages { get; set; }        


}
}

namespace BTD.Data
{
[Table("Product")]
public class Product
{
    [Key]
    public long ProductId { get; set; }

    [DisplayName("Manufacturer")]
    public int? ManufacturerId { get; set; }

    [Required]
    [StringLength(150)]
    public string Name { get; set; …
Run Code Online (Sandbox Code Playgroud)

mysql asp.net asp.net-mvc entity-framework ef-code-first

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

“sgen.exe”无法在 Azure Pipelines 上的 VSBuild 中运行

在本地运行构建很好,没有任何问题。当我在 Azure Pipeline 上运行它时,它出错了。

详细的错误信息是

“SGen”任务的命令行太长。超过 32000 个字符的命令行可能会失败。尝试通过将对“SGen”的调用分解为多个调用来减少命令行的长度,每个调用的参数较少。[D:\a\1\s\eFetch.Web.Core\eFetch.Web.Core.csproj]

##[错误]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3645,5):错误 MSB6003:指定的任务可执行文件“sgen” .exe”无法运行。System.ComponentModel.Win32Exception(0x80004005):文件名或扩展名太长

在此输入图像描述

Azure Pipeline 上的 VSBuild

- task: VSBuild@1
  inputs:
    solution: '$(agent.builddirectory)\s$(Project1-Folder)$(Project1-Name).csproj'
    msbuildArgs: '/p:OutputPath="$(build.binariesDirectory)$(Project1-Folder)\bin" /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl="$(build.artifactStagingDirectory)$(Project1-Name)TempFolder"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
Run Code Online (Sandbox Code Playgroud)

我们做了一些研究。通常出现的是将GenerateSerializationAssemblies设置为AutoOff。我们的项目已经处于“自动”状态,因此我们将其设置为“关闭”,但错误仍然存​​在。

有没有办法绕过某些 dll 引用的长路径?就像下面这样

  • 参考:“C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.7.2 \ System.Xml.Linq.dll”
  • /reference:“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\Facades\System.Xml.ReaderWriter.dll”

另一种情况是多次调用 sgen.exe,但我们不确定如何执行此操作,因为 sgen.exe 是在 VSBuild / msbuild.exe 内部调用的。

理想情况下,我们希望不必关闭GenerateXmlSerialization,而是让它正常工作。

msbuild sgen azure azure-devops azure-pipelines

10
推荐指数
0
解决办法
739
查看次数

如果URL包含Smarty

使用Smarty标签我想确定一个URL是否包含一个单词,例如:

{if $smarty.get.page contains "product.php"} .....
Run Code Online (Sandbox Code Playgroud)

我知道包含不存在,但我怎么能轻易地写一些类似的东西来实现上面的代码呢?

php smarty x-cart

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

MySql连接器6.8.2 RC,实体框架6和代码优先

我最近升级到Entity Framework 6并安装了MySql 6.8.2 RC Connector,因为它声称现在支持EF6 Code First.

请记住,在升级之前,我的项目在连接器6.7.4和EF 5中运行良好.

我对web.config进行了以下更改

<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
Run Code Online (Sandbox Code Playgroud)

<connectionStrings>
<add providerName="MySql.Data.MySqlClient" name="dbcontext" connectionString="Server=localhost; Database=db; Uid=un; Pwd=pw;Convert Zero Datetime=True" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

我还添加了以下引用(.net 4.5版本)

  1. MySql.Data
  2. MySql.Data.Entity.EF6
  3. MySql.Web

问题是 - 代码调用我收到的DBContext的那一刻:

Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)

再次 - 请记住,升级之前一切正常,所以我知道它不是代码问题,但是,我可能没有正确设置web.config?

另外 - 您可能会问,如果在升级之前它运行良好,为什么要升级?好吧,据说EF6和新的MySql连接器解决了我遇到的一些错误 - 所以我希望现在实现它,而它在开发中,当它转移到生产(几个月后)我应该能够加载6.8.x连接器的生产版本.

这是堆栈跟踪,以防它有所帮助

[NullReferenceException: Object reference not set to an instance of an object.]
MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection …
Run Code Online (Sandbox Code Playgroud)

c# mysql entity-framework ef-code-first

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

只有当属性的当前值为null时,才能设置EntityKey属性

我试图以下列方式执行EF更新,但继续收到此错误:

只有当属性的当前值为null时,才能设置EntityKey属性.

        using (hydraEntities db = new hydraEntities())
        {
            YouUser = db.youusers.Include("address").Include("entity").Include("youusercontacts.contact").Include("youuserlogins").Include("youusernotes.note").Include("youusernotes.youuser.entity").Where( yu => yu.YOUUserId.Equals(YOUUserId)).First();
        }

            YouUser.entity.FirstName = txtFirstName.Text;
            YouUser.entity.LastName = txtLastName.Text;
            YouUser.address.AddressLine1 = txtAddressLine1.Text;
            YouUser.address.AddressLine2 = txtAddressLine2.Text;
            YouUser.address.City = txtCity.Text;
            YouUser.address.State = ddlState.SelectedValue;
            YouUser.address.Zipcode = txtZipcode.Text;

            using (hydraEntities db = new hydraEntities())
            {
                db.youusers.AddObject(YouUser);
                db.ObjectStateManager.ChangeObjectState(YouUser, System.Data.EntityState.Modified);
                db.SaveChanges();
            }
Run Code Online (Sandbox Code Playgroud)

非常感谢我如何解决这个问题并执行上述声明.

c# entity-framework-4

6
推荐指数
1
解决办法
8260
查看次数

在C#中创建自定义绑定

我一直在尝试创建一个自定义绑定来输出这种类型的标头XML:

<soapenv:Header>
  <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
     <wsse:UsernameToken wsu:Id="UsernameToken-BEC9D84D8B68A3118D14543420311491">
        <wsse:Username>user</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pass</wsse:Password>
        <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hBcjVXk/NxiSiva5xXKphA==</wsse:Nonce>
        <wsu:Created>2016-02-01T15:53:51.146Z</wsu:Created>
     </wsse:UsernameToken>
  </wsse:Security>
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码:

        var customBinding= new CustomBinding();

        var securityBindingElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
        securityBindingElement.IncludeTimestamp = false;
        customBinding.Elements.Add(securityBindingElement);
        customBinding.Elements.Add(new TextMessageEncodingBindingElement());

        var transportElement = new HttpsTransportBindingElement();

        customBinding.Elements.Add(transportElement);
Run Code Online (Sandbox Code Playgroud)

但是我一直收到一条消息说:

The message could not be processed. This is most likely because the action is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings.

我很确定它与我的自定义绑定有关,但我正在努力弄清楚需要设置什么属性的时候非常困难.感谢任何指导!

c# asp.net wcf

6
推荐指数
1
解决办法
1296
查看次数

Git + Windows + Visual Studio合并由分支之间的行结束问题引起的冲突

我正在努力正确地合并到分支机构.分支似乎有行结束问题,因为当我打开Visual Studio中的冲突窗口时,它显示0个冲突和0个不同文件之间的差异.

我在两个分支上添加了一个gitattributes文件,它在两个存储库中查找并执行了存储库刷新.

当我刷新两个存储库时,没有提交更改,即使指令指出将提交更改(实际上更改来自EOL转换).

这是我的gitattributes

# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs     diff=csharp

# Standard to msysgit
*.doc    diff=astextplain
*.DOC    diff=astextplain
*.docx   diff=astextplain
*.DOCX   diff=astextplain
*.dot    diff=astextplain
*.DOT    diff=astextplain
*.pdf    diff=astextplain
*.PDF    diff=astextplain
*.rtf    diff=astextplain
*.RTF    diff=astextplain
Run Code Online (Sandbox Code Playgroud)

我也检查过,我的全局core.autocrlf等于true(因为我们所有的开发人员都在Windows上使用Visual Studio)

问题是,当我继续做以上操作以期在两个分支中修复和规范化这些分支时,我最终会遇到比以前更多的冲突 - 所有这些都是由于行结束:

在此输入图像描述

.git/config文件(不包括分支引用)

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = …
Run Code Online (Sandbox Code Playgroud)

git github visual-studio git-merge-conflict

6
推荐指数
1
解决办法
4320
查看次数

无法确定主要终端 - 实体框架代码第一关系

请检查下面可能的解决方案部分

我有一个外键关系的问题 - 这是我的表:

public class Lead
{
    [Key]
    public int LeadId { get; set; }
    public int? CustomerId { get; set; }

    [ForeignKey("CustomerId")]
    public virtual Customer Customer { get; set; }
 }

public class Customer
{
    [Key]
    [Column("customer_id")]
    public int CustomerId { get; set; }

    [ForeignKey("CustomerId")]
    public virtual Lead Lead { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

我遇到了一个问题,我收到此错误:

Unable to determine the principal end of an association between the types 'Sales.Customers.Customer' and 'Sales.Leads.Lead'. The principal end of this association must be …
Run Code Online (Sandbox Code Playgroud)

c# asp.net entity-framework ef-code-first

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

保护 Azure Pipeline Yaml 文件不被编辑

目前,我们将管道 YAML 文件存储在 Azure Devops 的 git 存储库中 - 试图找到一种方法来限制某些用户编辑/访问 YAML 文件,甚至可能是包含 YAML 文件的文件夹。

我们希望实施额外的安全措施,以防止我们的开发人员修改我们的 YAML 文件以潜在地利用敏感信息或进行我们不批准的更改(我们制定了 PR 政策,但希望采取额外的安全措施)。

理想情况下 - 我们可以在 azure 中设置一个组 - 添加成员,并且只有这些成员才能修改包含我们的 YAML 文件的特定存储库文件夹内的文件 - 不确定这是否可能。

git azure azure-devops azure-pipelines

5
推荐指数
2
解决办法
2188
查看次数