Simple redirect in IIS7 to another page? - asp.net

We are taking our website offline for approx an hour today and I want to redirect all traffic to an offline default page I created within the folder "offline" and the file is default.aspx. I tried using IIS7 HTTPRedirect by checking "Redirect requests to this destination;" and entering in the URL "http://webtest.ipam.ucla.edu/offline" but I am receiving a "Internet Explorer cannot display webpage" error.
please help.

I'm assuming as you're on IIS7 that your app is in ASP.NET - if not, please ignore this:
There's a nifty little feature that if you place an app_offline.htm file in the root directory of your ASP.NET application, it will have the net effect of taking your application offline.
What is the detail you see in your "Internet Explorer cannot display webpage" error? Is it really that generic or do you get some detail?
Addendum
An alternative is to add something like this into the web.config of your asp.net app (which will allow dynamic pages:
<system.webServer>
<httpRedirect enabled="true" destination="http://myurl.com/offline.aspx" />
</system.webServer>
The issue with using this approach is while you're uploading new assemblies, there is a chance your application will crash when someone hits it (giving them confusing errors) while you're making changes. Consequently, the offline.aspx page may not show properly - your mileage may vary, but this is why it's generally considered a better practice to use app_offline.htm.

Related

Blank ASP.NET Webpage for the application deployed on IIS

I have an asp.net application deployed on IIS Server located at 10.0.0.74, when
i tried to access it with chrome browser i get an empty or blank webpage.
However if my colleague tries to access it from his computer he get normal webpage with content on it.
It seems really weird to me what might be the problem.
The screen shot below is what the page looks like.
I would appreciate any help
This is not enough to go on, assuming ASP MVC 5 on IIS here are some suggestions.
On your server
Check the following
Is the physical path in IIS correct - actually point to your code?
Do you have any rewrite rules in your web.config that could be redirecting?
Did you set up the bindings correctly?
Are you hitting the site under https / http?
Checked "Turn windows features on/off" and see if ASP.NET 4.8 installed
Did you setup the HTTP Redirection and HTTP Errors
See how you are setting up error handling setup in your global.asax, see here and disable it
Goto your Control panel > Programs and features > Turn Windows features on or off and under "World Wide Web Services" / components:
Common HTTP features:
Default document
Directory browsing
HTTP Errors
HTTP Redirection
Static Content
Security
Basic authentication
Request filtering
URL Authorization
Windows authentication
The problem was that the plugins in "Content" folder were not included in the projects.
I included all the files shown in the image below.
I apologize for wasting your time, i should have checked the console before!

Anti-forgery cookie issues after a deployment

I keep getting the below error after deploying my ASP.NET MVC project to Azure Web Sites
A required anti-forgery token was not supplied or was invalid.
This seems like it only happens with the following steps:
Open browser and navigate to site's login page (this page may need to stay open for some amount of time) - UPDATE: This does not appear to be needed
Deploy project
Try to login
Get error
I do have the machine key specified
<machineKey validationKey="[vKey]" decryptionKey="[dKey]" validation="SHA1" decryption="AES" />
so I thought that should protect me from this happening. Any thoughts?
UPDATE: I am publishing from Visual Studio and the destination URL was set to http://[appName].azurewebsites.net instead of the custom domain that I use for FB authentication. I am on the custom domain when I actually log in so maybe there is some sort of caching issue? Not sure. As it doesn't always seem to repro, it's hard to determine if that made any difference.
I added DonutOutputCache to the ExternalLoginsList thinking I was being clever. This is a lesson in YAGNI.

Why do Asp.net web project have garbage values in the url?

I have tried googling and searching for this issue on SO - but have had little success - primarily because I am not sure whether I am searching right.
I am working on an ASP.Net Web Application Project (not website) using Visual Studio 2008, C# and Cassini for testing.
However, everytime I run the site, I get a URL such as:
http://localhost:8671/(S(saifdk55xyhalrqbstrtrdiw))/SubjectClassTeacher/Default.aspx
Even if I modify the URL and try to go to:
http://localhost:8671/SubjectClassTeacher/Default.aspx
I am redirected back to this URL.
The garbage value in the center: (S(saifdk55xyhalrqbstrtrdiw)) keeps changing every few times I compile and I have no idea why it gets injected or how to disable it.
Could anyone throw any light on this issue?
Primarily, I would like to know why this happens and how do I disable this.
Because this happens when I deploy the website on IIS as well.
Any help is appreciated.
Thank you.
This is a clever feature in ASP.NET* called cookieless sessions. It works by injecting your session ID into every URL, so ASP.NET can tell the difference between user A who visits a page, and user B who visits the same page. Normally this is accomplished with cookies, but this approach removes the dependency on the end-user having them enabled.
From MSDN:
...you don't have to change anything in your ASP.NET application to enable cookieless sessions, except the following configuration setting.
<sessionState cookieless="true" />
*The concept is not exclusive to ASP.NET, but it is baked into ASP.NET and - as you've discovered - can be turned on with no particular effort on the part of the developer.

ASP.NET 2.0 - How to use app_offline.htm

I've read about the app_offline.htm file which can be placed within the root of a .NET 2.0 application which will in essence shut down the application and disable any other pages from being requested.
I've placed the file in the root, and my site still loads. I went into default documents in IIS and set it to app_offline.htm and the site still loads (this might have been a caching issue though)
Anyway, has anyone run into issues using this? Am I doing something wrong?
I have used the extremely handy app_offline.htm trick to shut down/update sites in the past without any issues.
Be sure that you are actually placing the "app_offline.htm" file in the "root" of the website that you have configured within IIS.
Also ensure that the file is named exactly as it should be: app_offline.htm
Other than that, there should be no other changes to IIS that you should need to make since the processing of this file (with this specific name) is handled by the ASP.NET runtime rather than IIS itself (for IIS v6).
Be aware, however, that although placing this file in the root of your site will force the application to "shut down" and display the content of the "app_offline.htm" file itself, any existing requests will still get the real website served up to them. Only new requests will get the app_offline.htm content.
If you're still having issues, try the following links for further info:
Scott Gu's App_Offline.htm
App_Offline.htm and working around the "IE Friendly Errors" feature
Will app_offline.htm stop current requests or just new requests?
Make sure your app_offline.htm file is at least 512 bytes long. A zero-byte app_offline.htm will have no effect.
UPDATE: Newer versions of ASP.NET/IIS may behave better than when I first wrote this.
UPDATE 2: If you are using ASP.NET MVC, add the following to web.config:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
Note that this behaves the same on IIS 6 and 7.x, and .NET 2, 3, and 4.x.
Also note that when app_offline.htm is present, IIS will return this http status code:
HTTP/1.1 503 Service Unavailable
This is all by design. This allows your load balancer (or whatever) to see that the server is off line.
Possible Permission Issue
I know this post is fairly old, but I ran into a similar issue and my file was spelled correctly.
I originally created the app_offline.htm file in another location and then moved it to the root of my application. Because of my setup I then had a permissions issue.
The website acted as if it was not there. Creating the file within the root directory instead of moving it, fixed my problem. (Or you could just fix the permission in properties->security)
Hope it helps someone.
Make sure that app_offline.htm is in the root of the virtual directory or website in IIS.
Make sure filename extensions are visible in explorer and filename is actually
app_offline.htm
not
app_offline.htm.htm
I ran into an issue very similar to the original question that took me a little while to resolve.
Just incase anyone else is working on an MVC application and finds their way into this thread, make sure that you have a wildcard mapping to the appropriate .Net aspnet_isapi.dll defined. As soon as I did this, my app_offline.htm started behaving as expected.
IIS 6 Configuration Steps
On IIS Application Properties, select virtual Directory tab.
Under Application Settings, click the Configuration button.
Under Wildcard application maps, click the Insert button.
Enter C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll, click OK.

ASP.NET/IIS: 404 for all file types

I set up 404 handler page in web.config, but it works ONLY when extension of URL is .aspx (or other which is handled by ASP.NET).
I know I can setup static HTML page in website options, but I want to have a page.
Is there any options to assign ASPX handler page for all request extensions in IIS?
The direct question was whether or not there are options to assign the ASPX handler to all request extensions: Yes, there is. I'll discuss how to do that shortly.
First, I think the "hidden" question -- the answer you really want -- is whether or not there's a way to redirect all 404 errors for pages other than ASPX, ASMX, etc. Yes, there is, and this is the better choice if it'll solve the issue you're having.
To redirect all 404s in IIS 6, right click your web application root (whether it be its own site or a virtual directory in the main site), and choose "Properties." From there, choose the "Custom Errors" tab. Find 404 in the list and change it to the redirect you want.
Now, if that won't suffice -- and I really hope it does -- yes, you can run every page through the ASPX handler. However, doing so comes at a fairly high cost in terms of efficiency -- raw HTML/image serving is considerably faster than anything dynamic.
To do this, right click your web application root and choose "Properties." Choose the "Home Directory" tab. Click "Configuration;" a new window will pop up. Copy the path from one of the ASP.NET page serves, and then use it for a wildcard application map.
Bear in mind, again, this is the wrong answer most of the time. It will negatively impact your performance, and is the equivalent of using a chainsaw to carve a turkey. I highly recommend the first option over this one, if it will work out for you.
For information:
This is one of the several nice things that IIS7 brings - all pages are routed through the handler such that you can do custom 404s and - usefully - directory and file level security for any file (based on the same web.config stuff as for asp.net files prior to IIS7).
So notionally "use II7" is an answer (will be "the" answer in time) - but of course its not a terribly practical one if you're not hosting/being hosted on W2k8 (or higher).
The web.config can only set up errors pages for pages controlled by it's web site. If you have any other pages outside the purview of the ASP.Net application, then you set up handling for them in IIS. There's an option in there for configuring the 404 page where you can point it to your custom page.
Only other thing i can think of is passing ALL extensions to asp.net.
This way all types of files get processed by asp.net and your custom error page will work.
In the IIS application configuration, you can set a wildcard mapping (".*") to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
You can setup wild card mapping in IIS (Application configuration/Mappings/Wildcard mappings/ - just set aspnet_isapi.dll as executable and uncheck the Verify that file exists box) that will route all incoming requests to your app - so you can control the behavior directly from it.
You don't have to setup static page in your IIS application settings. Imho, you should be able to setup valid url (e.g. /error_handler.aspx) from your app that will be used as landing page in case of specific server error.
In IIS you can set a Custom Error for 404 errors and direct it to a URL in the site properties.
It shows a static html by default
C:\WINDOWS\help\iisHelp\common\404b.htm
You can change it to a relative url on your site.

Resources