PDA

View Full Version : IIS7 + .NET MVC3 + Sencha Touch Issue



Riaz
17 Apr 2011, 4:59 PM
I am working on project using ASP.NET MVC3 and Sencha Touch. When I run locally, it is working fine.
However, In IIS7, database is not loading. Anybody can help me?

“Global.asax.cs”


public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

}





“Index.chtml”


@{
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<title>ABC Project</title>

<!-- CSS - Sencha Touch 1.1.0 -->
<link href="@Url.Content("~/Content/sencha-touch.css")" rel="stylesheet" type="text/css" />



<!-- JS - Sencha Touch 1.1.0-->
<script src="@Url.Content("~/Scripts/sencha-touch-debug.js")" type="text/javascript"></script>



@* SECTION-Project tab*@
<script src="@Url.Content("~/ScriptsForViews/jsProjectList.js")" type="text/javascript"></script>


@* SECTION-1*@
<script src="@Url.Content("~/ScriptsForViews/jsMainFrame.js")" type="text/javascript"></script>

</head>
<body>

</body>
</html>




“ProjectController.cs”


public ActionResult Projects()
{
{
:
return Json(new { data = items }, JsonRequestBehavior.AllowGet);

}



“jsProjectList.js”


var ProjectStore = new Ext.data.JsonStore({
model: 'Project',
sorters: 'ProjectStatus',

getGroupString: function (record) {
return record.get('ProjectStatus');
},
proxy: {
type: 'ajax',
url: '/Project/Projects', //Any problem here???????????????


reader: {type: 'json', root: 'data' },
actionMethods: { read: 'POST' }
}
//,
//autoLoad: true

});



Frame is loading, but not loading json data.

Riaz
17 Apr 2011, 10:39 PM
Very frustration situation.

Riaz
18 Apr 2011, 12:47 PM
Any idea will be appreciated.

Bucs
18 Apr 2011, 2:20 PM
Why don't YOU give us some ideas on what errors are being reported. Does Chrome Inspector show any errors? Are you able to hit the Projects method if you set a breakpoint on it? You need to give more detail about what's going on before you can expect any worthy help. And you might want to ask a little nicer than you did for help, rather than just demand it :)

For starters, have you tried to remove the initial "/" on url:

'/Project/Projects', //Any problem here???????????????

But you need to get your debugging environment setup and working first so you know where to start looking.

Riaz
18 Apr 2011, 3:04 PM
At last, I got one respond from you. Many thanks "Bucs" for your suggestions.

When I run locally, it is working fine.
However, In IIS7, it is showing error that -"Uncaught TypeError: Cannot read property 'length' of undefined"

According your suggestion, I have remove, initial "/", it is working fine locally again.
However, When I publish, it is sowing that database is loading ................

Could you identify, why it is happening?

Bucs
18 Apr 2011, 3:16 PM
That typically means you are not getting anything back from the method call and so the reader is failing. When working with MVC and IIS7, I would suggest you do not use Personal Web Server (Cassini) if possible but rather the MVC properties tab and setup the application to run against your local IIS machine which will be more closely aligned with your production environment. I would set that up and then set a breakpoint on the server call to see if you are even getting to the server. My guess is that you are not. And when I make my calls to the IIS server MVC project, I do not include the "/" before the controller name. So your call should look like this if you switch the project over to IIS7 locally:



proxy: {
type: 'ajax',
url: 'Project/Projects',


Again, set a breakpoint on the controller to make sure that you are even getting there.

Riaz
18 Apr 2011, 4:40 PM
Thanks for your nice advice.

I also think, your guess is correct but I do not know how to fix it.

I have set a breakpoint on the controller, the event is respond correctly during debug mode.

Do you think it is the issue of IIS7 with Sencha Touch?

Bucs
18 Apr 2011, 5:26 PM
I use IIS7 with Touch all day long, everyday...so there is nothing wrong with that. The problem is either a problem with the server call, the server method not returning what you think it's returning (error or invalid JSON), or you are having a problem after the the result is returned, like with the reader not properly reading the JSON data.

If the event is responding to the client call, then you have eliminated the first problem. Next, you need to put a break point on on your returned JSON to ensure that it is returning what you think it is:



public ActionResult Projects()
{

// Breakpoint this line and test the items collection
return Json(new { data = items }, JsonRequestBehavior.AllowGet);

}


Lastly, the AJAX calls expect the root object to tell whether the operation was a success, so you may be returning the proper JSON but the method is not not marked as success so it could be processed as a failure.

Try doing this:


public ActionResult Projects()
{

// Breakpoint this line and test the items collection
return Json(new { success = true, data = items }, JsonRequestBehavior.AllowGet);

}

Riaz
18 Apr 2011, 7:32 PM
Hi Bucs,

I am grateful to you for giving me your valuable time. Still I am not getting what I am doing wrong.

I want to send my sample project if you permit me.

Riaz
19 Apr 2011, 3:14 PM
The following code is working on IIS7




Ext.regModel('Contact', {
fields: ['firstName', 'lastName']
});

var mystore = new Ext.data.JsonStore({
model: 'Contact',
sorters: 'lastName',

getGroupString: function (record) {
return record.get('lastName')[0];
},

data: [
{ firstName: 'Tommy', lastName: 'Maintz' },
{ firstName: 'Rob', lastName: 'Dougan' },
{ firstName: 'Ed', lastName: 'Spencer' },
{ firstName: 'Jamie', lastName: 'Avins' },
{ firstName: 'Aaron', lastName: 'Conran' },
{ firstName: 'Dave', lastName: 'Kaneda' },
{ firstName: 'Michael', lastName: 'Mullany' },
{ firstName: 'Abraham', lastName: 'Elias' },
{ firstName: 'Jay', lastName: 'Robinson' }
]
});


Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function () {

var list = new Ext.List({
fullscreen: true,
itemTpl: '{firstName} {lastName}',
grouped: true,
store: mystore

});
list.show();

} //[End- onReady function]

}); //[End- Ext.setup]






