Web.API Deploy URLs not working? - asp.net-web-api

In my Web.API project, for development in the web settings I use the 'Project Url:' of http://localhost/reporter on my local IIS web server. There are pages that are served up from this site using asp.net mvc4 with javascript calls that post to urls like 'api/getdata/'.
For some reason, these have stopped working- for example, I would make a jQuery post to 'api/getdata' and the full URL was http://localhost/reporter/api/getdata which was correct. And life was good.
But now something has changed- same jQuery post, nothing else in code different that I'm aware of, but my full URL's are now http://localhost/api/getdata - I lost that 'reporter' part. I think something may have happened when I deployed this to another internal server- it worked great locally- then I deployed and noticed it didn't work on the new server. And then I discovered that I wasn't working locally anymore.
I've double checked and my project config seems to be the same as it was before...?
I'm sure I broke something, but I have no idea what. Thoughts?

First, I recommend using a tool such as Fiddler or your web browser's development tools to do a network trace and see what the failed request is.
The most likely culprit seems to me to be that the virtual directory is different, or perhaps the browser's URL is different, and that causes the relative path to be resolved incorrectly. Relative paths are generally a very bad thing to use on the client because the client often doesn't know relative to what the URL is.
I recommend adding just a bit of client side code like this:
<script>
var baseUrl = '#Url.Content("~/")';
</script>
And that will declare a JavaScript variable that contains the "root" of the app. Then, elsewhere in the page, you can have code that uses the base URL and appends the rest of the relative path:
<script>
$.ajax(...., baseUrl + "api/getdata", ...);
</script>

Related

Google Chart API over SSL

Ok so since I applied an SSL Cert to our site the graphs in the dashboard have stopped working. i read this site
EDIT: forgot to add, im trying to get this working in the magento dashboard.
http://www.phpro.be/blog/detail/magento-dashboard-charts-not-working
which states to add "true" to the GetChartUrl() function within
app/design/adminhtml/default/default/template/dashboard/graph.phtml
this works on a site not using SSL.
I then found this site
http://webguru.org/2009/11/09/php/how-to-use-google-charts-api-in-your-secure-https-webpage/comment-page-1/#comment-988
but this supposedly opens up opportunity for SQL injection and other malicious attacks.
next I found this site
http://store.ivvy.ru/blog/chartssl/
and followed the instructions but still the charts aren't working.
i tried changing
const API_URL='http://chart.apis.google.com/chart';
to both
const API_URL='//chart.apis.google.com/chart';
const API_URL='https://chart.apis.google.com/chart';
but neither worked.
Can anyone point me to any other examples / explanations, or explain how to get this working?
Many Thanks
Do you use Firebug or another browser debug tool? If so, what is the error on the Console tab when you load the page containing the charts. I can tell you now, it's most likely due to trying to load a HTTP JS script over an HTTPS connection...which will fail.
Try using their latest API URL which supports HTTPS:
https://chart.googleapis.com/chart

AppRelativeCurrentExecutionFilePath is always set to ~/ for all ASP.NET Web API paths

Currently, we are adding asp-net web api support to an asp.net application. However when using any path to request an action on the controller, AppRelativeCurrentExecutionFilePath is always set to "~/" and results in 400 error. Used the route debugger available here confirmed that AppRelativeCurrentExecutionFilePath is always incorrect no matter what the url is.
For e.g. all of below url accesses, has AppRelativeCurrentExecutionFilePath as "~/"
http://localhost:1521/Testclient/apitest/values/get
http://localhost:1521/Testclient/apitest/values/get/1
Route debugger also shows failed/no match for above urls even though route table has required entries.
Have disabled all Application_BeginRequest/VPP/module/http handlers and anything that can cause routing to be impacted but still getting into same issue. Any other possible ways this can be debugged?
Update1: Checked the application.Request.AppRelativeCurrentExecutionFilePath by handling Application_BeginRequest( ) in global.asax, even there it appears to be wrong.
Seems to have found the issue, site had a "." in the name and for some reason asp.net does not like it. Root path that caused the issue was
http://localhost:1521/Test.client/apitest/values/get
http://localhost:1521/Test.client/apitest/values/get/1
Note the "Test.Client", changed it to "TestClient" and all worked as expected. When i copied the link from the test machine, had changed it and overlooked it. This should save somebody few hours if they hit this problem. Still not sure if this is a bug!?

