我是ASP.NET MVC和Web API的新手,并试图获得基础知识.据我所知,我们在VS 2013项目模板,命名为MVC,Web API和Both of them together.
我已经完成了教程并了解到我们可以通过单独使用MVC以及使用Web API模板来创建API.
那么,基于架构和使用情况,它们之间有什么区别?
我正在尝试使用JSON.Net将JSON对象从某些文本添加到现有的JSON文件中.例如,如果我有如下的JSON数据:
{
"food": {
"fruit": {
"apple": {
"colour": "red",
"size": "small"
},
"orange": {
"colour": "orange",
"size": "large"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我一直试图这样做:
var foodJsonObj = JObject.Parse(jsonText);
var bananaJson = JObject.Parse(@"{ ""banana"" : { ""colour"": ""yellow"", ""size"": ""medium""}}");
var bananaToken = bananaJson as JToken;
foodJsonObj["food"]["fruit"]["orange"].AddAfterSelf(bananaToken);
Run Code Online (Sandbox Code Playgroud)
但是这给出了错误: "Newtonsoft.Json.Linq.JProperty cannot have multiple values."
我实际上尝试了几种不同的方法,但似乎无法到达任何地方.在我的例子中,我真正想要做的是将新项添加到"fruit".如果有更好的方法或更简单的库可供使用,请告诉我.
我想在azure上托管我的WebApi项目.但我不确定我应该用哪种方式在天蓝色上运行它.就像有网站,包含Web角色和工作者角色的云服务一样.然后我应该选择哪一个.如果云服务是选项,那么Web角色和工作者角色中的哪一个是好的?
任何帮助表示赞赏.
我想生成重置密码链接以发送到用户的电子邮件,该电子邮件将打开ResetPassword页面.在此页面上,我将填写有关新密码的详细信息,然后确认密码.
为此我遵循了这个链接
但是有一个我无法在我的web api项目中找到的Url.Action方法.
var callbackUrl = Url.Action(
"ConfirmEmail", "Account",
new { userId = user.Id, code = code },
protocol: Request.Url.Scheme);
Run Code Online (Sandbox Code Playgroud)
Hase任何人在web api中完成了重置密码部分?我需要一些帮助.
我有一个单元测试我正在检查一个方法是否被调用一次,所以我尝试这样: -
这是我的ILicenseManagerService模拟,我通过construstor传递它的对象.
public Mock<ILicenseManagerService> LicenseManagerService { get { return SetLicenseManagerServiceMock(); } }
private Mock<ILicenseManagerService> SetLicenseManagerServiceMock()
{
var licencemangerservicemock = new Mock<ILicenseManagerService>();
licencemangerservicemock.Setup(m => m.LoadProductLicenses()).Returns(ListOfProductLicense).Verifiable();
return licencemangerservicemock;
}
public static async Task<IEnumerable<IProductLicense>> ListOfProductLicense()
{
var datetimeoffset = new DateTimeOffset(DateTime.Now);
var lst = new List<IProductLicense>
{
GetProductLicense(true, datetimeoffset, false, "1"),
GetProductLicense(true, datetimeoffset, false, "2"),
GetProductLicense(true, datetimeoffset, true, "3")
};
return lst;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个模拟对象来设置_licenseManagerService并在测试中的方法中调用LoadProductLicenses().像这样.许可证即将到期.
var licenses = (await _licenseManagerService.LoadProductLicenses()).ToList();
Run Code Online (Sandbox Code Playgroud)
我尝试验证对此方法的调用 -
LicenseManagerService.Verify(m => m.LoadProductLicenses(),Times.Once);
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的单元测试异常时,说方法根本没有被调用.我在哪里做错了?
编辑 @dacastro我在这里调用相同的模拟是我的单元测试.
[TestMethod]
[TestCategory("InApp-InAppStore")]
public async …Run Code Online (Sandbox Code Playgroud) 我面临一个奇怪的问题.我使用Windows Phone 8.1 silverlight和Windows通用链接进行Toast通知.我能够在Windows Phone应用程序中获取Toast通知,它在链接中提到的Windows 8.1中几乎相同.但是Toast并没有在Windows 8.1中出现.
步骤: -
1 - >我已经从Package.appxmanifest文件中启用了Toast .
2 - >然后我在上面提到的on_launched事件中的App.Xaml.cs中添加了这段代码
它显示了注册成功,如链接中所述
private async void InitNotificationsAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
var result = await hub.RegisterNativeAsync(channel.Uri);
// Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
} …Run Code Online (Sandbox Code Playgroud) 如何使用Xamarain.Android中的属性将可搜索xml的MetaData添加到Activity.必须添加的元数据: -
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable">
</meta-data>
Run Code Online (Sandbox Code Playgroud)
在这里,我使用Xamarin.Android中的ActionBar搜索Widget制作一个可搜索的Android Listview.任何帮助表示赞赏.:)
我想Class Object在Xamarin.Androidapp 中将一个活动传递给另一个活动.我可以使用Intent.PutExtra方法传递简单的字符串.
有人知道吗.感谢anyhelp :)
我只是尝试运行Xamarin App,这是如何工作的.我从这里下载了应用程序Sample App.我已经成功安装了Xamarin.当我试图运行该应用程序时,它说: -
Error 1 User code size, 430080 bytes, is larger than 65536 and requires aáIndieá(or higher) License. XamarinStore.Droid
Error 2 Using type System.Reflection.Assembly requiresáIndieá(or higher) License. XamarinStore.Droid
任何帮助表示赞赏:)
我刚刚遇到了在Windows Phone 8.1(SilverLight)中获取用户设置区域的问题.
情况: 我已将Region设置为United Kingdom和语言English(United States)(这样做是有效的).
在那种情况下,我仍然UnitedState(US)通过这些方法获得该地区:
RegionInfoThread.CurrentThread System.Globalization
private static void GetRegion()
{
// all of the three returing UnitedStates.
var dfg = RegionInfo.CurrentRegion;
var cuture = Thread.CurrentThread.CurrentCulture;
var cul = CultureInfo.CurrentCulture;
}
Run Code Online (Sandbox Code Playgroud)为什么这些不归属United Kingdom于某个地区?
c# ×8
asp.net ×3
xamarin ×3
android ×2
azure ×2
.net ×1
asp.net-mvc ×1
cloud ×1
json.net ×1
moq ×1
tdd ×1
unit-testing ×1
windows-8 ×1
windows-8.1 ×1