473,378 Members | 1,619 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,378 software developers and data experts.

URL encoding in global.asax

SMG
Hi All,
I want to do url encoding, can I do this in global.asax once for all?

Suppose someone request for a url http://localhost/test/test.aspx?ID=M&M

and I want my web server to do understand the url as
http://localhost/test/test.aspx?ID=M%26M

Regards,
Shailesh Gajare
Nov 19 '05 #1
6 3433
One of the "seems to be silly" way to do so is to store the URL in session,
so it becomes something like:

HttpContext.Current.Session =
HttpUtility.UrlEncode(HttpContext.Current.Request. RawUrl);

Note: I've not verify the above code so there may be typos.

See if others have better way.

Anyway, why do you want such function? You could have a global variable on
the pages that need this and encode it on Page_Load() eventhandler...

"SMG" <SM*@nodmain.com> ¼¶¼g©ó¶l¥ó·s»D:uQ**************@TK2MSFTNGP09.phx.g bl...
Hi All,
I want to do url encoding, can I do this in global.asax once for all?

Suppose someone request for a url http://localhost/test/test.aspx?ID=M&M

and I want my web server to do understand the url as
http://localhost/test/test.aspx?ID=M%26M

Regards,
Shailesh Gajare

Nov 19 '05 #2
SMG
Please go though this...
*******************************
Hi All,
I have created an application which is working fine and is in about to
launch, now suddenly my mgmt says there are chances that Scrip ID( a
particular id and not prim key) may have special characters like '&,*,),(
or/'

This data(field/key) I am passing this value as a querystring. e.g.

value to be passed : ABC
http://localhost/myProj/abc.aspx?ScripID=ABC
this works fine,

But when I have special characters like [ABC&D] then the value retrieved is
wrong it just retrieves ABC and not complete ID [ABC&D]
value to be passed : ABC&D
http://localhost/myProj/abc.aspx?ScripID=ABC&D

how do I overcome this, I know I can do it like we have %20 for space and
like wise for & there will be something, but this will be a major change to
my application, can I do this at one end some where in web.config or in aspx
page?

Regards,
Shailesh Gajare
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:ut**************@TK2MSFTNGP15.phx.gbl...
One of the "seems to be silly" way to do so is to store the URL in session,
so it becomes something like:

HttpContext.Current.Session =
HttpUtility.UrlEncode(HttpContext.Current.Request. RawUrl);

Note: I've not verify the above code so there may be typos.

See if others have better way.

Anyway, why do you want such function? You could have a global variable on
the pages that need this and encode it on Page_Load() eventhandler...

"SMG" <SM*@nodmain.com>
¼¶¼g©ó¶l¥ó·s»D:uQ**************@TK2MSFTNGP09.phx.g bl...
Hi All,
I want to do url encoding, can I do this in global.asax once for all?

Suppose someone request for a url http://localhost/test/test.aspx?ID=M&M

and I want my web server to do understand the url as
http://localhost/test/test.aspx?ID=M%26M

Regards,
Shailesh Gajare

Nov 19 '05 #3
In that way I suggest you to decode the raw url yourself instead of relying
on Request.QueryString(), I believe the QueryString is already decoded at
the time of BeginRequest...

If you are the one who prepare those URLs, of course you can supply the %XX
style character at the string in the beginning (you can always find the
ascii byte values using CharacterMap located in Accessories -> System
Tools.)

If you are passing them in forms, use POST instead of GET will give you
better chance of doing so.

Sorry for not having good suggestion to tell, but your mgmt really shouldn't
allow characters other than alphanumeric and '_', other chacracters are
likely to case problems in one program or the others. (consider SQL strings
in DB applications)

"SMG" <SM*@nodmain.com> ¼¶¼g©ó¶l¥ó·s»D:%2***************@tk2msftngp13.phx. gbl...
Please go though this...
*******************************
Hi All,
I have created an application which is working fine and is in about to
launch, now suddenly my mgmt says there are chances that Scrip ID( a
particular id and not prim key) may have special characters like '&,*,),(
or/'

This data(field/key) I am passing this value as a querystring. e.g.

value to be passed : ABC
http://localhost/myProj/abc.aspx?ScripID=ABC
this works fine,

But when I have special characters like [ABC&D] then the value retrieved
is
wrong it just retrieves ABC and not complete ID [ABC&D]
value to be passed : ABC&D
http://localhost/myProj/abc.aspx?ScripID=ABC&D

how do I overcome this, I know I can do it like we have %20 for space and
like wise for & there will be something, but this will be a major change
to
my application, can I do this at one end some where in web.config or in
aspx
page?

Regards,
Shailesh Gajare
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:ut**************@TK2MSFTNGP15.phx.gbl...
One of the "seems to be silly" way to do so is to store the URL in
session,
so it becomes something like:

HttpContext.Current.Session =
HttpUtility.UrlEncode(HttpContext.Current.Request. RawUrl);

Note: I've not verify the above code so there may be typos.

See if others have better way.

Anyway, why do you want such function? You could have a global variable on
the pages that need this and encode it on Page_Load() eventhandler...

"SMG" <SM*@nodmain.com>
¼¶¼g©ó¶l¥ó·s»D:uQ**************@TK2MSFTNGP09.phx.g bl...
Hi All,
I want to do url encoding, can I do this in global.asax once for all?

Suppose someone request for a url http://localhost/test/test.aspx?ID=M&M

and I want my web server to do understand the url as
http://localhost/test/test.aspx?ID=M%26M

Regards,
Shailesh Gajare


Nov 19 '05 #4

I would suggest you test the Server.URLEncode method that deals with
your problem. Something like:
Response.Redirect("http://localhost/myProj/abc.aspx?ScripID=" &
Server.URLEncode(ABC&D))

Regards,

Michel
Nov 19 '05 #5

I would suggest you test the Server.URLEncode method that deals with
your problem. Something like:
Response.Redirect("http://localhost/myProj/abc.aspx?ScripID=" &
Server.URLEncode(ABC&D))

Regards,

Michel
Nov 19 '05 #6
That's right.

Just picking small mistake, it should be UrlEncode("ABC&D")... :)

"Michel Couche" <mi**********@skynet.beREMOVE>
???????:42**************@skynet.beREMOVE...

I would suggest you test the Server.URLEncode method that deals with your
problem. Something like:
Response.Redirect("http://localhost/myProj/abc.aspx?ScripID=" &
Server.URLEncode(ABC&D))

Regards,

Michel

Nov 19 '05 #7

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

Similar topics

22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
12
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.