Web API URL from a asp.net website - asp.net

I have a hyperlink in a Web Forms project and it's href is set to a web api call.
http://www.domain1.com/form.aspx has
Test
"houston" is the parameter.
I get a 404 error when I click on the link. When I debug my Web API 2 application using the link above, everything works fine. But the Web forms application cannot seem to find it. I have also tried:
Test
I have even tried:
Test
My project on "domain2" is in MVC Web API 2. What am I doing wrong? I'm missing something.
I'm not getting any data back in return or waiting for any event. It simply opens in a new tab and only needs the parameter and returns nothing back to the calling page. Is it a routing issue? TIA!

In this case, the route worked fine. The compiled dll was missing from the server, which is why it worked locally but when called from another website, the 404 error popped up. Once I copied the dll to the right folder on the server, everything worked fine.

Related

Implementing Google Calendar API to get a list of events in ASP.NET core

I followed the tutorial here, except that I implemented it in a web app, and everything works fine in localhost, when I call the API to get calendar events for a give date, I get the events list back. However when I deploy to my test site I get a 502 Bad Gateway response, making the same call as in localhost.
Has anybody experienced the same? How to fix it?
If it works on localhost and not on deployment, it just means there are configurations which haven't been met. Check this Web applications (ASP.NET MVC) about setting up web apps using ASP.NET.
In order to run the following code successfully, you must first add a
redirect URI to your project in the Google API Console. Since you will
use FlowMetadata and its default settings, set the redirect URI to
your_site/AuthCallback/IndexAsync.

ASP.NET WEB API 2 Works Locally But Not On Production Web Server

I've developed a new WEB API 2 that works great locally, however when I upload the same code to my production server (Arvixe in this case) all I get is a 404 when I call it. I've spent HOURS searching the web, reading forums, etc.. and have been able to find no resolution, so I'm asking here as my last effort.
I'm currently only testing with the default project that gets created when you do New Project > ASP.NET Web API 2 Empty Project in Visual Studio. This creates an empty project with a single ValuesController. You should be able the JSON response by called /api/values, but this doesn't even work.
I'm using Fiddler to test the API locally and on the web server.
http://localhost:1993/api/values <--- works great
but
http://api.mydomain.com/api/values <--- returns 404
Note: I created a subdomain "api" in this case, but everything for the code for the API is unchanged from when it was created.
Why in the world does this work locally but not on the production web server?
That the server returns 404 (Not Found) may indicate a lot of things. However you can check using the following step:
Add a simple text document like readme.txt to your a folder sub-domain http://api.mydomain.com, and try to get access to that. If you can't access to that file, it means that the subdomain is not configured properly.
Publish the webservice using the "Publish" functionality, so that all DLLs will be copied.
After that,try to reach the Web ApI again.
Hope that help.
"Note: I created a subdomain 'api' in this case, but everything for the code for the API is unchanged from when it was created."
Above comment of your's is suspicious, you should publish your WEB API application in the root directory. Like if http://example.com is pointing to "MyExample" folder, then application should be published on "MyExample" folder.
After that you will be able access your api with http://example.com/api/{controller}/{action}
Just a simple suggestion which I'm sure you have already considered, but have you opened the http port 80 on the server's firewall?
Also stick a plain old html file in the root of your project and see if the server serves it up.
in your case, since you create a subdomain of 'api', you should try
http://api.mydomain.com/api/api/values
note that if you're using database for the function, you should change the connectionString in your web config
Please verify the .net framework on you hosted domain that may be old one.
Web api 2 is supposed on 4.5 framework.
One reason for web api 2 method working OK on local machine but not on production server is that the method you are calling is working on local machine but not on remote server. In such a case you will receive message 404 or 500, and you would be lost why this routing is failing.
Why a method would fail on remote server, well there may be many reasons. For me, I was querying database in my method and my connectionString was not set for remote server.
One way of resolving it would be to put some very simple code in that particular method and test that routing is working. Then check your original code for errors reasons.

How to make Asp.Net ignore my physical directory?

I'm creating my first FubuMVC application. I've got a physical folder Demo and a route that should handle the "/demo" url. For some reason, when I try to debug it in Visual Studio, it issues a permanent redirect to "/demo/", and then returns HTTP Error 404.20 - Not Found (No default document). When I route the same action to /demostuff, everything works just fine. I noticed that my application startup scripts are fired on the first request, but it's somehow not routed to Fubu's HttpHandler.
I'm using IIS Express.

ASP.Net MVC Controller causing Not Found error when deployed to IIS 7

