Is it possible to change the query string value - asp.net

Let me know Is their any possibility to change the query string value? i have tried
like the following:
Dim tab As Integer = CInt(Request.QueryString("tab"))
Request.QueryString("tab") = ""
but it says System.NotSupportedException: Collection is read-only.. does it means that assigning values to the query string only at the time of redirection using Response.Redirect(----)?
I know i can use session or cookies instead for this.

does it means that assigning values to the query string only at the time of redirection
Yes. The query string comes from the request the browser makes. You can't change a request that is being processed. You'll have to redirect using the new query string values.

HttpRequest.QueryString Property is for Gets the collection of HTTP query string variables. QueryString dos not support set value operation

Related

Can we add multiple values to the same session variable in ASP.net

Is it possible to add multiple values in one session variable ?
In my login page , one session variable is carrying a value, i need to append some other data in same session variable in another page.
In Login.Aspx.Vb
Session.Add("UserKey", "DATA_1_PAGE1 ")
In Dashboard.Aspx.Vb
Session.Add("UserKey", "| DATA_2_PAGE2")
In Process.Aspx.vb
Dim Session_StateValue = HttpContext.Current.Session("UserKey")
In Session_StateValue , I want my values as 'DATA_1_PAGE1| DATA_2_PAGE2'.
Is there any mechanism to append in session variable other than assign to a string and append along with the assigned string once again .
Please advice.
Dealing with strings, you can use List's, Dictionaries, Arrays, String etc.
Simplest way to concatenate string values would likely be
Session.Add("UserKey", "DATA_1_PAGE1")
Session.Add("UserKey", Session("UserKey").ToString() & "| DATA_2_PAGE2")
Dim str As String = Session("UserKey").ToString()
Another way could be using a List(Of String)
Session.Add("key", New List(Of String) From {"string1"})
DirectCast(Session("key"), List(Of String)).Add("string2")
Dim str As String = String.Join("|", DirectCast(Session("key"), List(Of String)).ToArray)
Now, based on how your are going to use it, persistence, serialization, etc., one might be more appropriate than the other.
You can store more than just strings in Session, like DateTime or some Person object that you defined yourself - how would you have the system implement an "append" then that is valid for all sorts of (combinations of) values?
So the only way is to get the original value as string, append the new value yourself and put that combination in Session.
But make sure then when a user happens to submit that second page twice (the user will always find a way...) you don't append that value twice. Maybe it's better to keep it in separate Session values and only combine them when you need the combined value.

Passing a Guid through to another page ASP.NET

I have a Guid loaded with a ID that a user selected from a GridView.
I want to pass this Guid to another page, but i dont know how to append it to the statement below:
Response.Redirect("LicenseDetailsView.aspx?idLicense=" guidLicense)
Here is the full code:
Dim dvrLicense As GridViewRow
Dim guidLicense As Guid
dvrLicense = grdAllUserLicense.SelectedRow
guidLicense = StringToGUID(dvrLicense.Cells(1).Text.ToString)
Response.Redirect("LicenseDetailsView.aspx?idLicense=" guidLicense)
the variable i want to pass is called: guidLicense.
Use a format string:
Response.Redirect(String.Format("LicenseDetailsView.aspx?idLicense={0}", guidLicense))
Or perhaps just concatenate it (though the former is preferred):
Response.Redirect("LicenseDetailsView.aspx?idLicense=" & guidLicense)
The point being that there has to be some operation performed on the two values (the string literal and the variable). Putting them next to each other doesn't mean anything to the compiler. A method call with the values as arguments, or an operator between the values, will instruct the code to do something with those values.

how to get query string parameters from a string? LUA/nginx

i am using lua module inside nginx for routing to a stored string.
The thing i want to do is to change the values of query string parameters from the stored string.
Is there any function which will give me table of query string parameters from a string?
And after changing the values, any function to change the values from the string.
Thanks
I think you're looking for ngx.encode_args and ngx.decode_args respectively.

How to encrypt a Huge query string to in short

I have a huge query string which is around 6000 to 7000 characters, is it possible to encrpyt the string in short?
any alogrithms ?
Usign ASP.NET as the web app.
The short answer is don't do it - it probably indicates you are doing something wrong.
If you have to then I would say the best way would be to store the long query string in a database field and generate a Guid you can store as a key against it.
You can then pass the Guid in the query string and when the page loads you can then retrieve the full details from the database using the key.
The URL accepts 255 character, after that you'll get nothing.
Use what Mr. Kevin mentioned, database storage, or use the context session to store variables you are sending in the query string.

How can I update a database string value from a TextBox?

I cant update my database through textbox.in the case of numeric value i can update but cant with a string value.
my coding is...
SqlCommand cmdup= new SqlCommand("UPDATE [port1] SET [prt1]=#prt1 WHERE [no]= 1",cn);
cmdup.Parameters.Add("#prt1", TextBox1.Text);
cmdup.ExecuteNonQuery();
if any one know the ans: reply me
I'd recommend explicitly defining the parameter type to match the type in the DB, and passing the value to Parameters.Add as the appropriate type.
e.g. at the moment, you are passing a string typed value to Parameters.Add, and not defining the type explicitly. Therefore, it will assume the data type from the type of value supplied...so the #prt1 type will be passed in to the DB as NVARCHAR I believe.
If the prt1 field is an INTEGER for example, much safer IMHO to do something like:
cmd.Parameters.Add("#prt", SqlDbType.Int,4).Value = Int32.Parse(TextBox1.Text);
or
cmd.Parameters.AddWithValue("#prt", Int32.Parse(TextBox1.Text));
I always like to fully define the type of the parameters I pass in to SQL to rule out any potential, unexpected issues.
Check the datatype for the #prt1 to see if it is a Int value because you are setting to the same column two different values.
Parse the textBox to Integer as you want to insert a numeric value i.e. Int64.Parse("Textbox1.Text"); well with string it does have problems.
Just a wild guess: Does prt maybe only accept numeric values?

Resources