Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not IsPostBack Then
            If Request.IsAuthenticated Then
                Dim ident As FormsIdentity = CType(User.Identity, FormsIdentity)
                If ident IsNot Nothing Then
                    Dim ticket As FormsAuthenticationTicket = ident.Ticket
                    Dim userDataString As String = ticket.UserData
                    Dim userDataPieces() As String = userDataString.Split("|".ToCharArray())
                    Dim username As String = userDataPieces(1)
                    Dim rolename As String = userDataPieces(2)
                    If rolename <> "Graduate" Then
                        Response.Redirect("~/login.aspx", False)
                    End If
                End If
            Else
                Response.Redirect("~/login.aspx", False)
            End If
            lblerror.Visible = False
            Dim ident1 As FormsIdentity = CType(User.Identity, FormsIdentity)
            Dim ticket1 As FormsAuthenticationTicket = ident1.Ticket
            Dim userDataString1 As String = ticket1.UserData
            Dim userDataPieces1() As String = userDataString1.Split("|".ToCharArray())
            Dim userid As Integer = userDataPieces1(0)
            Dim ds As DataSet

            sqlquery("select offer.offerid as 'Offer ID', companyname + '(' + convert(varchar(50), company.companyid) + ')' as 'Company', request.requestid as 'Request ID', fname + ' ' + lname as 'Student', days as 'Days', minsalary as 'Minimum Salary', maxsalary as 'Maximum Salary' from company, offer, request, requestdetail, users where offer.offerid = requestdetail.offerid and offer.companyid = company.companyid and offer.userid = '" & userid & "' and request.userid = users.userid and request.requestid = requestdetail.requestid;")
            If ds.Tables(0).Rows.Count <> 0 Then
                gvrequestgrad.DataSource = ds.Tables(0)
                gvrequestgrad.DataBind()
                gvrequestgrad.SelectedIndex = -1
            End If 


this code is giving me an error while compiling the error is :

-Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'System.Web.Security.FormsIdentity'.

- Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

-Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Security.Principal.WindowsIdentity' to type 'System.Web.Security.FormsIdentity'.



plz can anyone help me ?

[edit]Code block added, Urgency deleted - OriginalGriff[/edit]
Posted
Updated 3-Sep-13 6:14am
v2
Comments
Ron Beyer 3-Sep-13 12:12pm    
"can anyone help me" Its just a code dump an an error, how about pointing out the line that you get the error on?
Member 10250266 3-Sep-13 18:59pm    
it is all mentioned
OriginalGriff 3-Sep-13 12:14pm    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
Member 10250266 3-Sep-13 19:00pm    
it is for a friend and i didn't know the solution so i know there is bright helpfull people in here so i drop the question
i m sry for annoying you but i m not forcing you to help me
Sergey Alexandrovich Kryukov 3-Sep-13 14:03pm    
It's not cast X to X, it's the cast X to Y.
—SA

This line:
VB
Dim ident As FormsIdentity = CType(User.Identity, FormsIdentity)


Change to:
VB
Dim ident As IPrincipal = CType(User.Identity, IPrincipal)


FormsIdentity cannot be casted / converted from WindowsPrincipal
 
Share this answer
 
Comments
Member 10250266 3-Sep-13 17:56pm    
i try it about ur solution but when i wrote that they give me a another error and underline under of word "ticket and they write that "ticket" isnt a member of 'System.Security.Principal.IPrincipal' so what i should change about definition of "ticket" ?!?!?! and tnx so much jlopez788 "Dim ticket As FormsAuthenticationTicket = ident.Ticket"
onelopez 4-Sep-13 14:01pm    
My suggestion is not to store it in the FormsAuthenticationTicket, instead store that information as a role.

IPrincipal has a function called IsInRole... or something along the lines,

"bool IsInRole(string role)"

the class inheriting from IPrincipal should be able to tell whether or not a user has a "Graduate" role. Thus eliminating the need for the cast
oh i will try it now thank you jlopez788
 
Share this answer
 
Comments
Ron Beyer 3-Sep-13 12:42pm    
Please use the "Have a Question or Comment" box under the answer instead of posting a new answer as a comment, otherwise the poster of the answer won't get a notification of your comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900