HttpModule URL Rewriting - 404 error in IIS - asp.net-mvc

I have created a very simple HttpModule that rewrites the incoming path to one that matches a route in MVC. ex.:
http://www.example.com/cars.html -> http://www.example.com/Home/Vehicles/3
To rewrite the path I simply use RewritePath on HttpContext.
The problem is that while it works in IIS Express, this doesn't seem to work in IIS. I can see that the URL is rewritten, but I get a 404. It seems to happen beacause instead of matching this rewritten route against the registered routes, the StaticFileHandler tries to handle the request.
So when http://www.example.com/cars.html is entered into the browser, on the IIS error page, I see the Requested URL:
http://www.example.com/Home/Vehicles/3
which is correct, but I will also see that it tries to load a physical path: X:\Project\Site\Home\Vehicles\3.
If I enter the rewritten path into the browser, the page is loaded and works as expected, so the routes are ok.
Any ideas how could I rewrite the path from my HttpModule so that the rewritten path is than matched against the registered routes in MVC? Or any ideas what could be missing? :)
Cheers
Adam

Related

Zuul Routing: Static Resources Not Found Issue

When Zuul routes a request to, say, login page, the static resources (css, js etc.) cannot be correctly located. A 404 Not Found error will be returned.
I have the following routing setting first:
ui:
path: /ui/**
url: http://serviceHost:8082/ui/
And it's working well. So when I visit http://zuulHost/ui/login/, I'll get an index.jsp and then the browser will request the static resources, whose paths are like:
/ui/ext/ext-dev.js
The browser will use http://zuulHost/ui/ext/ext-dev.js, for e.g, for that resource. And Zuul will route it to http://serviceHost:8082/ui/ext/ext-dev.js according to its setting.
But then I want to forward the request to the root / path to the login page, and I added:
root:
path: /
url: http://serviceHost:8082/ui/login/
This time, after the browser gets the index.jsp file, it will request the resources using:
http://zuulHost/ext/ext-dev.js
So in this case, the context /ui is lost, because the browser doesn't know about it since I'm forwarding the request in zuul internally. The url in the browser is still http://zuulHost. And zuul won't know where to route http://zuulHost/ext/ext-dev.js, since there's not a match in its routing table.
I wonder if there's a solution to it. I think it's a quite common issue when doing forwarding in proxy servers. Thanks.

ASP.NET MVC server path is different from application path

I have an unusual circumstance where our web server inserts a folder into the url path before loading the page. Let me give you an example:
The app is called equipment and if I were to run it on a normal server setup, it would look like:
www.site.com\equipment\home\index
BUT when I run it on our server, it inserts "idn" in the url:
www.site.com\idn\equipment\home\index
The messes up my relative references. The MVC functions want to redirect to use "\equipment\" instead of "\idn\equipment\". This happens with Scripts.Render(), Return View(), etc.
Also, I can't hardcode the "idn" into my urls b/c then it is no longer relative and it won't work on my dev box or test servers b/c they don't have a "idn" subfolder in localhost.
I also tried functions such as Request.ApplicationPath and what not but none of them return the "idn" in the result.
Is there way to MVC to know that this "idn" was inserted into the url and account for it?
Thanks!
Create your application on the test/production server in the idn folder, then it all works.

Asp.Net MVC route exception

I am using MVC to develop my website. I am getting the following errors.
URL:http://www.abc.com/robots.txt
1. The controller for path '/robots.txt' was not found or does not implement IController.
URL:http://www.abc.com/blogs/post/whats-new-in-mvc
2. The controller for path '/blogs/post/whats-new-in-mvc' was not found or does not implement IController..
But i dont have the above mentioned url in my website. How the above url are generated? Can you please let me know the solution to fix the above issue?
The first one is used by search engines to index your website. It's a good practice to have a robots.txt file to your application. So you could add this file to the root of your site. As far as the second url is concerned, I have strictly no idea who is querying it. Maybe somewhere inside your site you have a link to this url?
But if you don't want to use this file you could exclude it from routing:
routes.IgnoreRoute("robots.txt");
Now when a search engine sends a request to this file he will also get a 404 but the request won't be routed through the MVC pipeline.

iis 7 url rewrite with preset paths

I'm trying to make something like this work in iis 7, or web config
request:
products.aspx?id=100
rewrite:
domain/products/mp3
Please note, I do not want redirection, for domain/products/mp3 is invalid path, I just want the url rewrite so the user sees this path but the server serves the actual request.
Can you help?
Can you use the URL Rewrite functionality from ASP.NET instead? That was built for that.
RouteTable.Routes.MapPageRoute("Test", "domain/products/{type}", "~/products.aspx");
Then in products.aspx you have to map from mp3 to 100 somehow, but I assume you have a db table for that anyway.

Wordpress with ASP.NET MVC

I have Wordpress in a subfolder in my site named blog.
When I goto the url of my site /blog/ I get the error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
This use to show the default theme and an empty blog.
I think it may be a routing problem with MVC?
Does anyone know how to correctly set this up or how the routes should be configured?
Try putting this in your RegisterRoutes handler in global.asax:
routes.IgnoreRoute("blog/{*subfolder}");
It might also work simply with blog/*, but I am not quite sure.

Resources