Custom URL Extensions/Routing Without IIS Access - asp.net

I have a need to use extensionless URLs. I do not have access to IIS (6.0) so I cannot map requests to ASP.NET and handle with a HttpHandler/HttpModule. However, I can set a custom 404 page via web host control panel.
My current plan is to perform necessary logic in the custom 404 page, but it "feels wrong". Are there any recommendations that I am missing?
Edited: Added "Without IIS Access" to the title since someone thought this was a repeat question.

Without access to IIS, that would be your only option.

The 404 page really is your only option if you can't map the requests. I've seen several blog packages that do this to enable magic URLs like .../archive/YYYY/MM/DD and such - there's no such page, so it hits the 404 page and the 404 page does the redirection.

Related

Akamai has issue with ASPX post backs

I'm using Akamai Edge Server to serve up all my web content except for html and aspx pages. The issue I am having is with a language switcher that does a post back to the same page and then based on the language does a response.redirect to the same page in the other language folder.
The steps that happen are:
go to page /en/default.aspx
select a different language such as fr.
The aspx code on that page calls a header user control which will then redirect to the proper language page
It fails on the postback to the control and I get an access denied on /en/default.aspx which is an akamai page not on my webserver.
If I access my dotnet server directly you'll see that the page will do a postback to itself /en/default.aspx then a response.redirect to /fr/default.aspx
Ok I figured it out that akamai edge server doesn't allow posts by default and you have to enable it. Im new to using akamai in this way didn't think it would deny such a common thing.

IIS 7.5 Logs and ASP.Net 404 Custom Pages

I want to make a custom 404 page for my site but I want to log all the normal information into my IIS 7.5 logs like the default 404 deals with so my Statics program can tell me things like what page got the 404 error, what was the referring URL to that broken page, and more. Do I have to do anything special on my 404 page to do this or has ASP evolved enough to automatically do logging for me if I return a 404 status code?
How you handle the errors determines how the errors will show up in the logs/responses. If you simply use custom error pages, it will show up no different in the log than if you had used the OOTB pages. If, however, you are writing an ASP.NET application, and handle/bury the exception, nothing will show up in the logs.
If you are writing a .NET application, this blog post provides a pretty good overview on how to properly handle errors for SEO.
ASP.NET Custom Error pages can be implemented in many different ways. The "worst" way are those that return a 301 redirection to "NotFound.aspx" (or similar), which will, of course, return a 200 status code. Unfortunately the IIS Manager actually lets you specify this method. If you're finding your 404s and 500s aren't being logged then check out this setting first.
Error pages, regardless of their implementation, must not issue any redirection and must set the status code to 404, that way IIS's logger will log it accordingly (IIS inspects the headers of all outgoing responses and uses that to populate the log).

How can I set the default page for https requests?

We have a website which has a Virtual Directory containing the secure portion of the website.
If users come to http://www.mydomain.com, they should get directed to default.aspx of the main site, but if they go to https://www.mydomain.com, they should go to default.aspx of the virtual directory.
The default page for the main site works fine, as does the secure page if I navigate to it using the full name, however I can't figure out how to set the default page for https traffic that doesn't specify a specific page.
http://www.mydomain.com - Works
https://www.mydomain.com - Page Not Found
https://www.mydomain.com/myvirtualdirectory - Page Not Found
https://www.mydomain.com/myvirtualdirectory/default.aspx - Works
What do I need to do to make links 2 and 3 load the default page show in 4?
My website is running on IIS 6.0 in Windows Server 2003
Overall, this is an anti-pattern as you state the entire behavior of the site changes based on the port. I am not stating definitively you are doing this, but consider the following:
If you are redirecting due to a user needing to see other things, you can make conditional controls that display only when in HTTPS. The same can be done for authenticated and authorized versus not.
If you are redirecting because an HTTP user needs to log in, the more consistent pattern is to have them click a log in button. And, you can force HTTPS at this point without breaking the pattern.
If you really need to redirect for some reason, there are a couple of ways of handling this:
In IIS
HTTP Handlers
URL Rewrite - requires the URL Rewrite bits for IIS 7
I imagine there are some other ways to solve this.
I finally figured out my issue. In my case, it turns out the problem was an old URL Rewrite rule I wasn't aware of that was transferring all https traffic that didn't have a file name specified to index.php, which of course didn't exist.
I found this out by viewing the IIS error logs, which was telling me the 404 was being caused by index.php

Custom http error pages for images?

I know it's common for pages to redirect to a custom error page for 404 errors and such. But say somebody opens the url in their browser for an image that doesn't exist for example http://mysite.com/nothinghere.gif. This site returns a 404 error but it's not just the browser default, it's a custom 404. How do you configure an ASP.NET site on IIS7 to do this? the customerrors section in the web.config doesn't seem to apply to things like images, css, js, etc
customErrors section would apply to resources managed by ASP.NET. IIS7 has its own httpErrors section under webserver node. Of course, there is also UI to configure it. Anyway error handling behavior also changes based on you are running your ASP.NET application under classic mode or integrated mode. I will suggest that you read following articles to get hold of it.
http://www.braintrove.com/article/46 - this will tell you how to set up IIS7's own cutom error pages
Below explains IIS7 errors handling
http://learn.iis.net/page.aspx/267/how-to-use-http-detailed-errors-in-iis-70/
http://blogs.iis.net/ksingla/archive/2008/02/18/what-to-expect-from-iis7-custom-error-module.aspx
Make your custom error page a script.
When its called you can either send a html response for a page missing or query the request to find out the image name and then send an image or redirect to an image.
try these links for issues with custom 404 errors
IIS 404 Custom Error not working as expected
http://forums.asp.net/p/1603843/4089618.aspx

URL Redirects in ASP.NET

Ok, wierd problem I cant figure out. Hopefully someone where can. I have inherited a site that was developed with a very over-architected Content Management System. I am having problems now with the redirection functionality built into it.
This is on a dedicated Windows 2003 server running ASP.NET 3.5 sp 1. The redirects are stored in the database, and I have confirmed that the correct redirect is in place in the database. Finally, the file extension .html has been mapped in IIS to the ASP.NET ISAPI. And there is an HttpHandler created to redirect the .html requests. The default documents on the server, in order, are:
default.aspx
index.aspx
default.asp
index.asp
default.html
index.html
for this example, we have two redirects both pointing to the same content page. /example and /example.html
when requesting /example.html it correctly finds the appropriate redirect in the database and does its magic. Bueno. When requesting /example it gives a 404 page. Its not even the asp.net yellowish 404 generic error page. Its the standard vanilla IIS 404 response so it appears that asp.net is not intercepting these requests.
Let me know if any other information is requested and I will try to provide what I can. Thanks in advance for all the great recommendation I am sure will come from the community.
You should be able to map a wildcard extension to go through the ASP.Net ISAPI DLL is the solution.
Installing Wildcard Application Mappings (IIS 6.0) may also be useful.
Without rewriting the CMS, you can put a physical file in a new directory "/example". This will trigger ASP.NET to intercept the request, and hopefully load your page.
If you want to really hack it up you can change the IIS 404 page to be a .NET page in your application that can handle the original request and redirect to the page you really want.
Yes this is correct because /example is not pointing to any file, it is pointing to directory in the web server. Check that Default.aspx/ default.html or any other atleast one of them exists in your app.
If you are using ASP.Net MVC for REST then check your actions are properly written.

Resources