I have a basic WebAPI OData application that seems to refuse to route requests to my controller if the parameter has a '.' in it.
For example:
http://localhost.com/vroot/odata/foo('abc') <== routes correctly
http://localhost.com/vroot/odata/foo('a.bc') <== returns a 404 error
I get the same 404 error even if I replace the '.' with a %2E.
http://localhost.com/vroot/odata/foo('a%2Ebc') <== returns a 404 error
Is this a generally understood problem in WebAPI OData?
Any ideas on what might be going on (or possibly how to work around this ?)
Dots in request urls are interpreted differently by IIS, so try adding the following setting in web.config:
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
(From here: http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html )
Some posts related to your issue:
Dots in URL causes 404 with ASP.NET mvc and IIS
Related
I have a simple objective; I just want -every- single 404 error to redirect to a Single-Page Application for the SPA to handle routing.
This seems to work for routes that could possibly exist within the ASP.NET app (based on existing Controllers). However, if I navigate to a route that couldn't not possibly have been an ASP.NET route (which is happening, as some routes only exist client-side in the Vue app), it seems like IIS is immediately taking charge of the request and issuing this simple text/html response:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
The response is issued almost immediately from receipt of the request, which seems to indicate it is being immediately handled as a 404 by IIS before any .NET managed handlers touch it.
How do I stop IIS from doing this?
Additional Info:
ASP.NET Web.config error fallback is already in place:
<system.webServer>
<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/vue-fallback.html" responseMode="File" />
</httpErrors>
</system.webServer>
This is an ASP.NET MVC Server; System.Web.Mvc v4.0.0.0.
IIS Version: IIS 8
ETA:
I ran the server locally (not sure why I didn't do this sooner), the exact error seems to be a failure in the StaticFile handler.
HTTP Error 404.0 - Not Found
...
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
This seems to solve my issue:
routes.MapRoute(
"Vue-Fallback",
"{*catchall}",
new { controller = "Home", action = "VueFallback" }
);
I'm trying to set up a stripped down web server that passes all URL requests through to a single IHttpHandler, instead of trying to match the URL to the file structure of the server.
I've got the IHttpHandler in there, along with some custom modules, and they're responding as expected when I go directly to my domain, but if I access the site via something like:
http://mysite/some/random/url
I get a 404 file not found error.
I'd assumed removing one of these modules would probably cover it:
<remove name="UrlRoutingModule-4.0" />
<remove name="UrlMappingsModule" />
<remove name="FileAuthorization" />
<remove name="UrlAuthorization" />
But IIS is still trying to match the URLs to the server file structure. I've since removed every module I'm not using and it's still returning 404's.
I have actually done this before, but I can't seem to quite remember or find online quite how I got it working.
I'm now basically out of ideas - anyone?
I added the runAllManagedModulesForAllRequests as per the suggestion from #Alexei Levenkov. While I remember definitely needing to do that, it didn't immediately solve it. After much fiddling about I found that IIS had set:
resourceType="Either"
on the handler. I tested changing it to File, and the problem was fixed for file type URLs, but of course not folder "style" ones. Changing it to:
resourceType="Unspecified"
Fixed the problem for all URLs.
I having a issue when i click to edit a user with this url in a ASP.NET MVC 3 project:
http://domain.com:8089/User/EditUser/username.surname?IDUser=e11a621p-df11-4687-9903-8bfc33c922cf
If i get another user without the '.' character, it works fine.
The error:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
I tried some tips that i find here, like:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
and:
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true" />
and this attribute on the edituser action:
[ValidateInput(false)]
But nothing seems to work. This site is hosted on a IIS server, when it was on Windows Azure WebSite, it was working as expected.
Thanks.
If you know for a fact that the edit page is the only page where you use the firstname.lastname url part, you can use the method described in this SO answer:
Prevent static file handler from intercepting filename-like URL
Specifically, in your case, adding the following web.config section should route the request to MVC:
<system.webServer>
...
<handlers>
...
<add
name="userEditPage"
path="User/EditUser/*"
verb="GET"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
This will not be sufficient if you use the firstname.lastname in urls outside of the User/EditUser/... path, and is not a general solution. That would be much more complicated because you would need to tell IIS something like the following:
1) if the file exists, serve it (so that your .js files still serve properly)
2) Before any of the other handlers execute for the file extension, run the MVC handler and see if there is a route matching the url. Because what if you have a user of last name html?
3) If the MVC handler does not match any routes for the url, let the other handlers. Because what if you also had an .aspx page in your project?
Lastly, for the general case, you may want to consider the edge case of someone malicious creating a user with first name ../../web and lastname config? Just a thought, but it seems like the best you can hope for is restricting the use of the . in the url to specific paths.
After some headache, i publish it to Azure WebSites again and it works normally, with same web.config file that i was using in local enviroment. So the solution must be on the IIS, then after no more tries, i change the Application Pool to Default App Pool and guess what, it worked.
I am trying to get Swagger to work with ServiceStack. The web server is located behind a Firewall and accessed from the Internet (my.domain.de:80). Requests are then forwarded to the web server on Port 8070.
When visiting the swagger page it is able to access /api/resources and retrieve the List of ServiceMethods, but then fails to retrieve the List of Operations.
When I use fiddler to inspect the result I see that he /api is missing so that swagger tries to get the List of Operations from /resources/ServiceName instead of /api/resources/ServiceName.
The Swagger-UI gives me the following error message:
Unable to read api 'ServiceName' from path http://my.domain.de/resource/ServiceName (server returned Not Found)
SwaggerConfig:
discoveryUrl:"../../api/resources",
ServiceStack Config:
WebHostUrl = "http://my.domain.de"
Update(2)
If I dont set the WebHostUrl the BasePath in the initial response from ServiceStacks resources service contains the portnumber from the webserver basePath=http://my.domain.de:8060/api. But on the Firewall this port is not reachable, nor do we want it to be reachable.
web.config:
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>
Update
in the Inital response the basepath is:
basePath=http://my.domain.de
and by my.domain.de I mean a real world url which is just the hostname without port, url-path, querystring or fragment (I acctually checked wikipedia for the correct names ;)
I have found this other question on StackOverflow, but it did not help me.
Swagger with Service Stack not working
How can I get ServiceStack/Resources Service to either add /api for its returned ServiceList?
Colleague of op here.
I spent some time researching this problem and I believe the issue is a bug in ServiceStack's swagger support.
See here:
https://github.com/ServiceStack/ServiceStack/pull/800
Quote:"When set, use webhosturl for base url in swagger and metadata links"
It is implemented correctly for metadata, but not for swagger.
Line 52 in SwaggerResourcesService.cs overrides the baseurl with the WebHostUrl if it is set, but does not combine with the real path as the implementation in metadata does:
https://github.com/sneal/ServiceStack/blob/6b33f5c2417587b5983c611b4bf8a5d42d88d890/src/ServiceStack.Api.Swagger/SwaggerResourcesService.cs
Assume I have a working Method in a Controller. Pseudo code could be:
public IEnumerable<ViewMP3> MyMP3(string token, string id)
{
using (ControlDbContext db = new MyDbContext())
{ List<ViewMP3> list = ...some list linq statement
return list;
}}
I consume the WebAPI using HttpClient and no error is produced.
Now, suppose I throw an error on purpose:
throw new ArgumentException("hello"); //inserted in method above
How can I get a real detailed error message. All I can get is IIS 7.5 Detailed Error - 500.0 - Internal Server Error. Note: not to confuse the issue, I pass the error output of the WebAPI service back to the client in a string. The error is originating inside the service but will only produce the 500.0 error. Normally JSON is returned but when a known error condition is set, I change my code to grab the response in a string format and pass on to the client. That is how I know what the error contains.
I have tried enabling "Send Errors to Browser". I have changed IIS Error Pages Feature Settings to Detailed Errors. I have changed Web.Config to include
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0" />
and
<httpErrors errorMode="Detailed">
<remove statusCode="500" subStatusCode="-1" />
</httpErrors> .
I have granted IIS_IUSRS rights to the folder with the web files.
I had a real error earlier in the day that was nearly impossible to troubleshoot because of the generic 500.0 error. Any idea what else I could do to get detailed error messages?
Thanks!