小编pat*_*dge的帖子

使用MicrosoftDateFormat时,防止Json.NET 4.5附加时区偏移量

DateTimeConverterBase缺少自定义实现,是否有一些方法可以保留Json.NET 4.5+,当设置为使用时DateFormatHandling.MicrosoftDateFormat,为任何非UTC提供时区偏移量DateTime

"\/Date(1333645844276-0600)\/"
Run Code Online (Sandbox Code Playgroud)

细节

我正在将API项目从使用内置.NET转换JavaScriptSerializer为使用Json.NET生成JSON.在Json.NET中,对于UTC DateTime,默认的日期时间序列化类似于.NET版本:

"\/Date(1333645844276)\/"
Run Code Online (Sandbox Code Playgroud)

对于非UTC,不像JavaScriptSerializer,Json.NET在结果中附加时区偏移量(对于我的区域,每年的这个时间为-6):

"\/Date(1333645844276-0600)\/"
Run Code Online (Sandbox Code Playgroud)

这是我用来将Json.NET 4.5+切换回\/Date(...)\/格式(称为MicrosoftDateFormat)的代码:

JsonSerializerSettings customJsonSettings = new JsonSerializerSettings() {
    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat
};
string result = JsonConvert.SerializeObject(DateTime.Now, customJsonSettings);
Run Code Online (Sandbox Code Playgroud)

解决方案似乎就像告诉Json.NET使用不同的DateTimeZoneHandling设置一样简单.我已经想尽设置为DateTimeZoneHandling(Local,Utc,UnspecifiedRoundtripKind),他们都保持"-0600"的输出.事实上,它们都为非UTC产生相同的结果DateTime.

JsonSerializerSettings customJsonSettings = new JsonSerializerSettings() {
    DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
    DateTimeZoneHandling = DateTimeZoneHandling.Utc
};
string result = JsonConvert.SerializeObject(DateTime.Now, customJsonSettings);
"\/Date(1333647855743-0600)\/"
Run Code Online (Sandbox Code Playgroud)

警告

理想情况下,我已经拥有UTC的所有时间.我当然计划使用此API的下一个版本.由于这是一个实时API,因此在发布新版本之前,不值得冒输出更改.对于大多数JSON解析系统来说,它似乎不是一个问题,但我不能冒这个改变的风险,因为JSON标准没有正式说明日期序列化.

json.net

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

RouteCollection.Ignore和RouteCollection.IgnoreRoute之间的区别?

RouteCollection.Ignore(url, constraints)和之间有什么区别RouteCollection.IgnoreRoute(url, constraints)

背景

新的MVC项目IgnoreRoute在Global.asax RegisterRoutes方法中包含此调用,以跳过对ASP.NET系统中其他位置处理的.axd位置的请求的路由.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Run Code Online (Sandbox Code Playgroud)

我想为项目添加一个额外忽略的路由,然后我开始输入新行.之后routes.I,Intellisense弹出,.Ignore并且.IgnoreRoute两者听起来都差不多.

根据MSDN文档,您可以看到一个是类的实例方法,System.Web.Routing.RouteCollection另一个是该类的扩展方法System.Web.Mvc.RouteCollectionExtensions.

  • RouteCollection.Ignore:"如果请求URL满足指定的约束,则定义不应检查路由匹配的URL模式"(MSDN文档).
  • RouteCollection.IgnoreRoute:"忽略给定的可用路由列表和约束列表的指定URL路由"(MSDN文档).

两者都采用路由URL模式和一组约束来限制路由在该URL模式上的应用.

asp.net-mvc ignoreroute asp.net-mvc-routing

18
推荐指数
1
解决办法
3986
查看次数

在Mercurial中修复失败的完整性检查?

我只是hg pull在存储库上做了一些变更集.它说跑了hg update,所以我做了.不幸的是,当我这样做时,它失败并出现以下错误消息:

abort: integrity check failed on 00manifest.i:173!
Run Code Online (Sandbox Code Playgroud)

当我跑步时hg verify,它告诉我有一些问题不在清单中(有一些轻微的路径模糊):

>hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
 somewhere1/file1.aspx@172: in changeset but not in manifest
 somewhere2/file1.pdf@170: in changeset but not in manifest checking files
 file3.csproj@172: ee005cae8058 not in manifests
 somewhere2/file1.pdf@171: 00371c8b9d95 not in manifests
 somewhere3/file1.ascx@170: 5c921d9bf620 not in manifests
 somewhere4/file1.ascx@172: 23acbd0efd3a not in manifests
 somewhere5/file1.aspx@170: ce48ed795067 not in manifests
 somewhere5/file2.aspx@171: 15d13df4206f not in manifests
1328 files, 174 changesets, 3182 …
Run Code Online (Sandbox Code Playgroud)

mercurial

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

FragmentPagerAdapter麻烦和困境:构造函数未定义

编辑:我已经重新编写了一些代码来尝试通过错误(但现在应用程序在启动时崩溃).首先,我的类现在扩展了FragmentActivity,以便我可以访问方法getSupportFragmentManager();. 然后,在创建中,我改变了我的构造函数:

mTabsAdapter = new TabsAdapter(this.getSupportFragmentManager(), this, mViewPager);
Run Code Online (Sandbox Code Playgroud)

从那里,在我的子类中,我更改了代码以反映这一点:

public TabsAdapter(FragmentManager fm, Activity activity, ViewPager pager) {
    super(fm);
    mContext = activity;
    mActionBar = activity.getActionBar();
    mViewPager = pager;
    mViewPager.setAdapter(this);
    mViewPager.setOnPageChangeListener(this);
}
Run Code Online (Sandbox Code Playgroud)

正如我所说,它仍然崩溃,此时有任何想法吗?

开始原始问题: 我有以下错误:"构造函数FragmentPagerAdapter(FragmentManager)未定义"*

当我尝试执行以下行时:

