我有一个复杂的JSON对象,它被发送到View没有任何问题(如下所示)但我无法弄清楚如何通过AJAX调用将这些数据序列化回.NET对象.各部分的细节如下.
var ObjectA = {
"Name": 1,
"Starting": new Date(1221644506800),
"Timeline": [
{
"StartTime": new Date(1221644506800),
"GoesFor": 200
}
,
{
"StartTime": new Date(1221644506800),
"GoesFor": 100
}
]
};
Run Code Online (Sandbox Code Playgroud)
我不确定如何将此对象传递给Controller方法,我在下面使用此方法,其中Timelines对象使用Properties镜像上述JS对象.
public JsonResult Save(Timelines person)
Run Code Online (Sandbox Code Playgroud)
我使用的jQuery是:
var encoded = $.toJSON(SessionSchedule);
$.ajax({
url: "/Timeline/Save",
type: "POST",
dataType: 'json',
data: encoded,
contentType: "application/json; charset=utf-8",
beforeSend: function() { $("#saveStatus").html("Saving").show(); },
success: function(result) {
alert(result.Result);
$("#saveStatus").html(result.Result).show();
}
});
Run Code Online (Sandbox Code Playgroud)
我已经看到这个问题类似,但不完全相同,因为我没有使用表单来操纵数据. 如何使用json将复杂类型传递给ASP.NET MVC控制器
我也看到过使用'JsonFilter'手动反序列化JSON的引用,但是想知道是否有办法通过ASP.NET MVC进行本地化的操作?或者以这种方式传递数据的最佳做法是什么?
我有一个标准的aspx页面,我需要在其中添加另一个标准HTML表单并将其提交到另一个位置(外部站点),但是每当我按下提交按钮时,页面似乎都会回复而不是使用子页面形成行动网址.
模拟下面的表单关系.请注意,在实际部署中,表单将成为母版页布局的内容区域的一部分,因此表单需要从母版页表单独立提交.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<form id="subscribe_form" method="post" action="https://someothersite.com" name="em_subscribe_form" >
<input type="text" id="field1" name="field1" />
<input id="submitsubform" type="submit" value="Submit" />
</form>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我想你不能但是有没有办法将方法作为属性的参数引用?就像下面的东西?我可以回退使用字符串,但更喜欢使用编译时间来验证类型是否正确.
[LinkToAction(Something)]
public void SomethingElse()
{
}
public static void Something()
{
}
public class LinkToActionAttribute : Attribute
{
public LinkToActionAttribute(MethodInfo info)
{
}
}
Run Code Online (Sandbox Code Playgroud) 我想知道缓存如何与基于内容协商的API协同工作.由于要获取XML或JSON资源,URI将是相同的,例如:
http://example.com/bikes/mountain
Run Code Online (Sandbox Code Playgroud)
该服务基于Accept类型标头返回JSON/XML.缓存有多聪明?
例如:
缓存检查接受/内容类型吗?或者这会导致JSON请求者获取XML数据,因为服务器缓存了什么?我希望这是一个非常明显的东西已经被照顾,否则,在URI中包含.xml/.json是不是一个非常大的论据?
我想我的问题基本上是,我可以安全地使用内容协商,同时仍然使用标准缓存技术吗?
想知道是否有人可以阐明使用谷歌标签管理器是否符合 PCIDSS?
我知道其中有一些规定可以确保标签不能被注入,例如保护服务器、xss 保护等,但找不到任何关于支持动态 html 更改的标签管理器是否可以的信息。
我可以看到这两个论点...
我有一个网络应用程序,到目前为止已被剥皮(只是基本的颜色和徽标,没有什么复杂)给一家公司,但是现在,由于与另一家公司合并,该网站需要被标记为两个独立的公司(操作正是两者都相同,并且它们共享相同的数据).最简单的方法是复制Web应用程序并托管它的两个实例,但这将是一个维护麻烦,我真的只想为同一站点设置DNS别名.
基本上我想根据网站的URL更改主题.例如alpha.company.com - >主题A beta.comany.com - >主题B.
你会怎么建议解决这个问题?
我在让WCF客户端连接到需要客户端证书和用户名/密码的服务器时遇到问题.
我已经验证使用JUST客户端证书使用此方法:
var binding = new WSHttpBinding(SecurityMode.Transport);
binding.Security.Transport = new HttpTransportSecurity();
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var ea = new EndpointAddress(EndpointUrl);
using (var p = new ServiceReference1.AAAClient(binding, ea))
{
try
{
p.ClientCredentials.ClientCertificate.SetCertificate(
System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser,
System.Security.Cryptography.X509Certificates.StoreName.My,
System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName,
CertificateSubject);
var x = p.RequiresClientCertificateOnly();
Console.WriteLine("Status: " + x.status);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine();
}
Run Code Online (Sandbox Code Playgroud)
下一个合乎逻辑的步骤是添加用户名/密码部分,但它会在未经授权的情况下返回403.我知道凭证和证书是有效的,因为我在中间使用fiddler提供客户端证书和用户名/密码,它工作正常,只是当通过WCF使用它似乎无法工作,或使用发送两个客户端证书和用户名/密码.
尝试使用两者的代码如下(尝试使用WSHttpBinding和BasicHttpBinding - 两者的结果相同):
var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
var ea = new EndpointAddress(EndpointUrl);
using (var p = new ServiceReference1.PingPortTypeClient(binding, ea))
{
try …Run Code Online (Sandbox Code Playgroud) ASP.NET MVC(以及一般的MVC)的标准模板似乎是{controller}/{action}/{id},但是,对于我正在进行的项目,我不确定这是否合适结构体.例如,如果我有一个控制汽车的应用程序,对我来说,拥有以下结构对我来说更有意义:
{car-rego}/{controller}/{action}/{data etc}
Run Code Online (Sandbox Code Playgroud)
这对我来说很有意义,因为汽车(由登记牌识别)是我们正在进行操作的资源,并且功能的逻辑分离被分离到控制器和动作中.这会导致URL如下:
/ESX-121/Power/On
/ESX-121/Speed/Set/100
/ESX-121/Speed/Current -- get the current speed (could be /ESX-121/Speed also)
/ESX-121/Turn/Left
/ESX-121/Speed/Set/90
/ESX-121/Power/Off
Run Code Online (Sandbox Code Playgroud)
如果这遵循默认模式,它将如下所示:
/Power/On/ESX-121
/Speed/Set/ESX-121/100
/Speed/Current/ESX-121 -- get the current speed (could be /Speed/ESX-121 also)
/Turn/Left/ESX-121
/Speed/Set/ESX-121/90
/Power/Off/ESX-121
Run Code Online (Sandbox Code Playgroud)
对我来说,第一个选项使得可读URL更有意义,资源标识符位于一个恒定的逻辑位置.例如/ Speed/Set/ESX-121/100向我建议,存在类型速度的资源,其标识符为ESX-121,实际情况并非如此,操作在汽车上.
你如何构建URL以及相关的控制器和动作来处理这种情况?您认为这是一个可接受的解决方案,还是有更好的方法来构建它?
asp.net ×2
asp.net-mvc ×2
c# ×2
rest ×2
.net ×1
attributes ×1
caching ×1
content-type ×1
forms ×1
friendly-url ×1
html ×1
json ×1
pci-dss ×1
reflection ×1
security ×1
themes ×1
url ×1
wcf ×1