所以我正在制作一些ajax帖子,它似乎在localhost上正常工作,但是当我将它发布到amazon上的ec2服务器时,我得到Uncaught SyntaxError:意外的令牌B.这似乎指向JSON解析失败.完全相同的数据库,相同的浏览器和相同的方法被调用.为什么它可以在本地而不是服务器上运行.
$.ajax({
url: '@Url.Action("Action")',
type: "POST",
data: ko.toJSON(viewModel),
dataType: "json",
contentType: "application/json; charset:utf-8",
success: function (result) {
},
error: function (xhr, textStatus, errorThrown) {
var errorData = $.parseJSON(xhr.responseText);
var errorMessages = [];
for (var key in errorData)
{
errorMessages.push(errorData[key]);
}
toastr.error(errorMessages.join("<br />"), 'Uh oh');
}
});
Run Code Online (Sandbox Code Playgroud)
这是服务器端的基本布局:
[HttpPost]
public JsonResult Action(ViewModel model)
{
try
{
Response.StatusCode = (int)HttpStatusCode.OK;
return Json("Successfull");
}
catch (Exception ex)
{
logger.Log(LogLevel.Error, string.Format("{0} \n {1}", ex.Message, ex.StackTrace));
Response.StatusCode = (int)HttpStatusCode.BadRequest;
List<string> errors = new List<string>(); …Run Code Online (Sandbox Code Playgroud) 我已经安装了VS2010和MVC2并使用tinyMCE测试了一个简单的表单.当我在tinyMCE中发布textarea的内容时,我得到了可怕的YSD和消息
"有潜在危险......"
我以前见过这个,所以我把它ValidateInput(false)放在控制器上,但没有快乐 - 我仍然得到错误.
edit.aspx中的页面代码是:
<% using (Html.BeginForm()){ %>
<!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->
<textarea id="elm1" name="mceText" rows="15" cols="80" style="width: 80%">
<p>
This is some example text that you can edit inside the
<strong> TinyMCE editor</strong>.
</textarea>
<br />
<input type="submit" name="save" value="Submit" />
<input type="reset" name="reset" value="Reset" />
<%} %>
Run Code Online (Sandbox Code Playgroud)
和控制器的行动是:
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public ActionResult Edit(string mceText)
{
return View();
}
Run Code Online (Sandbox Code Playgroud)
任何想法 - (我知道代码不完整)已经尝试了几个小时,但每个人只是说使用ValidateInput(false)
我有一个非常奇怪的问题.我发布了一个webrole到azure云服务.在这个项目中,它需要webrole调用Azure Rest API,我可以在本地模拟器中获取响应,但是,如果我将其发布到Azure,我会得到403禁止错误.我确信我已将证书安装到Azure.
可以通过以下步骤重现此错误:
控制台应用代码:
static void Main(string[] args)
{
try
{
// X.509 certificate variables.
X509Store certStore = null;
X509Certificate2Collection certCollection = null;
X509Certificate2 certificate = null;
// Request and response variables.
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null;
// Stream variables.
Stream responseStream = null;
StreamReader reader = null;
// URI variable.
Uri requestUri = null;
// Specify operation to use for the service management call.
// …Run Code Online (Sandbox Code Playgroud) 我不能用字符串属性做同样的事情.在下面的代码中,我想删除"姓氏"的验证并使其成为可选项.
[Required(ErrorMessage = "Required")]
[Display(Name="Last Name")]
public string LastName { get; set; }
Run Code Online (Sandbox Code Playgroud) 我有一个包含客户端路由的公共页面。我希望将所有形式的url Public/*路由到PublicController/Index。
我尝试了这个:
routes.MapRoute(
name: "Public",
url: "Public/{clientRoute}",
defaults: new { controller = "Public", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
这适用于类型为url的形式,Public/someRoute但不适用于形式Public/someRoute/secondRoute或其他形式的url Public/someRoute/secondRoute/thirdRoute。
我看到Ninject与asp.net-mvc 集成有一个扩展,但看起来我可以将Ninject与mvc完美集成而没有这个扩展.例如:
public class NinjectDependencyResolver : IDependencyResolver
{
private readonly IResolutionRoot _resolutionRoot;
public NinjectDependencyResolver(IResolutionRoot resolutionRoot)
{
_resolutionRoot = resolutionRoot;
}
public object GetService(Type serviceType)
{
return _resolutionRoot.TryGet(serviceType);
}
public IEnumerable<object> GetServices(Type serviceType)
{
return _resolutionRoot.GetAll(serviceType);
}
}
public class MvcApplication : HttpApplication
{
void Application_Start()
{
var modules = new INinjectModule[] { new ServiceModule() };
var kernel = new StandardKernel(modules);
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
Run Code Online (Sandbox Code Playgroud)
这是一些遗留扩展还是仍然相关?我看到源代码的最新更新,所以我有点困惑
protected void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
{
string kundeID = "-1";
int id = Convert.ToInt32(Request.QueryString["id"]);
int totalsum = Convert.ToInt32(ddlAmount.SelectedValue);
Handlevogn handlevogn = new Handlevogn
{
TotalSum = totalsum,
KundeID = kundeID,
Dato = DateTime.Now,
ErIHandlevogn = true,
ProduktID = id
};
HandlevognModell modell = new HandlevognModell();
lblResult.Text = modell.InsertHandlevogn(handlevogn);
}
Run Code Online (Sandbox Code Playgroud)
不断收到错误
无法将 typre 'string' 隐式转换为 'short'
对于局部变量 kundeID。
asp.net-mvc ×2
amazon-ec2 ×1
asp.net ×1
azure ×1
c# ×1
jquery ×1
json ×1
knockout.js ×1
ninject ×1