mardi 4 août 2015

Http request returns as failure but actually succeeds

I'm developing a web API and a website to interact with that api. So far I have each part done. I am using angular js for my website and an asp.net webapi for the other end. When I try to connect the two together to make it all work the signal sends and the api end gets executed like normal however in the console on the website end gives me an error: XMLHttpRequest cannot load http://localhost:1795/api/products/[ip address]/en-us/[product]/[version]/[email address]. A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:50028' is therefore not allowed access.

It just seems to be going in loops because if I now remove the custom header I provided for the Access-Control-Allow-Origin it still triggers the process I have in the api which gets executed as normal but I still end up getting an error on the other end. XMLHttpRequest cannot load http://localhost:1795/api/products/[ip address]/en-us/[product]/[version]/[email address]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:50028' is therefore not allowed access.

If I remove the credentials from the http request I get a 401 unauthorized error and the api process won't trigger. I've created both of these projects in Visual Studio 2013 and are both running in Chrome.

Do I ignore the errors on the website side and keep things as they are? Or is there another way to make the call without getting these console errors?



via Chebli Mohamed

Windows App Design

how to start windows app design in Visual Studio 2012 and latest version. I have good knowledge of design and develop web app in Visual Studio 2010 and 2012. Now I wish to move on Windows Mobile App Design and Develop. But I am unable to Start. Kindly help me and suggest me how I can start to design Windows mobile app.



via Chebli Mohamed

Textbox for Decimal value null when submitting form in ASP.Net?

Textbox value when submitting the form is null in the controller. Simplified structure of what I have is below:

MODEL

public class MyObject
{
    public decimal DecimalProperty { get; set; }
}

VIEW

@for(var i = 0; i < Model.Count; i++) 
{
   using (Html.BeginForm("UpdateObject", "MyController", FormMethod.Post))
   {
      @Html.Textbox(String.Format("Model[{0}].DecimalProperty", i), Model[i].DecimalProperty)
      <input type="submit" value="Update"/>
   }
}

CONTROLLER

public ActionResult UpdateObject(MyObject myObject)
{
   // Do Stuff...
}

If I put a breakpoint in the controller method, then check the property values of myObject, the DecimalProperty is null. There are other properties on the actual object I'm using and those come across alright, but for some reason this property isn't. I haven't found anything that suggests that decimals must be handled differently than a DateTime or string. I have also tried writing out the html for the input by hand:

 <input type="text" name="@(String.Format("Model[{0}].DecimalProperty", i))" value="@Model[i].DecimalProperty" />

I have set the name and the id attributes of the textbox just to be on the safe side. Any ideas as to why my textbox value is null when I submit the form?



via Chebli Mohamed

append server side code from client side jquery

I have a server side code block such as <%Response.Write(...)%> How would i append it dynamically from client side script using jquery?

$("div.items").append('<form action="#" method="POST">');
$(".items form').append('<%Response.Write(...)%>')  //???



via Chebli Mohamed

How to do performance testing for website hosted in integration environment

I wanted to do performance testing(profiling, instrumentation) for asp.net website which is hosted in our integration environment. I am able to do it in local machine using visual studio performance and diagnostics. How to do this in integration environment without installing visual studio in integration.



via Chebli Mohamed

ASP.NET c# Customer Resources "branching" system

Last couple of hours I am trying to figure out how I can use CustomerResources like the localization and globalization version of the Resources. I have a multilanguage website which uses Resources.localization-globalization.resx to get the texts for that language, example : Resources.en-EN.resx. Now I have multiple customers who want to have some texts changed to their own way of saying it. But also use Multilanguage on that version so what I wanted to do is create a folder based on the customer GUID, and use that name to select the right Resources file like this :

Google/CustomerResources.resx

the /\ folder is dynamic and could be either Google or Yahoo or Bing.

Is there a way to achieve this or could I change this to CustomerResources.Google.resx?



via Chebli Mohamed

Ajax Post in MVC... Why is the string null?

So basically I'm creating a Request system in a MVC application. I have this "Create Request" section where I can select the type of request I want to do in a DropDownList from Telerik. What I want to do is, every time I choose something from the list, a partial view appears with the form related to that type of request.

This is my ajax Post from the Create.cshtml View:

<script>
    function change() {
        var value = $("#RequestType").val();
        alert(value);
        $.ajax({
            url: "/Request/CreateRequestForm",
            type: "get",
            data: { requestValue : JSON.stringify(value)}
        }).done(function (data) {
            $("#partialplaceholder").html(data);
        }).fail(function () {
            alert('error');
        })
    };
</script>

This is my controller:

public ActionResult Index()
        {
           //Things
            return View();
        }

    [HttpGet]
    public ActionResult Create()
    {
        return View();
    }

    [HttpGet]
    public PartialViewResult CreateRequestForm(string dropDownValue)
    {   string partialView="";
        int RequestType = Convert.ToInt32(dropDownValue);
        switch (RequestType)
        {
            case 1 :
                partialView+="_CreateAbsence";
                break;
            case 2 :
                partialView += "_CreateAdditionalHours";
                break;
            case 3 :
                partialView += "_CreateCompensationDay";
                break;
            case 4 :
                partialView += "_CreateErrorCorrection";
                break;
            case 5 :
                partialView += "_CreateVacation";
                break;
        }
        return this.PartialView(partialView);
    }

Everytime time the even triggers my dropDownValue string is null... Why? Thanks in advance! :)

EDIT View Code

<h1>Create New Request</h1>

        @(Html.Kendo().DropDownList()
          .Name("RequestType")
          .DataTextField("Text")
          .DataValueField("Value")
          .Events(e => e.Change("change"))
          .BindTo(new List<SelectListItem>() {
              new SelectListItem() {
                  Text = "Absence",
                  Value = "1"
              },
              new SelectListItem() {
                  Text = "Additional Hours",
                  Value = "2"
              },
              new SelectListItem() {
                  Text = "Compensation Day",
                  Value = "3"
              },
              new SelectListItem() {
                  Text = "Error Correction",
                  Value = "4"
              },
              new SelectListItem() {
                  Text = "Vacation",
                  Value = "5"
              }
          })
          .Value("1")
        )


<script>
    function change() {
        var value = $("#RequestType").val();
        alert(value);
        $.ajax({
            url: "/Request/CreateRequestForm",
            type: "get",
            data: { requestValue : JSON.stringify(value)}
        }).done(function (data) {
            $("#partialplaceholder").html(data);
        }).fail(function () {
            alert('error');
        })
    };
</script>

<div id="partialplaceholder">

</div>



via Chebli Mohamed