Application Working Only When I remotely logged into the server - asp.net-mvc

I have a very small mvc application with 2 text boxes and few buttons. When user clicks on any button, data will be retrieved against particular value entered in text box.
But when I hosted it into the IIS server, its working only when I logged into the server remotely from my local machine, as soon as close the remote connection its giving error as "Data Not found".
In the coding I am displaying this error(Error Panel with ID #ErrorMessage) when we really don't have data and for any other exception as well. Please find my below code and advice why its working only when I remotely logged into the server
$.ajax({
url: "#Url.Action("DownloadForms", "Home")" ,
type: "POST",
data: { transactionType: btnType, QuotationNumber: quotNumber, ContractNumber: contractNumber},
cache: false,
async: true,
success: function (data) {
$('#divBlock').hide();
if (data != "") {
var _baseUrl = "#Url.Action("Download", "Home")" + "?FileVirtualPath=" + data;
window.location = _baseUrl;
}
else {
$("#ErrorMessage").css("display", "block");
$('#ldDialog').trigger('click');
ev.stopPropagation();
return false;
}
},
error: function (data) {
$('#divBlock').hide();
$("#ErrorMessage").css("display", "block");
$('#ldDialog').trigger('click');

The solution for this problem is, we just need to set the identity in component services of the server in which our application is hosted.
For example go to Start-->Component Services-->Microsoft Excel (or word)-->Properties-->Identity-->Set credentilas for This User(of user configured in IIS)
ASP.Net Com-InterOp Excel Generation issue when hosting

Related

How to send files to the controller using multipart FormData() on an iPad in Safari

My fellow coder and I are having issues sending some image uploads to the MVC controller via a multipart FormData() element. What we currently have set up has been tested on a windows desktop using the latest versions of Chrome, IE, Edge, Firefox, and Opera without any issues.
Below is the JavaScript and ajax we are using. We have multiple file inputs that accept multiple image files. The loop below goes through and individually appends each file from each input.
var index = 0;
var data = new FormData();
data.append("datalist", JSON.stringify(formInfo)); //list of objects
data.append("form", JSON.stringify(headerInfo)); //object
var images = document.getElementsByClassName("ImageUpload");
for (var i = 0; i < images.length; i++){
var files = $(images[i]).prop("files");
if (files != null && files.length > 0){
for (var e = 0; e < files.length; e++){
//append the image with a filename
data.append("image" + ++index, files[e]);
}
}
}
UpdateData(data);
function UpdateData(datalist) {
$.ajax({
url: '#Url.Action("UpdateData", "Home")',
type: "POST",
cache: false,
contentType: false,
processData: false,
datatype: "JSON",
data: datalist,
success: function (result) {
//do stuff
}
});
}
In the controller, we are getting the information through Request.Form and Request.Files. As I mentioned, we are not having any problems other than on the iPad. When using the iPad, all it does is hang there, and does not even hit the controller. We do not have access to a Mac machine, so we can't hook up the iPad to use developer tools. The iPad has the latest version of IOS and has all app updates installed. We have spent a good portion of the afternoon trying various methods we found online, and even gave the google chrome app a whirl. But alas, we have been left to scratch our heads. Any help or information would be greatly appreciated.
Thanks in advance.

RequestVerificationToken cookie is not being sent in Ajax POST requests

Here is the Ajax code:
var token = $('form input[name="__RequestVerificationToken"]').val();
var data = {};
data.Type = $(e.target).attr('type');
data.__RequestVerificationToken = token;
url = '#Url.Action("MyAction", "MyController")';
$.ajax({
type: 'POST',
url: url,
data: data,
dataType: "html",
success: function (result) {
//do some stuff
},
error: function (err) {
//display error
}
})
In IE 11 Developer tools, during the initial load of the page (GET), I can see that the RequestVerificationToken cookie is being set. Also, the form element for RequestVerificationToken is being populated too. During the Ajax POST, however, the cookie is not part of the request.
Chrome works fine in both places, and during the Ajax POST, the cookie is present. IE 11 works locally (localhost), but this problem arises when IE 11 accesses the application on the server, and this error is returned:
The required anti-forgery cookie "__RequestVerificationToken_L1JldkNvbm5lY3Q1" is not present.
For some reason IE 11 doesn't include the cookie in the Ajax POST when the application is on the server. I can see that it is missing in the Network tab of IE Developer Tools. In the Network tab of Chrome Developer tools, the cookie is present, and the POSt works.
ASP.NET MVC 5

jquery load page to dialog

I develop Intranet application with login via AD. In my application I need load web page from another application on same server and show this page in dialog.
$('#btnExample').click(function () {
var id = getCurrentId();
var url = 'http://SERVERNAME:81/Runtime/Forms/formDetail.aspx?SN=' + id;
jQuery.support.cors = true;
$('#pagePreview').load(url, function (response, status, xhr) {
alert(xhr.status + " " + xhr.statusText);
});
$('#pagePreview').dialog(
{
draggable:false,
height: 768,
width: 1024,
modal: true,
});
return false;
});
The load function throw error: Access Denied.
Why?
In my application is user logged by Active Directory and in the second app is logged too by AD...
Is any other way to resolve it? I need display this page in my site in a dilog.
Thanks
The second page is probably not on the same host as the first, so your request violates the "same origin policy".
As workaround, try an ajax request, load html into something, then populate the dialog with it. If the request is still denied make a local php script that makes a curl request to the specified page, and make an ajax request towards that script.
If it still fails... something is wrong.

How to return to app from web service

Edit:
I have a web service (written in PHP) to retrieve data and return the information using JSON, however I am unsure how to integrate this web service with my PhoneGap app. How do I do this?
Original question:
I have a basic app that uses a web service to retrieve data and displays the information using JSON, however I am unsure as to how to return to the app.
It is being coded in Dreamweaver using PhoneGap.
There is a form with a single input, the user selects "search" and it uses the web service to display the information.
However I cannot figure out how to go 'back' to the app as the loaded page is now on a different server.
How can this be achieved?
You should use a JQuery AJAX request. Here is an simple example:
$.ajax({
type: "POST",
url: "your-web-service-url-here.php",
//Optional data to send to the service.
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
//This is the JSON message received from the service.
alert( "Data Saved: " + msg );
});
Hope this helps.

Try to post JSON.stringify object to aspnet mvc controller - bad request

I'm trying to post a JS Object stored in a hidden field:
$("#hdnArr").val(JSON.stringify(arr));
<pre>
$.ajax({
url: form.action,
type: 'POST',
data: $(form).serialize(),
success: function (result) {
//
},
error: function (xhr, textStatus, exceptionThrown) {
//
}
});
</pre>
Locally it is working fine, but in a production server (windows 2012 server with IIS 8), it is returng a Bad Request Error. With Firebug I checked that my hidden value is like this:
hdnArr=%5B%7B%22Type%22%3A%22%22%2C%22TypeB%22%3A%22%22%2C%22TypeC%22%3A%22%22%2C%22TypeD%22%3A%22%22%7D%5D
This problem is basically the % character. How can I enable my server to accept this char?
Ok, I could solve this problem just switching the Managed Pipeline from App Pool to Classic Mode.

Resources