Hi micah,
Please refer below sample.
As per your condition can redirect different page.
In this sample i am redirecting same page for all condition.
HTML
Login.aspx
<asp:Login ID="Login1" runat="server" OnAuthenticate="ValidateUser">
</asp:Login>
Home.aspx
<div>
Welcome
<asp:LoginName ID="LoginName1" runat="server" Font-Bold="true" />
<br />
<br />
<asp:Label ID="lblLastLoginDate" runat="server" />
<asp:LoginStatus ID="LoginStatus1" runat="server" />
</div>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
Login.aspx.cs
protected void ValidateUser(object sender, EventArgs e)
{
int userId = 0;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Validate_User"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Username", Login1.UserName);
cmd.Parameters.AddWithValue("@Password", Login1.Password);
cmd.Connection = con;
con.Open();
userId = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
if (userId == 1)
{
FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet);
Response.Redirect("Home.aspx");
}
else if (userId == 2)
{
FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet);
Response.Redirect("Home1.aspx");
}
else if (userId == 3)
{
FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet);
Response.Redirect("Home2.aspx");
}
}
}
Home.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
FormsAuthentication.RedirectToLoginPage();
}
}
VB.Net
Login.aspx.vb
Protected Sub ValidateUser(ByVal sender As Object, ByVal e As EventArgs)
Dim userId As Integer = 0
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("Validate_User")
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Username", Login1.UserName)
cmd.Parameters.AddWithValue("@Password", Login1.Password)
cmd.Connection = con
con.Open()
userId = Convert.ToInt32(cmd.ExecuteScalar())
con.Close()
End Using
If userId = 1 Then
FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet)
Response.Redirect("Home.aspx")
ElseIf userId = 2 Then
FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet)
Response.Redirect("Home1.aspx")
ElseIf userId = 3 Then
FormsAuthentication.SetAuthCookie(Login1.UserName, Login1.RememberMeSet)
Response.Redirect("Home2.aspx")
End If
End Using
End Sub
Home.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.Page.User.Identity.IsAuthenticated Then
FormsAuthentication.RedirectToLoginPage()
End If
End Sub
Screenshot
Here UserId is return from procedure. So you need to return department from your procedure to redirect based on the department.