Index.htm question for ASP.NET

Discussion in 'General troubleshooting' started by PJ2010, Dec 20, 2010.

  1. Sorry if this is a FAQ, but I did a quick search and found nothing. I have experience in programming but not in this area.

    First, as background I checked this article: On 301 redirect at: http://www.stevenhargrove.com/redirect-web-pages/ -how to redirect web pages. ("Steven Hargrove article").

    What I want to do and cannot figure out is this: say you have a unique domain name: www.myDomainName.com

    When you type this into your browser, is it not true that you get loaded the "Index.html" or .htm page?

    Now that page is fine for HTML, but what if you want to redirect to an .aspx page? The idea is this: when a user enters "www.myDomainName.com" into their browser, I want an ASP.NET .aspx page to show up, not .html.

    I know how to redirect with ASP.NET (basically you put this in your <head> section: <%Response.Redirect("ThePageIWantToRedirectTo.aspx",true);%>

    But after reading the Steven Hargrove article I'm not sure what the best way to do this with .HTML. He implies perhaps using the IIS tool to do something (see where he says: "301 Redirect Using IIS

    1. In internet services manager, right click on the file or folder you wish to redirect.
    2. Select the radio titled "a redirection to a URL".
    3. Enter the page that the page will be redirected to.
    4. Check "The exact url entered above" and the "A permanent redirection for this resource".
    5. Click on 'Apply'.


    Since I only plan to do this once probably at my DASP site, perhaps I can get DASP tech people to do this at their server end with IIS? Or, perhaps somebody can tell me another way to do this from my client side so I can do this more than once if I want to (though at the moment I only have plans to change this redirect once).

    Thank you. This is not that important at the moment so I'll check this thread in a few days and hopefully somebody will answer by then.

    PJ
     
  2. So good it's Ludicrous! :)

    Thanks Wisemx! The article talks about hosting multiple websites under the same domain, which is a bit of overkill for what I have in mind (just a simple redirect from html to aspx is all I want). What I will do in a few hours is come up with a solution that works for me, based on the Steve Hargrove article (another one here: http://www.stevenhargrove.com/understanding-redirection/ ) and post my solution here for future reference.

    PJ
     
  3. The Solution

    After some trial and error here is what I found works for me, for an ASP.NET .aspx web page.

    Problem: you want a particular page other than index.html to show up when a user types "www.myDomainName.com" into their browser.

    The Solution: (or rather, one solution, of three or four possible solutions)--

    First solution: understand how the default webpages work, and rename your page so it shows up first.

    Second solution: Use the IIS manager to 'redirect' your index.htm page. IIS Manager HTTP Redirect.

    Third solution: use any of the other server side solutions as outlined by Steven Hargrove's blog: http://www.stevenhargrove.com/redirect-web-pages/ Actually one of Steven Hargrove's solutions is in fact the Second Solution, see where he talks about IIS.

    Fourth solution: use a client side command to redirect (not recommended, see Hargrove’s link as to why).

    Steps and points to make:

    I chose the "First solution" above, which was trivial, but only after I understood how pages are loaded by servers.

    See below for what I did.

    First solution (starts at step 4):

    1) Optionally enable the IIS Manager. It's not strictly necessary for the First Solution however. To do so, see this link on IIS Manager in general at DASP: https://support.discountasp.net/KB/a400/how-to-connect-to-windows-2008iis-7-using-microsoft.aspx

    2) make sure you configure IIS Manager to accept or assign users (enable users), or you'll not be able to log on to IIS: see: https://support.discountasp.net/KB/a402/assigning-users-to-microsoft-iis-7-manager.aspx

    2b) if you decide to do a true redirect, read Steven Hargrove's blog: http://www.stevenhargrove.com/redirect-web-pages/

    3) Log onto IIS Manager. Download any necessary modules that popup in your screen (there are always several it seems every time I log on, including one called "Redirect" which is used for redirects. They can be installed without the need for elevated permissions, i.e. no need to be Administrator in Windows XP)

    The above three steps are optional for the First Solution, so you can simply start here at step #4.

    4) for my purposes, I simply wanted to change the index.htm page to something else, an .aspx (.NET) page, when a user types www.myDomainName.com into their browser. Technically, I did this not by redirect per se, but it worked the same. There are four ways to do this--I choose the "easiest" way (for me), and it was not a "redirect" strictly speaking.

    5) The easiest way (First Solution) is to make sure a particular .aspx page gets loaded when a user types "www.myDomainName.com" into their browser. ASP servers have a hierarchy of files that are loaded, one after the other, with the server stopping at the first page it finds in this list, see below, so you simply change the priority of pages loaded when the user types www.myDomainName.com into their browser. The first solution simply deletes or renames all pages that might get in the way of your page loading first--it's that simple.

    First Solution here:

    6) For ASP.NET supported servers, the hierarchy of documents first loaded when a user types "www.myDomainName.com" into their browser is as follows (in this order--if the server fails to find the first page it goes to the next):

    ASP.NET's Hierarchy List:

    index.html
    index.htm
    index.asp
    index.aspx
    default.htm
    default.asp
    default.aspx

    7) So I wanted to have "default.aspx" loaded first. First Solution: simply delete or rename all files named above in your server root directory except "default.aspx". Done! Then, make sure your Visual Studio ASP.NET solution's "start" page is called "default.aspx" (right click from Solution Explorer and select “Set to Start Page”). Also of course change the "code behind" start page name to "Default.aspx" in your code (or you will get a runtime error when you debug it). That is, in the code behind make any necessary "global search and replace" edits using Visual Studio to change the references so they point to Default.aspx from whatever the original name of the startup page was. Right click in Solution Explorer and make sure you "Set as Start Page" this default.aspx file. Case is important. In your hard drive, the actual file name itself that your program starts in should be in lower case: 'default.aspx' (but in the Code behind code, the name of the code behind will be "Default.aspx" since 'default' in lowercase is a reserved keyword in ASP).

    Now FTP (publish) the solution files to your website, "www.myDomainName.com", using the Publish tool within Visual Studio. No need to specify a subdirectory, and it will go to root. No need to use the "Web Application Tool" in the DiscountASP.net Control Panel (one of the few times you never have to use this tool when publishing). I turned On and Off the website using the DASP Control Panel, just to flush out any old metadata, but I don't think you need to do this either.

    8) Done. It's that simple for the First Solution. Again, you are simply deleting or renaming all files that might get in the way, such as, above, "index.html", "index.htm", "index.asp", "index.aspx", "default.htm", "default.asp", and keeping "default.aspx".

    9) (optional) now for a minor point of aesthetics. If you do the above, everything is kosher and works fine but there's an aesthetics problem if you have more than one page (it's up to the reader to determine if this is a big deal or not--I don't think it's that big a deal but I offer this workaround below anyway). If you have more than one page, if you do a 'redirect' ( i.e., from inside one of the .aspx pages: "protected void LinkButton1_Click(object sender, EventArgs e) { Response.Redirect("Default.aspx");} you end up having a file called "Default.aspx" show up in the title bar. Is this annoying? Probably not. But if so, then to have a nicer looking .aspx page, like "MyStuffStartPage.aspx" (assuming for the sake of argument this is nicer looking in a title bar than "Default.aspx") you simply do this: first save your solution with "Default.aspx" in another directory, and work with a copy. With the copy, change all references to "Default" are replaced with "MyStuffStartPage" globally in your solution" then publish the solution again to your root directory, but this time with the startup page being "MyStuffStartPage.aspx" . Now go back to your "Default.aspx" solution, that you've saved, and republish it again onto your domain at DiscountASP.net. Now you have both default.aspx as well as "MyStuffStartPage.aspx" in your root directory, but the strange thing is that in the title bar you should get "MyStuffStartPage.aspx" showing up, not "Default.aspx". How this works is beyond me as you would think the binaries point to Default.aspx, not MyStuffStartPage.aspx, but it did work for me with ASP.NET and Visual Studio 2008. In any event, this is optional just for aesthetics--if you don't mind "Default.aspx" showing up in the browser bar when you redirect to the home page in a multi-page ASP application, then you don't need to do this optional step.

    That's it for the First Solution.

    For the Second Solution use the IIS tool by clicking on the icon that says "Default Document" and play with that. I think it only will allow you to bump up the ordering for ASP.NET's Hierarchy List above. That way you don't need to delete (or rename) the other files, you can continue to keep them in root directory. I did not see the need for this step. I also tried bumping "MyStuffStartPage.aspx" to the top of the list, but for whatever reason it did not override the default.aspx page and so I had to revert to the First Solution. Perhaps I could have played with the properties but I did not--I'll leave it to another person to explain how to use this tool.

    10) for the Third Solution: see the excellent Steve Hargrove blog post above.

    11) for a "Fourth" (and inferior) Solution, you can try a client side script or command, but see Steve Hargrove's blog as to why this should be avoided.

    12) For a way to host multiple websites in one domain, see the solution in the link in this thread provided by WISEMX.

    PJ
     

Share This Page