Forms Authentication in asp.net

Posted by Kavi.Sirius under ASP.NET on 5/8/2012 | Points: 10 | Views : 1192 | Status : [Member] | Replies : 2
hi ,

i have one problem.
i am using lDap forms authentication in my application,

i have three pages,

logon.aspx
login.aspx
webform.aspx

first user run the application ,its first check the user have the valid ipaddress,
if they have valid ipaddress it redirect to webform.aspx page
unless it goes to login.aspx page

below my coding:

web.config:

</pages>
<authentication mode="Forms">
<forms loginUrl="logon.aspx" name="adAuthCookie" timeout="10" path="/">
</forms>
</authentication>

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetCustomerIP();
if (Request.Params["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage("login.aspx", false);
}


}
}

[WebMethod]
public void GetCustomerIP()
{
string ipaddress = "172.16.107.192";//here i hotcode the ipaddress,this ipaddress not match to the below regex
Match mm = Regex.Match(ipaddress, "^(((1[0-9]{1,2}))\\.){3}(([0-5]{3,3}))$");
if (mm.Success)
{
string strUname = "";

strUname = WindowsIdentity.GetCurrent().Name.ToString();

Label1.Text = "User Name : " + strUname.ToString();

strUname = strUname.Replace("\\", ",");
string[] Uname = strUname.Split(',');
if (Uname[0].ToString() == "MARG")
//if (Uname[0].ToString() == "PRAGASHLAB")
{
hdnDomain.Value = Uname[0].ToString();
hdnUname.Value = Uname[1].ToString();
ModalPopupExtender1.Show();
}
//Response.Write(ipaddress);
//Response.Redirect("LoginForm.aspx");
}
else
{


Response.Redirect("login.aspx");
}

}

in this code i use hotcode for ipaddress,but the ipaddress not match to the regex
so it goes to the else part that is redirect to the login.aspx page,
but in my code it doest redirect,
defaulty its redirect to the start page of application.
Here i can get the Returnurl but it not goes to the loginpage


Thanks in advance...........

Regards
Kavi.n



Responses

Posted by: Funda on: 5/8/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
What you are trying is not advisable,
FormsAuthentication.RedirectFromLoginPage :
Redirects an authenticated user back to the originally requested URL or the default URL.
So the Orignally requested URL or the default URL will be referred in Web.Config
<system.web>

<authentication mode="Forms">
<forms loginUrl="Logon.aspx" name=".ASPXFORMSAUTH">
</forms>
</authentication>
<authorization>
</authorization>
</system.web>

Try Something like this
FormsAuthentication.RedirectFromLoginPage (UserEmail.Text, bool);


This will re directed to Logon.aspx if the credential are Ok
Thanks


Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sekar.C on: 5/9/2012 [Member] Starter | Points: 25

Up
0
Down
http://support.microsoft.com/kb/301240

Regards
Sekar.c

Kavi.Sirius, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response