ASP.net/MVC file upload with URL rewrite enabled - asp.net

I came across this interesting problem with an ASP.net MVC website, there is an Action method to process uploaded files and it works fine with cassini webserver but when I tried with IIS in my hosting machine the upload fails, after spending lot of time I noticed that it is because of the URL rewite rules inside set to change the incoming URLs to lowercase and add a trailing slash at the end.
Is there any recommendations to avoid problems like this?

This might sound simple but it would work. Generate your routes so they match your production environment rules. By doing so you'll keep the server from redirecting and causing your issue.

Related

ISAPI Rewrite With Azure Web App

I'm not sure if this is the best/correct place for this type of question. But I have an existing .NET website which I am moving from our dedicated EC2 server to an Azure Web App.
However, this current site uses an .htaccess file with about 200 redirects (301 from old urls to new ones) which is powered by ISAPI rewrite (Which was installed manually on the Win2008 server).
I need to keep these redirects, but wondering how everyone else deals with permanent Url redirects on .NET applications when moving to an Azure Web App (From a dedicated server that had ISAPI rewrite installed)?
Putting them all in the web.config seems a little odd to me? And I don't know how that would affect performance?
Any advice or pointers would be appreciated as always.
I always put them in the web.config.
If you think it will be too messy, you can put them in a separate file and use the configSource attribute to link to the file.

Web.config redirect outside traffic for testing purposes

This is a bit of a tricky question.
I am developing a .net website, and it is hosted on our own servers.
I want to redirect outside traffic to a blank "coming soon" page, while our internal network can see the content.
How do I modify the web.config to do that?
I have already tried default document settings, but it doesn't seem to accept those, and instead displays the .NET website.
Please have a look at http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module. It shows how to use IIS URL Rewrite Module (which in turns writes to web.config) to handle your scenario.

Httphandler for ASP Classic?

Is there any way in ASP Classic to catch HTTP request before it comes to that page? Like in ASP.Net we can catch request at Application_BeginRequest.
Actually what I'm trying to do is to redirect requests to some other pages if asking files from a certain directory. My application is hosted on IIS6. And I suppose IIS6 by default doesn't support for url rewrite. Directory browsing is already disabled.
It would be nice if it could be done just putting a web.config in that certain directory to redirect to other pages.
e.g.
Original Requests:
Https://stackoverflow.com/NoReadWriteFolder/file1.asp
Https://stackoverflow.com/NoReadWriteFolder/file2.html etc
and I'd like to redirect to
Https://stackoverflow.com/ReadOnlyFolder/someOtherFile1.asp
Https://stackoverflow.com/ReadOnlyFolder/someOtherFile2.html
I googled but so far no luck, any clue would highly be appreciated.
background:
My application runs for different companies (countries in actual fact) that use the same application.
I use include file called default.asp that runs as standard include for all the scripts I serve. I catch domain requests in URL, detect which company this and then redirect to a URL that I build that includes company code and a "URL prefix" which is added to the URL throughout the session.
To do this, I read URL using request.servervariables, set Session variables, work out my URL prefix and based on this, create revised URL which I then response.redirect.
I hope this may give you an idea for your situation.
For IIS6 I have used Ionic's Isapi Rewrite Filter
https://iirf.codeplex.com/
It supports URL re-writes and re-direction and should do exactly what you need.
On the examples and help pages there are examples for you to re-direct.

Setting Default URL in Web.Config for website (Routed page!)

This is a follow-up on this question.
I basically have the same question as this question, but with a few differences. First of all, my url is http://site/Image/Cassandra/Image.aspx and I want to see http://site/Image/Cassandra instead. This is a routed page where I use ASP.NET routing to translate an url to the one above. But somehow, it doesn't find my page when I don't add "Image.aspx" or anything else ending with ".asmx".
That annoys me...
Since this has to run on both IIS 6 and 7, and because the administrators won't let me have access to the IIS configuration, I need to solve this from within my web application and I think web.config is the place to add the solution. But what is the solution?
(Btw, I know there is some trick with authentication and a default URL in it but that won't work in this case.)
The problem with the URL you would like to have is that IIS6 would require that a physical resource exist on disk, unless you've configured IIS6 to route all requests through ASP.NET. From your statement this would appear to not be the case.
So, assuming that IIS6 is not routing all requests to the ASP.NET pipeline, then there will be no way of providing the exact URL you are wanting.
I encountered a similar dilemma before and overcame it by modify my routes to include a dummy .aspx extension so that IIS6 would be happy. Is there a reason you couldn't modify your desired URL to contain an extension that IIS6 does route to ASP.NET?

ASP.NET routes on IIS 7 keep reverting

I have deployed an ASP.NET MVC web application to an IIS 7 server. It's in the root directory of the www folder. There is a sub folder that is not part of the application that needs to be served up as normal. So I added some code into my MVC app routes.
Basically I:
routes.IgnoreRoute(name);
var ignore_route = string.Concat(name, #"\/(.*)");
routes.IgnoreRoute("{*path}", new { path = ignore_route });
This words perfectly. For a while. Then it breaks. Specifically, going to "/subDirectory" (i.e. without the trailing slash) gives a "401 - Unauthorized: Access is denied due to invalid credentials." This wouldn't bother me except for the fact that due to business cards in the wild giving the subDirectory url without the trailing slash. It has to work.
It always works fine on my dev machine, but it's not running on IIS there.
I don't understand how it could work for a while and then break. If I copy over the assembly, it starts working again, and then it stops by the next day.
One possibility is that when I first deployed this web application, this code was not present. I had to add it later when we realized that there needed to be subdirectories that would be served up normally. So my first gut feeling was that it was somehow reverting back to an older version of the assembly. I have no idea how this would happening, though. When I access the directory via ftp, the modified dates are correct. The only access I have to the server is through ftp, but the server admins who are supposed to be helping me with this have been frustratingly absent. I'm at my wits end. Any ideas?
EDIT: I don't know why this was sent over here to stack overflow. This is obviously a server issue, isn't it? Look at the first response! It's talking about the server. The code works fine. Can we get this booted back over to serverfault where it belongs?
May be your server rebooting the HttpApplication once in a while and you're checking a boolean to see whether it's configured or not which stays true, so you don't add routes?

Resources