473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Please Help!

Guys I need your help on this.

I have this one problem and I admitted I am a novice at this. This is a Code
Behind in an aspx page. You will see where I have the plus signs below in
SecureQueryString2.vb where I am calling another Class called
"InvalidQueryStringException". My problem is where do I put this code so it
can be called from SecureQueryString2.vb. I have tried to put it in the same
code behind SecureQueryString2.vb and I get errors. How should I do this to
make it work and also check my .ASPX page to make sure I and referencing it
correctlly. Thanks for your help in advance.

Here is the code for InvalidQueryStringException:
==============================
Public Class InvalidQueryStringException
Inherits System.Exception
End Class
==============================

Code Behind named: SecureQueryString2.vb
==============================
Imports System
Imports System.Collections.Specialized
Imports System.Security.Cryptography
Imports System.Text
Imports System.Web

Namespace dma

Public Class SecureQueryString
Inherits NameValueCollection
Private Const cryptoKey As String = "test"
Private ReadOnly IV As Byte() = New Byte(7) {240, 3, 45, 29, 0, 76,
173, 59}

Sub New()
End Sub

Sub New(ByVal encStr As String)
deserialize(Decrypt(encStr))
End Sub

Public ReadOnly Property EncryptedString() As String
Get
Return HttpUtility.UrlEncode(Encrypt(Serialize()))
End Get
End Property

Public Overrides Function ToString() As String
Return EncryptedString
End Function

Private Function Encrypt(ByVal serQS As String) As String
Dim buffer As Byte() = Encoding.ASCII.GetBytes(serQS)
Dim des As TripleDESCryptoServiceProvider = New
TripleDESCryptoServiceProvider
Dim md5 As MD5CryptoServiceProvider = New
MD5CryptoServiceProvider
des.Key =
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(crypt oKey))
des.IV = IV
Return
Convert.ToBase64String(des.CreateEncryptor.Transfo rmFinalBlock(buffer, 0,
buffer.Length))
End Function

Private Function Decrypt(ByVal encQS As String) As String
Try
Dim buffer As Byte() = Convert.FromBase64String(encQS)
Dim des As TripleDESCryptoServiceProvider = New
TripleDESCryptoServiceProvider
Dim MD5 As MD5CryptoServiceProvider = New
MD5CryptoServiceProvider
des.Key =
MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(crypt oKey))
des.IV = IV
Return
Encoding.ASCII.GetString(des.CreateDecryptor().Tra nsformFinalBlock(buffer,
0, buffer.Length()))
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++
Catch ex As CryptographicException
Throw New InvalidQueryStringException
Catch ex As FormatException
Throw New InvalidQueryStringException
++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++
End Try
End Function

Private Sub Deserialize(ByVal decQS As String)
Dim nameValuePairs As String() = decQS.Split("&")
Dim i As Integer
For i = 0 To nameValuePairs.Length - 1
Dim nameValue As String() = nameValuePairs(i).Split("=")
If nameValue.Length = 2 Then
Me.Add(nameValue(0), nameValue(1))
End If
Next
End Sub

Private Function Serialize() As String
Dim sb As StringBuilder = New StringBuilder
Dim key As String
For Each key In Me.AllKeys
sb.Append(key)
sb.Append("=")
sb.Append(Me(key))
sb.Append("&")
Next key
Return sb.ToString
End Function

End Class
End Namespace

Here is my .ASPX page code:
====================

<%@ Page language="VB" src="SecureQueryString2.vb" AutoEventWireup="false"
Inherits="SecureQueryString" %>
<%@ Import Namespace="dma" %>

<script language="VB" runat="server">
'Sending page
Dim qs
qs = new SecureQueryString()
qs("Name") = "Test"
qs("Phone") = "704-822-8999"
Response.Redirect("Data2.aspx?x=" + qs.ToString())
</script >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

--
Thanks,


Mar 29 '06 #1
6 2503
you shouldn't have a problem with this code -- as long as you're
properly referencing whatever namespace your
"InvalidQueryStringException" class is defined within. if you want,
you can put it in the same codebehind file, within your "dma"
namespace, and this code should work fine... otherwise, if it's in a
different namespace, you'd have to reference it accordingly within your
codebehind. e.g.:

=======================
SecureQueryString2.vb
=======================

Namespace dma
Public Class InvalidQueryStringException Inherits System.Exception
End Class

Public Class SecureQueryString
...
Throw New InvalidQueryStringException
...
End Class
End Namespace
--- OR ---
=======================
Functions.vb
=======================

Namespace dmaFunctions
Public Class InvalidQueryStringException Inherits System.Exception
End Class
End Namespace

=======================
SecureQueryString2.vb
=======================

Imports dmaFunctions

Namespace dma
Public Class SecureQueryString
...
Throw New InvalidQueryStringException
// OR "Throw New dmaFunctions.InvalidQueryStringException",
// if you don't include "Imports dmaFunctions"
...
End Class
End Namespace
HTH,
Luke

Mar 29 '06 #2
Luke, I want to say thank you for helping me with this, I really appricaite
it. I tried the first option and then run the DATA.ASPX file below and I got
this error. It doesn't make sense. SecureQueryString2.vb is in the same
folder with DATA.ASPX.
Server Error in '/' Application.
--------------------------------------------------------------------------------