500 error when integrating multiple apps in one code base

I'm trying to set up an MVC application that will service several facebook applications for various clients. With help from Prabir's blog post I was able to set this up with v5.2.1 and it is working well, with one exception.
At first, I had only set up two "clients", one called DemoStore and the first client, ClientA. The application determines what client content and facebook settings to use based on the url. example canvasUrl: http://my_domain.com/client_name/
This works for ClientA, but for some reason when I try any DemoStore routes I get a 500 error. The error page points to an issue with the web.config.
Config Error:
Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'facebookredirect.axd'
I am able to add additional clients with no problem, and changing DemoStore to something like "demo" while using the same facebook application settings works fine also.
Working calls:
http:// localhost:2888/ClientA/
http:// localhost:2888/ClientB/
http:// localhost:2888/Demo/
Failing call:
http:// localhost:2888/DemoStore/
I was thinking this might be an MVC issue, but the Config Error points to the facebookredirect handler. Why would the SDK try to add this value to the config during runtime, and only for this specific client?
Any insight would be greatly appreciated.
I managed to figure out what went wrong here. Silly mistake..
After I had set up the application routes to require the client_name I changed the Project Url in the project properties to point to demostore by default. When I hit ctrl+S a dialog popped up that I promptly entered through without reading.
When I changed the Project Url, IIS Express created a new virtual directory for the project. This was the source of my problem. Why? I'm not sure, but once I removed the second site from my applicationhost.config I was able to access the DemoStore routes.
Moral of the story: read the VS dialog messages!

Ajax call from local html page in Webkit Qt

I'm trying to perform an Ajax/XMLHTTPrequest from within a local HTML file in QT 4.7RC QWebview. It consistently fails with an empty responseText and status 0. I've set the follwing
page->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true);
but it has no effect (I can load remote images without problems though).
It seems to be a known issue and I'm not sure if there is a solution already.
https://bugs.webkit.org/show_bug.cgi?id=31875
Any ideas for a workaround would be very helpful. Basically what I'm trying to do is running a HTML/Javascript WebApp in QWebview that talks to a local server at 127.0.0.0 and this problem is kind of a show-stopper. Interestingly, the actual query is sent and my server responds with 200 and the requested data. But the response never arrives in my Javascript callbacks.
Not sure about your question but are you sure that you are inside an AJAX security sandbox that works with webkit? In Firefox, IE and others using AJAXin different domains does not work. In fact, http://demo1.demo.com is different than demo2.demo.com

Allowing Cross domain ajax calls from firefox

I want to change the settings of firefox so as to allow it to make cross domain ajax calls. Since due to the security feature of the firefox it doen't allow ajax calls to be made. I know if it is in same domain it will allow. I have a code given bellow which in safari works fine but firefox doesn't display the results when it calls csce server then since the code is on local machine doesn't allow it and returns error. I know it will start working if I load my this code to csce server but I want to run the code from my machine. So can anyone help me in resolving this. I have spent past couple of days just searching for this solution.
Kindly suggest how to achieve this or should I go with some older version of firefox?
I googled and set the parameters of browser in config file as specified in this site but it still doesn't work.
http://code.google.com/p/httpfox/issues/detail?id=20
Maybe you could use privoxy and tell it to inject something like "Access-Control-Allow-Origin: *" in the server response.
To do this, you would have to go into the file user.filter (create it if it doesn't exist) in privoxys configuration directory and insert something like this:
SERVER-HEADER-FILTER: allow-crossdomain
s|Server: .*|Access-Control-Allow-Origin: *|
Instead of Server, you can also use any other header that's always present and you don't need.
And this into user.action:
{+server-header-filter{allow-crossdomain}}
csce.unl.edu
Note: I didn't test it.
https://developer.mozilla.org/En/HTTP_access_control
http://config.privoxy.org/user-manual/
This appears to enable XSS from file:// pages in Firefox 4, although it prompts you so might not be suitable for more than simple test pages:
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

Resources