小编Jid*_*jan的帖子

HttpClient不支持PostAsJsonAsync方法C#

我试图从我的web应用程序调用web api.使用.net 4.5并在编写代码时我收到错误HttpClient不包含定义PostAsJsonAsync方法

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:51093/");
client.DefaultRequestHeaders.Accept.Add(
   new MediaTypeWithQualityHeaderValue("application/json"));
var user = new Users();
user.AgentCode = 100;
user.Remarks = "Test";
user.CollectionDate = System.DateTime.Today;
user.RemittanceDate = System.DateTime.Today;
user.TotalAmount = 1000;
user.OrgBranchID = 101;

var response = client.PostAsJsonAsync("api/AgentCollection", user).Result;
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:51093/");
client.DefaultRequestHeaders.Accept.Add(
   new MediaTypeWithQualityHeaderValue("application/json"));
var user = new Users();
user.AgentCode = 100;
user.Remarks = "Test";
user.CollectionDate = System.DateTime.Today;
user.RemittanceDate = System.DateTime.Today;
user.TotalAmount = 1000;
user.OrgBranchID = 101;

var …
Run Code Online (Sandbox Code Playgroud)

c# json asp.net-web-api dotnet-httpclient

223
推荐指数
9
解决办法
21万
查看次数

无法加载文件或程序集'WebGrease,Version = 1.5.1.25624,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一

我有一个MVC4 Web api项目.在运行服务项目时,我收到一个错误

无法加载文件或程序集'WebGrease,Version = 1.5.1.25624,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.该系统找不到指定的文件.

我添加了WebGrease.dll文件,但仍然出现错误

并尝试更改web.config

<bindingRedirect oldVersion="0.0.0.0-1.3.0.0"/>"
Run Code Online (Sandbox Code Playgroud)

<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
Run Code Online (Sandbox Code Playgroud)

请告知我缺少的东西.

.net c# dll asp.net-mvc-4 webgrease

69
推荐指数
6
解决办法
7万
查看次数

.NETFramework,Version = v4.5框架是比当前目标框架".NETFramework,Version = v3.5"更高的版本

我在Framework 3.5中创建了我的第一个项目,并且我转换为框架4.5并且它完美地工作.其次,我尝试将此项目的引用添加到在框架4.5中创建的另一个项目.在添加引用后构建我的第二个项目时,我收到一条错误消息:

1. The primary reference "xxx" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v3.5".
2. The type or namespace name 'xxx' could not be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)

请告诉我遗失的地方

.net c# asp.net frameworks

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

如何在Crystal报告中取代空白日期而不是12/30/1899

我正在使用水晶报告,我使用日期参数.在某些情况下,我没有从数据库返回任何日期.系统正在跟踪默认日期12/30/1899.所以在这种情况下,我想将报告与空白日期绑定.需要显示所有其他字段的空白日期.请帮忙

在此先感谢Jidheesh

.net c# datetime crystal-reports

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

在单元测试 FormsAuthentication.SignOut() 中抛出错误

在运行我的单元测试方法时,我收到错误 FormsAuthentication.SignOut()。我已经像这样嘲笑了 httpcontext

var httpRequest = new HttpRequest("", "http://localhost/", "");
var stringWriter = new StringWriter();
var httpResponse = new HttpResponse(stringWriter);
var httpContext = new HttpContext(httpRequest, httpResponse);
var sessionContainer = new HttpSessionStateContainer(
    "id",
    new SessionStateItemCollection(),
    new HttpStaticObjectsCollection(),
    10,
    true,
    HttpCookieMode.AutoDetect,
    SessionStateMode.InProc,
    false);
SessionStateUtility.AddHttpSessionStateToContext(httpContext, sessionContainer);
var controller = new AccountController();
var requestContext = new RequestContext(new HttpContextWrapper(httpContext), new RouteData());
controller.ControllerContext = new ControllerContext(requestContext, controller);
var actual = controller.Login(new CutomerModel() { Login = "admin", Password = "Password1" });
return httpContext;
Run Code Online (Sandbox Code Playgroud)

在登录方法中

public ActionResult Login(CutomerModel …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing forms-authentication mocking httprequest

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