Url rewriter in ASP.NET: Resource cannot be found - c#

I am using the url rewriter described here.
On production, it works great but locally, for any links that uses url rewrite, it says:
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.
Do you have any idea why?
Do I have to install IIS locally and configure something?
Some rules I use:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>/Payment/Secure/Order.htm</LookFor>
<SendTo>/Payment/Secure/Order.htm</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>/Payment/Secure/Result.htm</LookFor>
<SendTo>/Payment/Secure/Result.htm</SendTo>
</RewriterRule>
<RewriterRule>
..
They are all defined well because they work in production...
Thanks a lot!

Locally, Url rewrite only works with IIS running on localhost for your website!

Yes specify the correct path name for your web server.

Related

Cannot reach an otherwise reachable web API, with dots in URL

I have a web service deployed on IIS 8.5 (Windows Server 2012 R2) which has to be called passing four arguments. They are not optional, and are to be included directly in the URL, without a query string, as such:
.. api/myservice/argument1/argument2/argument3/argument4
If I try to call it with the URL written above, it answers and gives the expected response. However, a 404 - Not Found error is given instead when trying to use real production-like arguments as such:
api/myservice/AAAA_AAAAA.AAA_AAA_AA_AA_AAA_000000_000000_000000/333/AAA/AAA.AAA.AA.AA.AAA.000000.000000.000000
I thought the multiple dots raised the issue, so I replaced each one of them with %2E, but nothing changed.
I've searched for already answered questions: I tried this and this, to no avail.
What is the problem with that production-like URL?
Here is the code of the API:
[RoutePrefix("api/myservice")]
public class MyServiceController : ApiController
{
[HttpGet]
[Route("{argument1}/{argument2}/{argument3}/{argument4}")]
public string StartValidation(string argument1, string argument2, string argument3, string argument4)
{
// operations...
}
}
I traced the request with IIS Failed Request Tracing as suggested in an answer, but I'm not able to find a clue in the resulting log:
Can anyone help me?
Enable failed request tracing on IIS to check.
https://learn.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/tracefailedrequestslogging
Good possibility that IIS is rejecting these as part of URLScan (if enabled), but FRT will confirm.
First try to deploy it to your local Iis, if it works, means that your production can have a different configuration at the level of the IIS, or the compiled code is not the same as the one you have and you need to redeploy the api.
If the api fails at the level of your local IIS and it runs properly from the vs(if you pass any parameter with the postman) you hit a backend breakpoint, then you have a wrong configuration on your deployment on your local IIS.
If you never hit the breakpoint you have an error at the level of your code.
Hope this helps
I finally solved this. I added a piece code, provided by this answer to a quite identical question, to the web.config, but a different issue arose: it seemed IIS had to be run in "Integrated Mode". Thanks to the clue given by this answer to a question about this subsequent problem, I switched the Managed pipeline mode of the application pool where the API was deployed from Classic to Integrated, which allowed that code to work. The web API finally accepts arguments with periods.

ASP.NET and IIS and MVC - site does not open

I have a web site and when I try to view/access through IIS(Default Web Site -> Search/Run Site -> Search *:80(http)) the site open.
But when I try to open/debug using Visual Studio 2010, the following problem happens:
Server Error in '/' Application.
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: /help
If I am in home page(root "/") and I try to open any page, open the "Directory Listing"
What is happening ?
It sounds like the problem is in your routing (Route.Config). Make sure you change your routing to follow how your website is set up in IIS.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed,

I was told to work on the google api.
its pretty much the same as FB but I am having a slight trouble with redirect_url
This is the url which my app is using to get a access token
https://accounts.google.com/o/oauth2/auth?client_id=**********3-uiqulutgsobu5df302tup49v6e6ae5qu.apps.googleusercontent.com?&redirect_uri=http://localhost/Default1.aspx&scope=https://www.google.com/m8/feeds/&response_type=token
When I registered the app
I set the redirect_url to
http://localhost/Default1.aspx
In my project there is a page called Default.aspx. The name of the solution is Googleprofiles.
It gives me an error:
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: /Default1.aspx
Looks very simple. But I am unable to fix it..
Need some expert help
Thanks
Sun
Your redirect_uri is wrong, change it or rename your Default.aspx to Default1.aspx:
redirect_uri=http://localhost/Default.aspx

Parse Subdomain on localhost

The Setup
I am building an app using ASP.NET MVC3, the application makes use of sub domains, i added the following in my hosts file : 127.0.0.1 students.localhost.
This all seems fine, when i debug, the browser opens up localhost:{PORT}, i can browse the site, i can also open up: students.localhost:{PORT}, and the site works perfectly.
In case you were wondering, i made use of: Maarten Balliauw's code to achieve the routing requirements in MVC and subdomains
The Problem
I need to somehow find out what subdomain the user is accessing the site from. If i debug, my and go to my subdomain:http://students.localhost:{PORT} Request.Url is : http://localhost:{PORT}, for some reason the deubugger (or ASP.NET Development Server) is not picking up students.
Please do not go into the TLD descussion trying to explain what a subdomain really is, all i need is the first string after http://. in local and production this WILL be my subdomain.
Thanx in advance
UPDATED:
I managed to get the desired result by making use of:Request.Headers["host"], it would be interesting to find out why Request.Url does not contain the students substring.
The easy way to do this is to put a fully qualified domain name in hosts. If the production site is subdomain.domain.com, I like to use subdomain.domain.local and just map this to 127.0.0.1.
new System.Uri(Request.RawUrl).Host
I think this will be the real hostname.

How to solve HTTP status 405 "Method Not Allowed" when calling Web Services

I've got a siluation where i need to access a SOAP web service with WSE 2.0 security. I've got all the generated c# proxies (which are derived from Microsoft.Web.Services2.WebServicesClientProtocol), i'm applying the certificate but when i call a method i get an error:
System.Net.WebException : The request failed with HTTP status 405: Method Not Allowed.
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
I've done some googling and it appears that this is a server configuration issue.
However this web service is used many clients without any problem (the web service is provided by a Telecom New Zealand, so it's bound to be configured correctly. I believe it's written in Java)
Can anyone shed some light on this issue?
Ok, found what the problem was. I was trying to call a .wsdl url instead of .asmx url.
Doh!
I found this was due to WCF not being installed on IIS. The main thing is that the .svc extension has to be mapped in IIS See MSDN here. Use the ServiceModelReg tool to complete the installation. You'll always want to verify that WCF is installed and .svc is mapped in IIS anytime you get a new machine or reinstall IIS.
I had the same problem, but the details were different:
The Url we were using didn't have the file (.asmx) part. Calling the Url in a browser was OK. It also worked in a simple client setting the URL through Visual Studio.
But it didn't worked setting the Url dynamically! It gave the same 405 error.
Finally we found that adding the file part to the Web Service Url solved the problem.
Maybe a .Net framework bug?
You needto enable HTTP Activation
Go to Control Panel > Windows Features > .NET Framework 4.5 Advanced Services > WCF Services > HTTP Activation
hmm are those other clients also using C#/.NET?
Method not allowed --> could this be a REST service, instead of a SOAP web service?
MethodNotAllowedEquivalent to HTTP status 405. MethodNotAllowed indicates that the request method (POST or GET) is not allowed on the requested resource.
The problem is in your enpoint uri is not full or correct addres to wcf - .scv
Check your proxy.enpoint or wcf client.enpoint uri is correct.
In my case the problem was that the app config was incorrectly formed/called:
in config the service url was using "localhost" as domain name, but real hostname differed from the URL I called :( so I changed the "localhost" in config to domainname thah I use in URL. That`s all!

Categories