I am developing a website using ASP.Net MVC. I have a method in the Home controller which returns a partial view when called. The issue is when I am calling the controller method using jQuery, I get a 404 Not Found error.
This only happens when the application is deployed on IIS 7. It works fine during development, but after deployement, none of the controller are found when called through jQuery.get method or post.
Thanking you all in advance for helping me.
I had the same problem. The simple fix for me was to do a aspnet_regiis -r
is the error an asp.net error (yellow and red) or the default iis7 html error? if its iis7 default error, make sure IIS7 has asp.net installed, that caught me out when i first started working with it. (programs and features and add windows components and make sure asp.net is selected under IIS)
Actually, the website is running, I can navigate among pages, only if there is a call through jQuery.get or post methods, then the error occurs. I guess, there is an issue with ISS 7 regarding recognizing that its a controller method. The error text is given below.
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable .
Thanks.
Make sure you have ASP.NET MVC installed and running. Also, make sure that your application is installed properly with appropriate references.
Like Tony says above, make sure you can actually access the complete URI (controller/method) in a browser to see if it works ok.
what is the URL that the jQuery.get method is accessing?
If it does, check how you have wired your Ajax call.
Do the method in your code have the AcceptVerbs attribute defined? [AcceptVerbs(HttpVerbs.Post)]
If you are deploying your mvc app as a virtual web make sure that BOTH your virtual web and the root site has its Application Pool set as Integrated Pipeline.
If you are running ASP.NET MVC on IIS7, make sure you configure IIS to run in "Integrated Pipeline Mode" as opposed to "Classic". You'll have more success with routing in this mode. More here.
I had same problem.
solved issue by changing the ajax url.
Just for an example ,
if you are using ajax call to the controller:
have to write url as like this == url: '#Url.Action("actionmethod", "controller")',
instead of ===== url: '/controller/actionmethod',
Thanks

ASP.NET gone FUBAR on a production machine

Today we tried to put an ASP.NET application I helped to develop on yet another production machine. But this time we got a very weird error.
First of all, from all the ASP.NET pages, only Login.aspx was working. The rest just show a blank screen when they should have redirected to Login.aspx. The HTTP response is 200, but no content.
Even worse - when I try to enter the address of some inexistent ASPX page, I also get HTTP 200! Or, when I enter gibberish in some existing ASPX page code (which should have been accessible without login) I also get HTTP 200.
If I enter the name of some inexistent resource (like asdasd.jpg), I get the expected 404.
The redirect to login page is written manually in Global.asax. That's because the application has to use some alternate methods of authentication as well, so I can't just use Forms Authentication. I would suspect that Global.asax is failing, if not for the working Login page.
Noteworthy facts are also that this machine is both a Domain Controller and has SharePoint installed on it. Although the website in question is listed in SharePoint's exception list.
I would check the following:
Is the application within a virtual application or its own site and not just a virtual directory?
Does the application have it's own App Pool? If it does not then is the app pool shared by apps in a different .net version.
Is the .net version of the application the correct one? 1.1 or 2.0?
Do the files in the file system have the correct permissions to be accessed via IIS?
Have you performed an IIS Reset?
Create a stand alone test.aspx page within your folder that just displays the date/time and check it works.
Make this single test.aspx page perform an exception (eg. divide by zero) and see what the outcome is.
More information required.
What Op Sys?
What mode IIS running under?
What version of .Net?
What version of SharePoint?
(Why are you using your DC as a web host?)
Does it work on the other production machines you've deployed to?
If so what is different between this machine and the working ones?
Did you deploy the same way?
Are you sure your hitting the right machine?
Are you sure your hitting the right web site?
What ISAPI components are installed globally and for the web site?
Is .aspx mapped to the ASP.Net ISAPI filter?
Do you have any HTTP Modules or HTTP Handlers configured?
Can you change the global aspx to write out some messages so you can be sure the piece of code you interested in is reaching?
Anything coming up on the IIS log or the event logs?
Addition:
What version of .Net?
By the sounds of it the .jpg request is being dealt with by IIS directly which is why you get the 404, but the .aspx request is being dealt with by something else which except for you login page, is always returning 200.
Assuming .aspx is wired correctly to .Net the the order of processing is based on ISAPI filters (high to low then global before site), then the ASP.Net ISAPI Extension (sorry I said this was a filter earlier but it's actually an extension). Then we get into the ASP.Net pipeline based on your .Net configs, and calls the HTTP Application (which includes your global.asax code), any HTTP Modules followed finally by a HTTP Handler. Your ASP.Net web forms are just fancy HTTP Handlers.
However, the request can be responded to and terminated from any point.
Since your code works on other machines though, I'm tempted to point a finger at SharePoint if it isn't installed on the working machines. Is this SharePoint 2007? That is also an ASP.Net application (I don't think 2003 was).

Resources