Parser Error
Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: The base type 'SecureQueryString' does not exist in
the source file 'SecureQueryString2.vb'.

Source Error:
Line 1: <%@ Page language="VB" src="SecureQueryString2.vb"
AutoEventWireup="false" Inherits="SecureQueryString" %>
Line 2: <%@ Import Namespace="dma" %>
Line 3:
Source File: d:\inetpub\wwwroot\websites\specialk\test\Data.asp x Line: 1

--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032
+++++++++++++++++++++++++++
Here is the code for DATA.ASPX:+
+++++++++++++++++++++++++++

<%@ Page language="VB" src="SecureQueryString2.vb" AutoEventWireup="false"
Inherits="SecureQueryString" %>
<%@ Import Namespace="dma" %>

<script language="VB" runat="server">
'Sending page
Dim qs
qs = new SecureQueryString()
qs("Name") = "Test"
qs("Phone") = "777-888-9999"
Response.Redirect("Data2.aspx?x=" + qs.ToString())
</script >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>

Any idea why this is not working?

Thanks.


"slagomite" <sl*******@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
you shouldn't have a problem with this code -- as long as you're
properly referencing whatever namespace your
"InvalidQueryStringException" class is defined within. if you want,
you can put it in the same codebehind file, within your "dma"
namespace, and this code should work fine... otherwise, if it's in a
different namespace, you'd have to reference it accordingly within your
codebehind. e.g.:

=======================
SecureQueryString2.vb
=======================

Namespace dma
Public Class InvalidQueryStringException Inherits System.Exception
End Class

Public Class SecureQueryString
...
Throw New InvalidQueryStringException
...
End Class
End Namespace
--- OR ---
=======================
Functions.vb
=======================

Namespace dmaFunctions
Public Class InvalidQueryStringException Inherits System.Exception
End Class
End Namespace

=======================
SecureQueryString2.vb
=======================

Imports dmaFunctions

Namespace dma
Public Class SecureQueryString
...
Throw New InvalidQueryStringException
// OR "Throw New dmaFunctions.InvalidQueryStringException",
// if you don't include "Imports dmaFunctions"
...
End Class
End Namespace
HTH,
Luke

Mar 30 '06 #3
Hrm, not sure why the error says it doesn't exist -- but the true
problem probably lies in the fact that your ASPX page is inheriting
from a class that does not inherit from System.Web.UI.Page (I didn't
notice this problem before). In your ASPX page, you want to inherit a
page class, something like:

<%@ Page Language="VB" src="Data.aspx.cs" AutoEventWireup="False"
Inherits="Data" %>

and in your the Data.aspx.cs codebehind file:

Public Class Data Inherits System.Web.UI.Page
...
End Class

ASPX pages need to inherit from a class that inherits from
System.Web.UI.Page. In other words, your ASPX page shouldn't be
*extending* your SecureQueryString() class -- it should just be *using*
it.

HTH
Luke

Mar 30 '06 #4
I took out the "Inherits NameValueCollection" and replaced it with "Inherits
System.Web.UI.Page" and tried to execute it. I got a server error. But when
I change it back I still get the previous error.

Server Error in '/' Application.
--------------------------------------------------------------------------------

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: 'Add' is not a member of
'System.Web.UI.Page'.

Source Error:
Line 86: Dim nameValue As String() = nameValuePairs(i).Split("=")
Line 87: If nameValue.Length = 2 Then
Line 88: MyBase.Add(nameValue(0), nameValue(1))
Line 89: End If
Line 90:
System.Math.Min(System.Threading.Interlocked.Incre ment(i),i-1)

Source File: d:\inetpub\wwwroot\websites\specialk\test\SecureQu eryString.vb
Line: 88
"slagomite" <sl*******@gmail.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Hrm, not sure why the error says it doesn't exist -- but the true
problem probably lies in the fact that your ASPX page is inheriting
from a class that does not inherit from System.Web.UI.Page (I didn't
notice this problem before). In your ASPX page, you want to inherit a
page class, something like:

<%@ Page Language="VB" src="Data.aspx.cs" AutoEventWireup="False"
Inherits="Data" %>

and in your the Data.aspx.cs codebehind file:

Public Class Data Inherits System.Web.UI.Page
...
End Class

ASPX pages need to inherit from a class that inherits from
System.Web.UI.Page. In other words, your ASPX page shouldn't be
*extending* your SecureQueryString() class -- it should just be *using*
it.

HTH
Luke

Mar 30 '06 #5
No. Don't change the inheritance of the SecureQueryString class --
change the inheritance of your page class, in the @Page directive --
the value of the "Inherits" attribute should match the name of your
codebehind class.

Please take another look at the code I wrote out in my last post.

Luke

Apr 4 '06 #6
Also, please note that your ASPX page should *not* use the
SecureQueryString class as its codebehind -- SecureQueryString should
just be a stand-alone class; you should have *another* class as your
codebehind (the name of the file which contains it should be the the
name of your ASPX page, with ".vb" appended -- e.g., if your ASPX page
is called "Data.aspx", your codebehind file should be called
"Data.aspx.vb", and the name of the codebehind class in that file
should be "Data").

Visual Studio should have created such a codebehind file for you -- to
view it, right-click somewhere in your HTML view of the ASPX page, and
click "View Code".

HTH,
Luke

Apr 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
0
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
5
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.