Answered by:
Access to page for specific users only

Question
-
User810354248 posted
In my asp.net+VB=SQL
My basic requirement is if user is nothing then redirect to login.aspx
after login when the user reaches terms.aspx then
If user NOT =baijuep or User NOT = pooja then
redirect to task_.aspx
i was using this code and it is not working. I dont know where i am wrong
login.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim uid As String = txtUserId.Text Dim pwd As String = txtPassword.Text Dim con As New SqlConnection(Str) Dim cmd As New SqlCommand("FIND_USER", con) cmd.CommandType = Data.CommandType.StoredProcedure cmd.Parameters.AddWithValue("@userid", uid) cmd.Parameters.AddWithValue("@password", pwd) Dim rdr As SqlDataReader Try con.Open() rdr = cmd.ExecuteReader() If rdr.HasRows() = True Then While (rdr.Read()) Session("userid") = rdr("userid") Session("sect") = rdr("sect") Dim url As String = Request.QueryString("url") If Not String.IsNullOrEmpty(url) Then Response.Redirect(Server.UrlDecode(url)) End If End While End If Catch ex As Exception Response.Write(Err.Description) Finally con.Close() End Try End Sub
Terms.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Session("userid") = Nothing Then Response.Redirect("login.aspx?Url=" & Server.UrlEncode(Request.Url.AbsoluteUri)) End If usertxt.Text = Session("userid") dttxt.Text = DateTime.Now.ToString("dd-MMM-yyyy") If Session("userid") <> "baijuep" Or Session("userid") <> "pooja" Then Response.Redirect("err.aspx") End If If RadioButtonList1.SelectedValue = "0" Then Panel1.Visible = True Else Panel1.Visible = False End If If RadioButtonList1.SelectedValue = "1" Then Panel2.Visible = True Else Panel2.Visible = False End If End Sub
Thursday, September 28, 2017 11:10 AM
Answers
-
User475983607 posted
The condition should be written like so...
If NOT (Session("userid") = "baijuep" Or Session("userid") = "pooja") Then Response.Redirect("err.aspx") End If
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 28, 2017 11:47 AM -
User475983607 posted
This is a new issue that has nothing to do with your original question.
The error is very clear.
Compiler Error Message: BC30456: 'Description' is not a member of 'err'.
Perhaps change the code to the following as there is no indication where Err is defined in the code you provided.
End If Catch ex As Exception Response.Write(ex.Message) Finally con.Close()
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 28, 2017 12:58 PM
All replies
-
User475983607 posted
The condition should be written like so...
If NOT (Session("userid") = "baijuep" Or Session("userid") = "pooja") Then Response.Redirect("err.aspx") End If
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 28, 2017 11:47 AM -
User810354248 posted
Thanks for reply
In my default page i had given this code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then If Session("userId") Is Nothing Then Response.Redirect("login.aspx") End If End If End Sub
Default page directs to login.aspx
Now this error comes. on page load.
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30456: 'Description' is not a member of 'err'. Source Error: Line 29: End If Line 30: Catch ex As Exception Line 31: Response.Write(Err.Description) Line 32: Finally Line 33: con.Close()
Source File: J:\Projects\ABC\login.aspx.vb Line: 31 Show Detailed Compiler Output: C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_global.asax.khzcdiii.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\assembly\dl3\35a9a193\00f19e47_48f6ce01\ASPNetSpell.dll" /R:"C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_p5rmqmtm.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Code.u3tyyrwm.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Web.PageInspector.Loader\v4.0_1.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Web.PageInspector.Loader.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Web.Entity.dll" /out:"C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.dll" /debug- /win32resource:"C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\hvsqzs1o.res" /nowarn:41008,40000,40008 /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Collections.Specialized,System.ComponentModel.DataAnnotations,System.Configuration,System.Linq,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.DynamicData,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls,System.Xml.Linq /warnaserror- /optionInfer+ "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.13.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.10.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.11.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.16.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.17.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.14.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.15.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.7.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.8.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.30.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.0.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.29.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.18.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.22.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.2.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.20.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.5.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.23.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.27.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.24.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.25.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.4.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.9.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.1.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.6.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.26.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.3.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.19.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.21.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.28.vb" "C:\Users\shreya\AppData\Local\Temp\Temporary ASP.NET Files\mceme_dak_280917\f0d80ed0\ffe58c56\App_Web_hvsqzs1o.12.vb" Microsoft (R) Visual Basic Compiler version 11.0.50938.18408 Copyright (c) Microsoft Corporation. All rights reserved. J:\Projects\ABC\login.aspx.vb(31) : error BC30456: 'Description' is not a member of 'err'. Response.Write(Err.Description) ~~~~~~~~~~~~~~~ J:\Projects\ABC\login1.aspx.vb(29) : error BC30456: 'Description' is not a member of 'err'. Response.Write(Err.Description) ~~~~~~~~~~~~~~~ Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408
I had noticed it earlier also when a link is clicked by user and then redirected to login.aspx it never gives error. If automatically redirected then this error comes.
Login.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim uid As String = txtUserId.Text Dim pwd As String = txtPassword.Text Dim con As New SqlConnection(Str) Dim cmd As New SqlCommand("FIND_USER", con) cmd.CommandType = Data.CommandType.StoredProcedure cmd.Parameters.AddWithValue("@userid", uid) cmd.Parameters.AddWithValue("@password", pwd) Dim rdr As SqlDataReader Try con.Open() rdr = cmd.ExecuteReader() If rdr.HasRows() = True Then While (rdr.Read()) Session("userid") = rdr("userid") Session("sect") = rdr("sect") Dim url As String = Request.QueryString("url") If Not String.IsNullOrEmpty(url) Then Response.Redirect(Server.UrlDecode(url)) End If End While End If Catch ex As Exception Response.Write(Err.Description) Finally con.Close() End Try End Sub End Class
When i remove the below code from login.aspx. It work but never goes to page which was requested.
Dim url As String = Request.QueryString("url") If Not String.IsNullOrEmpty(url) Then Response.Redirect(Server.UrlDecode(url)) End If
Thursday, September 28, 2017 12:04 PM -
User475983607 posted
This is a new issue that has nothing to do with your original question.
The error is very clear.
Compiler Error Message: BC30456: 'Description' is not a member of 'err'.
Perhaps change the code to the following as there is no indication where Err is defined in the code you provided.
End If Catch ex As Exception Response.Write(ex.Message) Finally con.Close()
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, September 28, 2017 12:58 PM