0

Things I'd like to achieve

I set index.html(default.html, etc) as most prevailing default page in ASP.NET Web Application, and hope to let it show when user set url of the WebApps without page name.

I thinkg, if the url of the WebApp is something like 'http://www.somewhere.com/testApps/', when you set it in browser's address bar, index.html would be shown.

But if the web application uses form authentication, it does not work.

Environment

  • OS: Windows 7 Pro or Windows Server 2008
  • IIS Server: IIS 7.5.7600
  • Web Application/ ASP.NET 4.0, ASP.NET 2.0

The way to reproduce the problem

  1. Make a simple ASP.NET Web Application which uses form authentication. f.e. WebApp url is 'http://localhost/testApps/'
  2. Make a simple login form which publishes authentication ticket if user put any ID and Password, and set it as a login form of the form authentication in web.config.
  3. Default.aspx simply shows the page name in a text box, which is designaged in Page_Load method.
  4. Make a Index.html which statically shows its page name in the body.
  5. Set the following entry in web.config last parts.

  6. So far, when you set 'http://localhost/testApps/Index.html', the Index.html is shown. But when you set 'http://localhost/testApps/', the Login page is shown instead of Index.html


That's all. Any advice, suggestion, hit would be appreciated.

Thank you.

Masatoshi Furuya
  • 483
  • 1
  • 4
  • 5
  • Did you at all searched before posting a question. There are tons of solution present over net. – Rahul Apr 17 '15 at 12:53
  • Hi Rahul, Thank you for your advice. Actually I tried to search resembling case, but I couldn't. After I came up with my solution, I found the topics which shows the same solution! http://stackoverflow.com/questions/3824951/forms-authentication-ignoring-default-document Thanks. – Masatoshi Furuya Apr 18 '15 at 12:21

3 Answers3

0

add this to web.config to disabled authentication in this pages

<location path="index.html">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
  <location path="yourcss.css">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
Cesar BA
  • 146
  • 1
  • 5
  • Hi, Cesar BA. I have tried this web.config setting before, but it didn't work fine. I guess form authentication settings prevails IIS default page setting. Thus, before http request reaches default page, form authentication is kicked. That's what I guess. – Masatoshi Furuya Apr 17 '15 at 12:17
  • Of course, in your IIS first list default page should be index.html – Cesar BA Apr 17 '15 at 13:52
0

I have found the solution.

I've changed the approach toward this problem, and modified the AuthenticationRequest event handler in global.asax.

As I expected, when I implement AuthenticationRequest event handler, it became obvious that it's called as soon as WebApp's url withount page is called. (f.e. 'http://localhost/testApps/'). Of course it's before the default page occurs the same event handler.

So I implement the following logic in global.asax.


// bind custom method to authenctionrequest event handler.
public Global(): base()
{
    this.AuthenticateRequest += new EventHandler(this.MyAuthenticationRequest);
}

// the custom method
void MyAuthenticationRequest(object sender, EventArgs e)
{
    var myPage = HttpContext.Current.Request.Url.ToString();
    myPage = myPage.Replace(Request.Url.GetLeftPart(UriPartial.Path),
        String.Empty);
    if (String.IsNullOrEmpty(myPage))
    {
        if (Request.Cookies["started"] != null)
        {
            String flg = Request.Cookies["started"].Value;
            if (flg == "true")
            {
                return;
            }
        }
        Response.Cookies.Add(new HttpCookie("started", "true"));
        Response.Redirect("Index.html");
    }
}

The cookie 'started' is set so that even if 'Index.html' igonred the web.config's entry and request form authentication again.


With this method, I can show 'Index.html' when I set 'http://localhost/testApps/', under circumstances of form authentication.

That's all. Thank you.

Masatoshi Furuya
  • 483
  • 1
  • 4
  • 5
0

One more ultimate solution. It's much easier and practical way.

Set following entry inside section in the web.conf

<urlMappings enabled="true">
<add url="~/" mappedUrl="~/Index.html" />
</urlMappings>

Both of the way works fine, but I myself recomment the simple way.

Tnanks.

Masatoshi Furuya
  • 483
  • 1
  • 4
  • 5