super(activity.getFragmentManager());这一行遵循我public TabsAdapter(Activity activity, ViewPager pager) {的扩展FragmentPagerAdapter.

基本上,我正在尝试获取我的8+片段应用程序(8个片段,一个活动,其中包含一组链接到每个片段的ActionBar选项卡[为简洁起见,此处仅显示一个"loginTab"]).

这是我的整个代码:

编辑:我用于参考的页面: http ://developer.android.com/reference/android/support/v4/view/ViewPager.html

http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/

package com.davekelley.polling;

import java.util.ArrayList;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import …
Run Code Online (Sandbox Code Playgroud)

tabs android android-viewpager android-actionbar

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

MVC @import html关键字

我正在尝试使用:

<style>@import url("css/main.css");</style>
Run Code Online (Sandbox Code Playgroud)

但是mvc在剃刀视图中将其视为.net代码."CS0103:当前上下文中不存在名称'import'"我该如何解决?谢谢

asp.net-mvc razor asp.net-mvc-3

13
推荐指数
2
解决办法
6717
查看次数

AngularJS $ http.post(..) - 错误:$ http未定义

我是第一次尝试使用AngularJS.使用该$http.post("url", data)功能时,我收到一个Error: $http is not defined控制台消息.

在我的HTML页面的顶部,我在所有其他JS导入之后包括AngularJS.

由于小部件依赖等,我还包括其他JavaScript库.我的脚本导入部分如下所示:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="http://www.trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="http://www.trirand.com/blog/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

我有一个控制器,我用它来发送一些数据到服务器:

function FormCtrl($scope) {
  $scope.sendData = function(){
        var data = "firstName=" + $scope.firstName + "&" +
            "lastName=" + $scope.lastName + "&" +
            "address=" + $scope.address + "&" +
            "postcode=" + $scope.postcode;

        $http.post("/data/person/put", data);
     };
}
Run Code Online (Sandbox Code Playgroud)

sendData功能附在按钮上.一切正常,直到调用$http.post(...)控制台输出错误.

完整的错误列表是:

Error: $http is not defined
$scope.sendData@http://localhost:8080/angularjs/:96
Mc/x/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js:71
ec[c]</</</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js:142
e.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js:87
e.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js:87
ec[c]</</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js:142
c.event.handle@http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js:63
c.event.add/o@http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js:57

https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js …
Run Code Online (Sandbox Code Playgroud)

angularjs

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

有没有办法修复错误:“Xamarin.Forms 建议 TargetPlatformMinVersion &gt;= 10.0.17763.0(当前项目为 -1)”

当我想将 Xamarin 应用程序从 Android 9.0 升级到 Android 10 时遇到问题。

/Users/user/.nuget/packages/xamarin.forms/4.8.0.1269/buildTransitive/Xamarin.Forms.targets(5,5): 
Warning: Xamarin.Forms recommends TargetPlatformMinVersion >= 10.0.14393.0 (current project is -1) (WeatherApp)
Run Code Online (Sandbox Code Playgroud)

错误在代码的这一部分:

 <Warning
    Text="Xamarin.Forms recommends TargetPlatformVersion &gt;= 10.0.17763.0 (current project is $(MicrosoftUIXamlTargetPlatformCheckValue))"
    Condition="$(MicrosoftUIXamlTargetPlatformCheckValue) &lt; 17763" />
Run Code Online (Sandbox Code Playgroud)

我想在 Android 10 上运行这个应用程序,但是在真正的 Android 设备应用程序上构建和运行的每个干净的应用程序每次都没有响应。

c# android xamarin

12
推荐指数
2
解决办法
3586
查看次数

在Xamarin Forms上创建ICommand Bindable属性

我有一个自定义复选框控件,我使用ICommand属性和相应的可绑定属性创建(我的复选框是一个Xamarin.Forms XAML页面),代码是:

CheckBox.xaml

<Image x:Name="imgCheckBox"
       WidthRequest="20"
       HeightRequest="20"/>

<Label x:Name="lblCheckBox"
       TextColor="Black"
       VerticalOptions="CenterAndExpand"/>

<TapGestureRecognizer Tapped="OnCheckBoxTapped"/>
Run Code Online (Sandbox Code Playgroud)

CheckBox.xaml.cs

public partial class CheckBox : ContentView
{
    private static ImageSource uncheckedImage;
    private static ImageSource checkedImage;

    public CheckBox()
    {
        InitializeComponent();
        uncheckedImage = ImageSource.FromResource("cbUnchecked.png");
        checkedImage = ImageSource.FromResource("cbChecked.png");
        imgCheckBox.Source = uncheckedImage;
    }

    public static readonly BindableProperty IsCheckedProperty =
        BindableProperty.Create<CheckBox, bool>(
            checkbox => 
                checkbox.IsChecked,
                false,
                propertyChanged: (bindable, oldValue, newValue) =>
                {
                    CheckBox checkbox = (CheckBox)bindable;
                    EventHandler<bool> eventHandler = checkbox.CheckedChanged;
                    if (eventHandler != null)
                    {
                        eventHandler(checkbox, newValue);
                    }
                });        

    public bool …
Run Code Online (Sandbox Code Playgroud)

custom-controls bindable xamarin xamarin.forms

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

在Visual Studio 2017中的local.settings.json本地开发中缺少AzureWebJobsStorage的值

我正在本地开发一个azure函数,打开了Storage Emulator和de Storage Explorer.

文件树

文件树

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
  },
  "ConnectionStrings": {
    "PlantaoEntities": {
      "ConnectionString": "CENSORED",
      "ProviderName": "System.Data.EntityClient"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是在尝试运行代码时收到以下消息:

缺少local.settings.json中AzureWebJobsStorage的值.除HTTP之外的所有触发器都需要这样做.您可以运行'func azure functionapp fetch-app-settings'或在local.settings.json中指定连接字符串

它在重建解决方案之前工作,如果我尝试func azure functionapp fetch-app-settings <functionAppName>它尝试从天蓝色门户网站本身检索信息.

azure azure-functions visual-studio-2017

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

我可以从C#向IIS发送一个空的HTTP POST WebRequest对象吗?

我是否需要在WebRequest对象中打一些随机垃圾数据以获取IIS上的HTTP状态码411限制?

我在MVC 3应用程序中有一个HttpPost操作方法,该方法使用一个POST请求,其中包含在查询字符串中传递的所有相关信息(不需要正文).

[HttpPost] public ActionResult SignUp(string email) { ... }
Run Code Online (Sandbox Code Playgroud)

它在Visual Studio内置的Web主机Cassini中运行良好.不幸的是,一旦MVC代码在IIS [7.5 on 2008 R2]上运行,当我从外部C#表单应用程序点击它时,服务器正在回调HTTP错误代码.

远程服务器返回错误:(411)长度必需.

这是调用代码:

WebRequest request = WebRequest.Create("http://somewhere.com/signup/?email=a@b.com");
request.Method = "POST";
using (WebResponse response = request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader responseReader = new StreamReader(responseStream)) {
    // Do something with responseReader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)

c# iis-7 webrequest

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