코드에서 리디렉션 루프의 원인을 알고 있습니다. 어떻게 수정해야할지 모르겠습니다. 첫째, 내 코드.리디렉션 루프 해결
switch (Request.QueryString["Error_ID"])
{
case "1":
// Error Code 1 is when a user attempts to access the Admin section and does not have rights to.
MultiView1.ActiveViewIndex = 1;
break;
case "2":
// Error Code 2 is when a user is not currently Active.
MultiView1.ActiveViewIndex = 2;
break;
default:
// Default is View Index 0 for default access.
MultiView1.ActiveViewIndex = 0;
break;
}
// Get current username.
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
// Test to see if user is Active.
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HSEProjRegConnectionString1"].ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT [active] FROM [tbl_Person] WHERE username LIKE @username", conn))
{
cmd.Parameters.AddWithValue("@username", "%" + userName + "%");
var res = cmd.ExecuteScalar();
bool registeredAndActive = (bool)res;
if (registeredAndActive)
{
// Active Condition. The DEFAULT in SWITCH() will take care of displaying content.
}
else
{
// !Active Condition. Shows an alternative version of the default page where the user is told they do not have access.
Response.Redirect("default.aspx?Error_ID=2");
}
}
코드 포인트는 나중에 하나의 페이지가 제공 될 경우 SWITCH() 메소드에서 쿼리 문자열을 확인하는 것입니다. 그런 다음 현재 AD 사용자 이름을 사용하여 로그인 한 다음 사용자 데이터베이스를 검사하여 사용자가 활성으로 표시되는지 확인합니다. 그렇다면 페이지를 정상적으로로드 할 수 있으므로 아무 작업도 수행하지 않습니다. 그렇지 않으면 동일한 페이지로 리디렉션되지만 Error_ID를 추가하여 사용자가 액세스 권한이 없다는 다른보기를 표시 할 수 있습니다. 나는 이것이 리다이렉트 루프가 어디서오고 있는지 확신한다. 누구든지 리디렉션 루프를 제거 할 수있는 방법에 대한 아이디어가 있습니까? Request.Url.ToString()
을 시도한 다음 !var.Contains
을 시도하여 리디렉션을 수행했지만 그 작업을 수행 할 수도 없었습니다.
편집 : 누군가가 Response.Redirect()
에 대한 대안이 있다면 듣고 싶습니다. 작동하지만, 원래는 Response.End()
을 사용하고 있었고 코드 실행을 허용하지 않았기 때문에 Response.Redirect()
과 QueryString
을 사용하여 원하는대로 할 수있었습니다.
완벽하고 간단합니다. 고맙습니다. 나는 해결책 2와 함께 갔다. 그리고 설명에 감사드립니다. 그게 문제가 어디에서 왔는지 알았지 만, 어떻게 그리고 왜 제대로 파악하지 못했습니다. – Trido