WebAPI for web forms producing 404 on site with SSL - asp.net

I have not used the WebAPI for Web forms before but have inherited code that uses the WebAPI, so I apologise if this is a stupid question.
From the research I have undertaken today our setup seems fairly basic...
Route Table definition in global.asax
A Controller class that inherits from the ApiController
Ajax calls via jQuery
This all works fine locally and on product sites that do not have SSL certificates. However, the site has an SSL the ajax call produces a 404.
Any help would be greatly appreciated.
Thank You!
Rich

This worked for me:
Go to: IIS -> [your site] -> Handler Mappings
You need to make sure there is a Handler mapped to a path your web service is using, i.e. " */api/* ". In my project there was an existing handler called "Static File" with such a path. It used the StaticFileModule, DefaultDocumentModule, and DirectoryListingModule.
Under "Request Restrictions" set the rules that apply to your project. My settings:
Mapping
- Check "Invoke handler only if request is mapped to:"
- Mark "File or folder"
Verbs
- "All Verbs"
Access
- "Script" (default)
More info about Request Restrictions:
http://technet.microsoft.com/en-us/library/cc730969(v=ws.10).aspx
These settings can most likely be set in your site's Web.config. I'll post my findings when I get that working.

Related

ASP.Net MVC – Resource Cannot be found error - at first time

Good day!
I'm writing a very simple asp mvc 4 app which is a simple static site.
When i send a request from the site to app - I get the following error on my first attempt:
The resource cannot be found.
Description: HTTP 404. The resource you are looking for
(or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /EmailSendApp/login.aspx
On my second attempt, i click "send" and my app works well!
Why is it not working the first time?
Thank you!
It is Intranet site and i use Windows authorization.
It is ASP MVC application with Windows authorization.
In MVC application we cannot write .aspx extension in browser url.In mvc application viewpage extension is .cshtml so please remove .aspx extension in browser url.
Your requested url could be like this http:localhost/EmailSendApp/login
so your request is sent to login method which is present in EmailSendApp controller

MVC3: Route with same name as directory

I have an ASP.NET MVC Route URL set to "/Services" which points to a controller action, but there is also a directory that contains my C# Services classes called "Services" which users cannot navigate to. This is causing issues with my route. It throws the following error:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Does anyone know how to overcome this?
Thank you
You would probably be best to not have this sort of clash but you can disable that feature by setting the RouteExistingFiles property on RouteCollection.

HTTP 405 on Error on HTTP POST IIS ASP .NET

I'm working on a web application that is referenced from another, external application. The external application tries to do a POST on the vdir when opening. At this point, I get an HTTP 405 Error:
HTTP Error 405 - The HTTP verb used to access this page is not allowed.
Internet Information Services (IIS)
I checked the IIS event logs and I see that the external application tries to post, but I can't change permissions for a directory, since I need an extension.
Any ideas?
Make sure you are including the web page file name in the post URL (http://yoursite/app/Page.aspx instead of http://yoursite/app)
You may need to explicitly allow POSTs to the file type of your web page. See here for instructions of how to do it in IIS. (Those instructions are for IIS 6. For IIS 7 simply go to Handler Mappings, click Edit for the appropriate entry, click the Request Restrictions button, then go to the Verbs tab.)
Do you have a default document in the virtual directory that you are posting to? IIS will not allow POST commands to a folder, but it should still map the virtual directory to the default document. Also try removing the trailing slash.
http://forums.iis.net/t/1171316.aspx

Url rewriting with asp.net. is there a configuration needed?

I'm trying to enable rewrited urls in my project.
it's very good described in this post: urlrewriting by scottgu
It works very well when im running it on localhost, but as soon as i upload it to my host (.net 3.5), it doesn't work! i always get redirected to a 404 page!
Is there a configuration needed to enable this?
as scottgu says no, but i don't find out why it's not working...
thanks
// UPDATE 2.09.2010
Is there actually a way to enable routing or rewriting without having iis7 or the ability to install a modul like ISAPI Rewrite on the server?
Looks like i got a bad asp.net host...
In your localhost environment you are probably running the website on your ASP.NET Development server. That server is set up to capture all request (* . *) and run them through the ASP.NET pipeline.
II6 on the other hand, is configured to only send some requests ( ie *.aspx, *.asmx, *.ashx) through the ASP.NET pipeline. So if you are trying to catch a request for an url like "/my/fine/url" that will never be passed to the ASP.NET handler, and thus not rewritten.
You can change this configuration in the Application configuration for the website:
Open IIS Manager and right-click on the website, choose Properties
On the tab "Home Directory", click "Configuration..." button.
Click "Insert..." button to insert a Wildcard application map.
In "Executable:" insert path to aspnet_isapi.dll, in my case C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll (note: this path may differ on you server).
Remember to uncheck "Verify that file Exists"
Click OK!
And so! All your requests should now be directed to the ASP.NET handler and hence caught in your URL rewriter, regardless of extension.
But I must admit that I'm a bit unsure as to how this will affect performance on you site, routing all requests for static files, css, images etc through the ASP.NET handler. Maybe someone else out there has something to say about that.
/Dennis :-)
There are two ways to get the extensionless routes in IIS6:
a) ISAPI rewrite or other ISAPI url rewriter
b) Use a wildcard mapping to aspnet_isapi.dll
See this blog post for detailed instructions.
Here is example how to use new System.Web.Routing within ASP.NET WebForms.
http://deepumi.wordpress.com/2010/02/27/url-routing-in-asp-net-web-forms/

