tags:

views:

105

answers:

6

Hi All,

Suppose I have a server wid some virtual name as ABC. And also I have a .Net web application XYZ with some .aspx pages like Home.aspx etc. Now if I want to make Home.aspx page as the default page when I type the server name in brower the Home.aspx opens automatically. what I need to do in this case.

Currently Iam accessing the application with this URL https://ABC/XYZ/Home.aspx But I want to access the application in this way: http://ABC

+3  A: 

I'm not sure in which version of iis you are working, but in the iis 7 manager:

  • Select the site that responds to the url / which could be "default web site" depending on your set up
  • Open the "Default Document" option
  • Select the Add action and enter Home.aspx. If you already see it in the list, you might need to move it up if something else is taking preference (select Home.aspx, and on the right hit the move up action)

In previous IIS versions just do the same but from the properties of the site.

eglasius
+1  A: 

One of the easiest ways is to declare the default doc in your web.config.

For more details see: http://blogs.iis.net/bills/archive/2008/03/22/how-to-add-a-default-document-with-iis7-web-config.aspx

JohnEgbert
+3  A: 

There is not a way in IIS to get:

https://ABC/XYZ/Home.aspx

to point to:

https://ABC

because XYZ/Home.aspx is not a valid "default document". Default documents must be in the same folder.

If you are trying to get:

https://ABC/XYZ/Home.aspx

to point to:

https://ABC/XYZ

then see eglasius's answer.

Otherwise, you will need to set Default.aspx as the default document.

Then create a file Default.aspx in your website root folder containing:

<%@ page language="C#" %>
<%
Server.Transfer("/XYZ/Home.aspx");
%>
userx
There are actually several ways to do this in IIS, see http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
Hightechrider
+1  A: 

In IIS you can set default documents in the document tab. In this tab you can set home.aspx to be recognized as a default document to load. However, you can't set a file down the tree to be the default document to load when you go to the root of the site. For this you will have to redirect.

You can do this two ways:

  1. Have IIS do it.

  2. Do it yourself.

By having a default.aspx doc in the root of the ABC server and have it redirect to /xyz/home.aspx or just /xyz and set in the xyz folder in IIS to have home.aspx in the default document list.

<%@ Page Language="C#" %> 
<% Response.Redirect("path", true); %>

You could use Response.Transfer as well but it will not change the URL.

klabranche
A: 

you can do either :
1- Create an HttpHandler and register it in web.config or in IIS:

public class MyHandler : IHttpHandler
{
    public bool IsReusable
    {
        get { return true; }
    }

    public void ProcessRequest(HttpContext context)
    {
        //you can use any way you see good to determin that the user requestd the default document  
        //this line is not practical but just to make the idea clear
        //the following line could need more revising.

        if (context.Request.Url.ToString() == context.Request.Url.GetLeftPart(UriPartial.Authority)
            context.Server.Transfer("MyPage.Aspx");
    }
}

and here is the Web.Config:

  <system.web>
    <httpHandlers>
      <add verb="*" path="*" type="HandlerNameSpace.MyHandler, HandlerAssembly" />
    </httpHandlers>
  </system.web>

2- or create an HttpModule :

    public class MyModule : IHttpModule
{
    public void Dispose()
    {
        //Dispose
    }

    public void Init(HttpApplication context)
    {
        //hook into the requesting process and try to figure the Url


    }
}

and you can register it in code AFAIK

  public static IHttpModule Module = new MyModule();

    void Application_Start(object sender, EventArgs e)
    {
        base.Init();
        Module.Init(this);
        // Code that runs on application startup

    }
Nour Sabouny
+1  A: 

You can do this using URL rewriting in IIS. See http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

Hightechrider