I am doing some work with Web.Routing, using it to have friendly urls and nice Rest like interfaces to a site that is essentially rendered by a single IHttpHandler. There are no webforms, the handler generates all the html/json and writes it as part of process request.
This works well for things like /Sites/Accounting for example, but I can't get it to work for the site root, i.e. '/'.
I have tried registering a route with an empty string, with 'default.aspx' (which is the empty aspx file I keep in my root folder to play nice with cassini and iis). I set RouteExistingFiles to false explicitly, but whatever I do when hitting the root url it still opens default.axpx, which has no code it inherits from, and contains a simple h1 tag to show that I've hit it.
I don't want to change the default file to redirect to a desired route, I just want the equivalent of a 'default' route that is applied when no other routes are found, similar to MVC.
For reference, the previous version of the site didn't use Web.Routing, but had a handler referenced in the web.config that was perfectly capable of intercepting requests for the root or default.aspx.
Specs: ASP.NET 3.5sp1, C#, no webforms, MVC or openrasta. Plain old IHttpHandlers.
Fixed my own problem: the issue is the integrated web server, Cassini or some such. Seems that it doesnt play nice with routing, and will by default simply return the default.aspx file or, if it is missing, show a directory listing.
Using IIS with a virtual directory works fine, but is annoying (frustrates code sharers because they need to set up new virtual directories when they open my app, and pollutes my own IIS instance. Bah. Probably what I'll do for the moment however, or setup a new application manually so I can use the domain host only path like what will exist in live.
An alternative is to use the updated version of cassini, seen here, which works if the default.aspx file is missing, but I have not worked out how to integrate it with visual studio yet. Any help would be appreciated, but its not a big priority given I have workarounds.
I realise that this is a really old post, but I just ran into the same problem using VS2012, so I'm posting this here just in case.
I solved the problem by installing IIS Express and setting the project to use IIS Express in Visual Studio. Solved the problem.
Related
I have some asp.net c# code that grabs the path name and uses it for various authorization and authentication tasks. In our web site project, this is what returns the path (with extension, for example: index.aspx?querystringparam1=3&qp2=4):
string strPath = HttpContext.Current.Request.RawUrl;
This used to return "index.aspx?querystringparam1=3&qp2=4".
However, in our work to convert to a web application project, that same line of code is now returning the url WITHOUT the extension: "index?querystringparam1=3&qp2=4".
How I can get the old behavior to return? It seems to be an IIS setting somewhere because going back to the website project on the same IIS instance does not revert to the old functionality.
OK. I found the problem. Looks like Visual Studio, in its infinite wisdom, installs two packages that make up Microsoft Friendly Url (DynamicModule_Microsoft.AspNet.FriendlyUrls.FriendlyUrlsModule), which removes extensions from path files by sending a permanent redirect to the browser before even reaching the site code.
And, removing those NuGet Packages (there are two), solves the problem!
I am contracted to support a legacy ASP.net WebForms application. It's a commercial web site, and it's quite old.
Yesterday, I received a trouble-ticket that seemed to defy everything I know about web applications.
The trouble-ticket indicated that a certain URL sometimes returned an HTTP 404 error. The submitter also swears that the problem only occurs when browsing the site with Chrome. The web application is available in English and French, but the trouble-ticket says that the problem only occurs on the French version of the web application.
The URL looks like this:
http://www.example.com/promotion/mg_547/SpecialOffer.search
I tried navigating to the page in my development environment: http://www.example.dev/promotion/mg_547/SpecialOffer.search. It seemed to work fine.
Although these URLs are fictionalized, "mg_547" is an actual directory name in the URL.
I decided to navigate to the file in Windows Explorer to see if there is something unusual about the file. That's when things became surreal.
When I navigated to the "promotion" directory, I found that there is no "mg_547" directory (and besides, what meaning could such a name have?). My understanding is that in an ASP.net WebForms application, URLs corresponding to files on a physical disk, but here, there is not file; there is no directory!
I checked that there isn't an "mg_547" virtual directory in IIS.
I carefully checked that there isn't an MVC controller hiding somewhere in the application and I reviewed the global.asax.cs file to see if there could be some unusual routing set up. I couldn't find anything that would explain what I'm seeing.
I decided that the text of the page must appear in my code base somewhere, so I selected some text from the page (being sure that it didn't contain HTML-encodings) and searched for the text in the code-base; no matches!
Therefore, as far as I can tell, it seems as if the IIS server is just making up this page with Satanic Black Magic!
I believe that I've found the answer. #EdSF's comment was very helpful.
There is a .net class called PageHandlerFactory which is overidden in the web application. Specifically, this class overrides the PageHandlerFactory.GetHandler method. The mg_547 directory name is parsed in this overridden method and maps the URL to a different file on disk.
As for the original trouble-ticket that started all of this, perhaps there could be a bug in this method that causes the 404 error.
This is just as I expected. This is a corner of ASP.net I've not yet become familiar with.
I'm having a problem with a component used in a Sitecore solution on our Windows 7 workstations that is driving me batty.
In short, the component in question adds <script> tags to the page that load supporting JavaScript files. The src attributes are set to something like:
/path/to/scriptgenerator/?r=1234&p=asdf
Those paths are not working - I'm getting a 404 back.
You might thing "oh ... well, the path doesn't exist." But it does, and it also has a Default.aspx page in it. In fact, if I try the following path, the JS is generated and returned by the server:
/path/to/scriptgenerator/Default.aspx?r=1234&p=asdf
We're testing the site using IIS7.5, not Visual Studio's debugging web server. Of course, on the production machines, which are Win Server 2008, things work just fine.
The component in question is a third-party component and I have no access to the source code, so I can't just modify it to append default.aspx to the SRC path.
I have checked to verify that Default.aspx is set up as a default document for the site, and it is.
I tried to work around the problem using ISAPI_Rewrite, but for some reason, rules that I set up for /path/to/scriptgenerator are ignored.
I've tried the solution described in these questions, and that has no effect on my problem:
IIS 7 Not Serving Default Document
ASP.NET 2.0 and 4.0 seem to treat the root url differently in Forms Authentication
I'm really not sure what to try or look for next ... any suggestions?
Is this component set up within the same IIS Site as the Sitecore application?
If so, have you added path /path/to/scriptgenerator to IgnoreUrlPrefixes setting in web.config?
Greetings
i have a little problem with my ASP MVC application.
On my local development server everything works just fine but when i try to publish the application to an IIS 7.0 server it just displays plain pages without any styles / markups / images.
I put all those things in the /Content/ subfolder but when i try to access that folder on the production server it just returns me a 404 not found error.
I set the IIS server up with .Net 4.0 and followed the deployment guide on here: http://www.asp.net/learn/mvc/tutorial-08-cs.aspx
All views / controllers / classes seem to work just fine, the only thing which does not is the content subfolder and i cant see why.
Anyone got a suggestion what i could have overlooked or does anyone know that problem?
I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.
When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.
That fixed it for me, hope it works for you.
Well, I added the IIS_IUSRs to the project directory and found the same problem:
CSS won't load and nothing from the content folder.
But it resolved the Unable to start debugging on the web server problem.
Then, I added the IUSR to the same folder and that fixed the problem. Now, I can see images, css styles and all that stuff.
This is because you are probably using a fixed path on the src, like: ../../Content/Styles/style.css. In MVC you should use the Url helper: Url.Content("~/Content/Styles/style.css").
Using the Url helper you should have no issues.
Been pulling my hair out all night with this one.
On W2K8, MVC2, .NET 4.0, and IIS 7 (using VS 2010)
Made sure that IIS_IUSRS had full rights to the root folder but still no go - css, js, images still not being accessed in rendering the page....
and then .... so simple:
In Features view for the site - defined MIME types for .js, .css, and .jpg - and voila!
Sweet!
p.s. my 1st mvc app - and I think I'm liking it...
Check the properties of your content folders...see if they are not 'copying locally' for some reason.
The folder that your virtual directory is pointing to gave to the user "All" reading properties.
I wrote a custom URL rewriting module, to take certain paths and map them to our catalog out of the database.
I am using the technique outlined in the link at the bottom of my post.
I'm using .NET 3.5. The problem is that it only works when there is a page name on the end of the original URL, but if the page name is left off, then it never even calls my handler.
So for example, the URL
http://mysite.com/folder/index.aspx works but
http://mysite.com/folder/ does not.
The one with just the folder never gets into my handler class at all. Is there something you need to do to enable folders to work properly?
http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/
Is a know issue when using .NET rewriting. You need to correctly configure the wildcard mapping. Here is a good link:
http://devtalk.dk/2007/03/19/Wildcard+Mapping+And+URL+Rewriting+On+IIS7.aspx
Another option will be rewriting by IIS ISAPI with regular expressions.
In my company we actually use both.
Check out this link for references:
http://www.kowitz.net/archive/2006/09/15/url-rewriting-using-ihttpmodule-vs-isapi-rewrite.aspx
I'm not sure how to solve it but the reason is becaus IIS is treating it as a directory (which it is) and doesn't have any knowledge about how to pass the folder to the ASP.NET isapi filter and trigger the .Net handler.
You could try doing it with IIS7 and inserting the handler in the actuall IIS pipeline. Or check the bottom of the article you referenced below the heading "Using RewriteModule".