小编Øyv*_*hen的帖子

需要在比较两个字符串后显示更改的文本

我有两个字符串:

1 string ="stackoverflow"

2 string ="stackoverflow很好"

我想表明:"stackoverflow is good".

应该用一些背景颜色突出"好".

怎么可能用c#做?

c# asp.net string

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

从ASP.NET MVC2应用程序执行Ajax调用时出现问题

我正在将现有的ASP.NET应用程序转换为MVC2,并且我有一个现有的方法,通过使用Ajax的jQuery调用,之前有效,但现在不起作用.因此,由于使用我无法弄清楚的MVC2,我似乎需要做一些改变.

我已经降低了代码的复杂性,但它仍然无法正常工作.这是我目前的代码:

触发按钮点击的jQuery脚本

function leaveComment() {
if (validate()) {
    $.ajax({
        type: "POST",
        url: "/Pages/PostBlogComment",
        data: "{'name':'Test','url':'Test','email':'Test','body':'Test','postid':'Test'}",
        dataType: "json",
        success: function (msg) {
            //success code goes here
        },
        error: function (msg) {
           //error code goes here
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

};

在我的控制器里面叫Pages,我创建了以下方法:

public string PostBlogComment( string name, string url, string email, string body, string postid)
{
  return "This is a test";
}
Run Code Online (Sandbox Code Playgroud)

调试时我可以看到调用了PostBlogComment方法,但是我遇到了两个主要问题:

  1. 该方法的所有参数都被接收为null,因此我没有可用的有用数据.现在进行测试,所有参数Test都会从代码中看到.
  2. 将结果返回到Ajax方法时,将调用错误路径,而不是成功路径,即使方法确实正常返回字符串(即使发送的参数为空)

对于那些经常使用这些东西的人来说,这个错误很容易被发现(或者至少我希望如此:))

ajax jquery asp.net-mvc-2

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

datepicker不是选择自定义日期格式?

要求是以"2010年1月22日"格式显示日期.

我编码了

 calanderFrom.Format = DateTimePickerFormat.Short;
 calanderFrom.CustomFormat = "dd MMM yyyy";
Run Code Online (Sandbox Code Playgroud)

但日期仍以"5/5/2011"格式出现.请指导我如何改变fromat.

谢谢

.net c# winforms

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

正在为所有操作调用ActionFilterAttribute

也许我误解了ActionFilterAttribute的观点,但我现在所拥有的是以下内容:

public class MyCustomAttribute : ActionFilterAttribute
{
  public override void OnActionExecuting(ActionExecutingContext filterContext)
  {
    //do something useful here
  }
}
Run Code Online (Sandbox Code Playgroud)

然后在我的Home控制器中,我有以下操作方法:

public class HomeController : Controller
{
  public ActionResult Index()
  {
    return View();
  }

  [MyCustom]
  public ActionResult Test()
  {
    return View();
  }
}
Run Code Online (Sandbox Code Playgroud)

我现在期望的是,OnActionExecuting当我尝试访问时会被触发/Home/Test,但是当我尝试访问时却没有/Home/Index.

但是,它会被两个动作方法触发.我也在内部验证过OnActionExecuting,实际上有Index一个被调用的动作.

OnActionExecuting当你调用一个用属性标记的动作方法时,是否有可能只被调用?

.net actionfilterattribute asp.net-mvc-3

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

用NSubstitute模拟表达

我有一个包含以下方法签名的接口:

TResult GetValue<T, TResult>(object key, Expression<Func<T, TResult>> property) where T : class;
Run Code Online (Sandbox Code Playgroud)

使用Moq,我可以模拟这种方法的特定调用,如下所示:

var repo = new Mock<IRepository>();
repo.Setup(r => r.GetValue<Customer, string>("SomeCustomerId", c => c.SecretAgentId)).Returns("SecretAgentId");
Run Code Online (Sandbox Code Playgroud)

那我打电话的时候

repo.Object.GetValue<Customer, string>("SomeCustomerId", c => c.SecretAgentId);
Run Code Online (Sandbox Code Playgroud)

Tt "SecretAgentId"如我所愿返回,所以一切看起来都很好。

我的问题是,在实际的生产代码中,我们使用NSubstitute,而不是Moq。我尝试在此处使用相同类型的设置:

var repo = Substitute.For<ICrmRepository>();
repo.GetValue<Customer, string>("SomeCustomerId", c => c.SecretAgentId).Returns("SecretAgentId");
Run Code Online (Sandbox Code Playgroud)

但是,当我在这里打电话时

repo.GetValue<Customer, string>("SomeCustomerId", c => c.SecretAgentId);
Run Code Online (Sandbox Code Playgroud)

它返回“”而不是 "SecretAgentId"

我试图取代c => c.SecretAgentIdArg.Any<Expression<Func<Customer, string>>>()只是为了看看它的工作原理,然后,再返回"SecretAgentId"预期。但是我需要验证是否使用正确的表达式而不是仅使用任何表达式来调用它。

因此,我需要知道是否有可能在NSubstitute中使它工作,如果可以,怎么办?

.net c# moq nsubstitute

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

快速确定接口/类中方法数的方法

有没有一种快速的方法来告诉VS2008中接口/类的方法数量?使用Resharper?使用NDepend?

c# visual-studio-2008

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

C#字符串文件路径问题

我正在尝试为SoundPlayer对象设置文件路径

如果我的主项目文件夹中有一个声音文件夹.我该如何发送

Soundplayer test = new Soundplayer("Sounds/Fireball.wav");
Run Code Online (Sandbox Code Playgroud)

c#

3
推荐指数
1
解决办法
1598
查看次数

使用单击事件禁用锚点

我有一个锚标记,它有一个链接到它的jQuery点击事件.

此click事件的第一件事是通过将disabled属性设置为true将锚设置为禁用.这会激发正确的外观,因为它myAnchor[disabled]从我的样式表中获取样式.

但是,当锚点已禁用设置为true时,它不会停止多次触发Click事件.我想这是因为disabled属性只适用于输入而不是锚点(正如我在尝试之后发现的那样).

此代码适用于应用程序内的许多锚点,因此不希望向Click事件本身添加一些代码,因为我必须将其复制到所有Click方法.即使我使用所需的代码创建一个函数,这意味着我(或者更糟糕的是,其他可能不知道的开发人员)必须记住将此行放在所有Click方法的第一位.

请记住,也可能在某些时候再次启用锚点,所以我不能只删除click事件,因为在启用时我需要跟踪其他地方的函数以及click方法.

所以问题是,禁用锚点的正确方法是什么?

jquery

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

引用另一个 Git 存储库中的项目的 ASP.NET Core 应用程序

我有一个由三个 ASP.NET Core MVC 应用程序和一个 ASP.NET Core 库组成的解决方案,该库具有由三个 MVC 应用程序共享的一些逻辑。每个应用程序和库都是它们自己的 Git 存储库。

现在,我正在尝试将其中一个 MVC 应用程序部署到 Azure,并且在部署时失败并显示以下错误日志(仅在此处显示发生错误的最后一部分)

Installing System.Security.Cryptography.Cng 4.2.0.
Installing System.Security.Cryptography.Csp 4.0.0.
Installing Microsoft.NETCore.Windows.ApiSets 1.0.1.
Committing restore...
Writing lock file to disk. Path: D:\home\site\repository\project.lock.json
D:\home\site\repository\project.json
Restore failed in 55782ms.

NuGet Config files used:
  C:\DWASFiles\Sites\#1cerebro-lantern\AppData\NuGet\NuGet.Config
Errors in D:\home\site\repository\project.json

Feeds used:
  Unable to resolve 'Telepathy (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
  https://api.nuget.org/v3/index.json

Installed:
  192 package(s) to D:\home\site\repository\project.json
Failed exitCode=1, command=nuget.exe restore -packagesavemode nuspec
An error has occurred during web site deployment.
Errors in D:\home\site\repository\project.json\r\n …
Run Code Online (Sandbox Code Playgroud)

.net github azure .net-core asp.net-core

3
推荐指数
1
解决办法
1084
查看次数

无法对 ASP.NET Core 中的 SOAP 服务进行身份验证

我正在尝试使用来自 ASP.NET Core 库项目的 SOAP Web 服务。

我已经安装了 Mictosoft WCF Web 服务参考提供程序,它为我创建了代理类,但我遇到了身份验证问题。

我的代码目前看起来像这样:

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);

var address = new EndpointAddress(@"https://myserviceaddress.asmx");
var client = new TestApiClient(binding, address);
client.ClientCredentials.UserName.UserName = "testusername";
client.ClientCredentials.UserName.Password = "testpassword";
var result = await client.GetDataAsync(params);
Run Code Online (Sandbox Code Playgroud)

我尝试了一些不同的方法,但我要么得到了未经授权,要么得到了以下内容的变体:The value 'TransportWithMessageCredential' is not supported in this context for the binding security property 'securityMode'..

我想我也应该在 上设置一些属性binding.Security.Message,但存在的唯一属性binding.SecurityTransportMode

有人知道如何正确设置吗?

从 ASP.NET Core 使用 SOAP 服务还有其他更好的方法吗?我喜欢一种不必创建代理类的动态方式,但是如果必须的话,我可以使用代理,但是我需要能够使用用户和密码进行身份验证,而且我必须使用 https。

c# authentication soap asp.net-core

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