ASP.NET/IIS: 404 for all file types

I set up 404 handler page in web.config, but it works ONLY when extension of URL is .aspx (or other which is handled by ASP.NET).
I know I can setup static HTML page in website options, but I want to have a page.
Is there any options to assign ASPX handler page for all request extensions in IIS?
The direct question was whether or not there are options to assign the ASPX handler to all request extensions: Yes, there is. I'll discuss how to do that shortly.
First, I think the "hidden" question -- the answer you really want -- is whether or not there's a way to redirect all 404 errors for pages other than ASPX, ASMX, etc. Yes, there is, and this is the better choice if it'll solve the issue you're having.
To redirect all 404s in IIS 6, right click your web application root (whether it be its own site or a virtual directory in the main site), and choose "Properties." From there, choose the "Custom Errors" tab. Find 404 in the list and change it to the redirect you want.
Now, if that won't suffice -- and I really hope it does -- yes, you can run every page through the ASPX handler. However, doing so comes at a fairly high cost in terms of efficiency -- raw HTML/image serving is considerably faster than anything dynamic.
To do this, right click your web application root and choose "Properties." Choose the "Home Directory" tab. Click "Configuration;" a new window will pop up. Copy the path from one of the ASP.NET page serves, and then use it for a wildcard application map.
Bear in mind, again, this is the wrong answer most of the time. It will negatively impact your performance, and is the equivalent of using a chainsaw to carve a turkey. I highly recommend the first option over this one, if it will work out for you.
For information:
This is one of the several nice things that IIS7 brings - all pages are routed through the handler such that you can do custom 404s and - usefully - directory and file level security for any file (based on the same web.config stuff as for asp.net files prior to IIS7).
So notionally "use II7" is an answer (will be "the" answer in time) - but of course its not a terribly practical one if you're not hosting/being hosted on W2k8 (or higher).
The web.config can only set up errors pages for pages controlled by it's web site. If you have any other pages outside the purview of the ASP.Net application, then you set up handling for them in IIS. There's an option in there for configuring the 404 page where you can point it to your custom page.
Only other thing i can think of is passing ALL extensions to asp.net.
This way all types of files get processed by asp.net and your custom error page will work.
In the IIS application configuration, you can set a wildcard mapping (".*") to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
You can setup wild card mapping in IIS (Application configuration/Mappings/Wildcard mappings/ - just set aspnet_isapi.dll as executable and uncheck the Verify that file exists box) that will route all incoming requests to your app - so you can control the behavior directly from it.
You don't have to setup static page in your IIS application settings. Imho, you should be able to setup valid url (e.g. /error_handler.aspx) from your app that will be used as landing page in case of specific server error.
In IIS you can set a Custom Error for 404 errors and direct it to a URL in the site properties.
It shows a static html by default
C:\WINDOWS\help\iisHelp\common\404b.htm
You can change it to a relative url on your site.

Resources