小编Tom*_*mmy的帖子

未捕获的SyntaxError:实时但不是本地服务器上的意外令牌B.

所以我正在制作一些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)

jquery json amazon-ec2 asp.net-mvc-3 knockout.js

5
推荐指数
2
解决办法
5388
查看次数

检测到一个潜在危险的request.form值,但validateinput(false)无效

我已经安装了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%">
        &lt;p&gt;
            This is some example text that you can edit inside the
  &lt;strong&gt; TinyMCE editor&lt;/strong&gt;.
    </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)

asp.net-mvc-2

4
推荐指数
2
解决办法
5356
查看次数

403禁止从Web角色实例调用Azure rest api时

我有一个非常奇怪的问题.我发布了一个webrole到azure云服务.在这个项目中,它需要webrole调用Azure Rest API,我可以在本地模拟器中获取响应,但是,如果我将其发布到Azure,我会得到403禁止错误.我确信我已将证书安装到Azure.

可以通过以下步骤重现此错误:

  1. 首先使用以下链接创建证书:http://msdn.microsoft.com/en-us/library/windowsazure/gg651127.aspx
  2. 使用webrole创建云服务,Azure门户中的证书,云服务证书和webrole-> property-> certificate.
  3. 发布项目.
  4. 远程登录Web角色实例.
  5. 在本地创建一个控制台应用程序,然后将调试文件夹复制到远程实例并在远程应用程序中运行exe.你可以发现应用程序可以在本地运行完美,但在Azure实例中,似乎它可以找到证书,但仍然得到403禁止错误.

控制台应用代码:

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)

azure

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

如何删除MVC4中的必需属性,尽管模型中已经需要这样做

我不能用字符串属性做同样的事情.在下面的代码中,我想删除"姓氏"的验证并使其成为可选项.

[Required(ErrorMessage = "Required")]    
[Display(Name="Last Name")]
public string LastName { get; set; }
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc-validation asp.net-mvc-4

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

ASP MVC将对控制器的所有请求路由到Index操作?

我有一个包含客户端路由的公共页面。我希望将所有形式的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

asp.net asp.net-mvc

3
推荐指数
1
解决办法
1471
查看次数

我是否需要再使用ninject.mvc扩展名?

我看到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)

这是一些遗留扩展还是仍然相关?我看到源代码的最新更新,所以我有点困惑

asp.net-mvc ninject

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

无法将类型“字符串”隐式转换为“短”

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。

c#

-3
推荐指数
1
解决办法
6792
查看次数