But, bellow code is not working on IIS7.


Ext.regModel('Project', {
fields: ['ProjectNumber', 'ProjectName', 'ProjectStatus', 'Manager', 'OfficeName', 'LastActivityDate', 'Address1', 'Address2', 'Town', 'State', 'PostCode', 'Country']
});


var ProjectStore = new Ext.data.JsonStore({
//var ProjectStore = new Ext.data.Store({
model: 'Project',
sorters: 'ProjectStatus',

getGroupString: function (record) {
return record.get('ProjectStatus');
},
proxy: {
type: 'ajax',
url: 'Home/Projects',
reader: { type: 'json', root: 'data'}//,
// actionMethods: { read: 'POST' }
}
//,
//autoLoad: true
//riazTest
, listeners: {
render: function () { alert('data is rented'); },
datachanged: function (response) {
alert('riazTest');
},
exception: function () { alert('HTTP error occured'); }

}

//~riazTest
});



Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function () {

var list = new Ext.List({
fullscreen: true,
id: 'idProjectlist',
itemTpl: '{ProjectNumber} {ProjectName}',
grouped: true,
store: ProjectStore,

listeners: {
render: function () {
ProjectStore.load();
}

}
});
list.show();

} //[End- onReady function]

}); //[End- Ext.setup]



From my test, I understood that URL is unable to load json page during IIS7.

Still searching how do I fix it?

Riaz
20 Apr 2011, 1:03 PM
Could you please inform me where do I get help to slove the above issue?

Bucs
20 Apr 2011, 2:10 PM
You haven't posted all the pieces to your issue so it's hard to know the whole picture to help. What does your controller look like, what errors are you getting, are you using the debuggers in both IIS and in the browser Chrome (Developer Tools / Scripts / setting break points) etc. etc. You cannot just say "it doesn't work", you need to research the problem with the debuggers and then post more specific code examples and errors messages to get the proper help. Remember, this is a user forum so no one is obligated to help...and that can be VERY frustrating, trust me, I know. But you're more likely to get help quickly if you post examples AND specific error messages.

If I were you, you need to really study the examples that come with the down load, and study the API docs on Data, Model, Proxy, etc and ensure that you are doing things the right way. It sucks when you're new, but it's really the only way to figure out how all the pieces fit together and where to look when things go wrong.

I would also suggest that you strip down your request for project info into the smallest unit, maybe just one string field and get that working...then move on. As far as I can tell, if you are getting all the way through to the controller return value, and know that it is returning the proper JSON, then your problem is more than like the setup of your JSON reader.

Try something like this for your store object instead of what you have:



var ProjectStore = new Ext.data.Store({
model: 'Project',
autoLoad: true
proxy: {
type: 'ajax',
url: 'Home/Projects',
extraParams: {
// yourParam1: 'test'
},
reader: {
type: 'json',
root: 'data' // <== note: this is important and depends on how your returned JSON is organized. Make sure you are returning an object that has a data property set to the array of JSON Project objects you are attempting to read. If you are returning an object array of all your Project objects, then you do not need this property. Typically you'll want to return an object that has at least a success property and a data property that contains your JSON array of objects to read.
}
},
listeners: {
scope: this,
beforeload: function (store, op) {
// put code here to check things before the load is fired
},
load: function (store, recs, success) {
// Get data object that holds returned JSON
var jsonResult = store.proxy.reader.jsonData;

// Check for errors and display if needed
if (!jsonResult.success) {
// Note: You need to set the success property on your returned object depending on the result of the method call
}

}
}
}),

Riaz
20 Apr 2011, 3:47 PM
Thanks Bucs for your time. At last I solve my problem. Many thanks for good suggestions

all4gsus
22 Apr 2011, 6:17 AM
runAllManagedModulesForAllRequests in <system.webServer>

I had (possibly) the same problem. For some reason it seems that the defaults for this setting are different when running "locally" or in the 'Default" web site of IIS7. You can do a Google on it to find more about it. And you don't necessarily have to enable all routes, but you just have to know which ones to enable.



<system.webServer><modules runAllManagedModulesForAllRequests="true" /></system.webServer>