default document not displaying complete url
Asked Answered
S

3

7

I having an issue with default document of iis setting. In my site (http://mysite) I have provided the default document as login page. When user type the url (http://mysite) it does redirect user to login page but doesn't display the complete url (http://mysite/login.aspx). Looks like default document does server.transfer rather than response.redirect. Because of that when user enter their credentials and then click sign in, it again redirects them to login and from there on it works fine. So user has to enter their credentials twice.

My app is developed on .NET 3.5.

Is there a way that I can achieve response.redirect.

Stochmal answered 14/1, 2013 at 10:8 Comment(0)
C
3

Use an index.html as default document in your base directory. In this index.html use either meta refresh or javascript redirect to your login.aspx page. See following example meta refresh code.

your project

website 
   index.html
   secure/login.aspx

index.html

<!DOCTYPE html>
<html>
<head>
<title>YOUR PROJECT NAME</title>
    <meta http-equiv="refresh" content="0;URL='http://www.YOURDOMAIN:COM/secure/login.aspx'" />    
</head>

<body>
    <p> Click to   
        <a href="http://www.YOURDOMAIN:COM/secure/login.aspx">Login</a>
   </p> 

</body>

</html>
Cravens answered 22/1, 2013 at 0:29 Comment(0)
M
2

In the same folder as default document place text file named web.Config (no .txt, .xml or any other extension) with following exact content:

<?xml version="1.0"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to login" stopProcessing="true"> 
                    <match url=".*" />
                    <conditions>
                         <add input="{URL}" pattern="^/$" />
                    </conditions>
                    <action type="Redirect" url="/login.aspx" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Mirabel answered 20/1, 2013 at 17:3 Comment(3)
hi , do u mean that i should place another web.config to the folder where my login page sits?. my login page sits in different folder. it is not directly under root folder.Stochmal
another? In one folder one filename can be used only once. If you've an existing web.config in that folder, you'll have to merge with this XML code.Mirabel
Probably a better soluction than the accepted one, thanks!Dalenedalenna
B
0

Write following lines in Page_Init of your Login page.

Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
    If Not MyBase.IsPostBack Then
        If HttpContext.Current.Request.Url.ToString.Contains("Login") = False Then
            Response.Redirect("~/Login.aspx")
        End If
End Sub
Bandeen answered 2/12, 2013 at 10:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.