Thursday, March 29, 2012
Server side variables (e.g. $_SERVER['REMOTE_ADDR']) - dotNet equivalent?
For example in PHP, one such predefined variable is: $_SERVER['REMOTE_ADDR']"Frank Moyles" <fgmoyles@.nospam.com> wrote in message
news:ceKdne8KddpqoenaRVnyjwA@.bt.com...
> What is the equivalent for retrieving server side variables?
> For example in PHP, one such predefined variable is:
> $_SERVER['REMOTE_ADDR']
string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"].ToString();
Mark Rae
ASP.NET MVP
http://www.markrae.net
"Gran Andersson" <guffa@.guffa.com> wrote in message
news:uIV97CVSIHA.4584@.TK2MSFTNGP03.phx.gbl...
> The ServerVariables collection is a collection of strings, so just do:
> string strRemoteAddr = Request.ServerVariables["REMOTE_ADDR"];
> Besides, the collection returns null if there is no item by the specified
> name, and calling ToString on a null reference causes an exception.
You're quite correct - I should have been more specific.
Mark Rae
ASP.NET MVP
http://www.markrae.net
Monday, March 26, 2012
Server Transfer
SearchResults.aspx and I want to pass a variable named strSearch.
So far I have:
Dim strSearch as string
strSearch = tbSearch.text
Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch ")
It is throwing this error:
Compiler Error Message: BC30648: String constants must end with a
double quote
I do not understand. Help anyone?Here's a nice, simple way to pass values from one page to another:
(VB.NET code)
'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")
Then, in WebForm2.aspx:
'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)
Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/i...te/default.aspx
http://www.aspalliance.com/kenc/passval.aspx
http://www.dotnetbips.com/displayarticle.aspx?id=79
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Sparky Arbuckle" <twa@.secureroot.com> wrote in message
news:1108528696.261435.215090@.f14g2000cwb.googlegroups.com...
>I want to transfer to a search page from my default page to
> SearchResults.aspx and I want to pass a variable named strSearch.
> So far I have:
> Dim strSearch as string
> strSearch = tbSearch.text
> Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch ")
> It is throwing this error:
> Compiler Error Message: BC30648: String constants must end with a
> double quote
> I do not understand. Help anyone?
>
anyone else got any suggestions?
Hi,
Your Server.Transfer line should be: -
Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch)
HTH
regards
Joyjit
"Sparky Arbuckle" <twa@.secureroot.com> wrote in message
news:1108528696.261435.215090@.f14g2000cwb.googlegroups.com...
> I want to transfer to a search page from my default page to
> SearchResults.aspx and I want to pass a variable named strSearch.
> So far I have:
> Dim strSearch as string
> strSearch = tbSearch.text
> Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch ")
> It is throwing this error:
> Compiler Error Message: BC30648: String constants must end with a
> double quote
> I do not understand. Help anyone?
>
On 15 Feb 2005, "Sparky Arbuckle" <twa@.secureroot.com> postulated in
news:1108532798.517363.148550@.c13g2000cwb.googlegroups.com:
> anyone else got any suggestions?
>
Why the extra quote at the end of the line?
-- ip
Server Transfer
SearchResults.aspx and I want to pass a variable named strSearch.
So far I have:
Dim strSearch as string
strSearch = tbSearch.text
Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch ")
It is throwing this error:
Compiler Error Message: BC30648: String constants must end with a
double quote
I do not understand. Help anyone?Here's a nice, simple way to pass values from one page to another:
(VB.NET code)
'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")
Then, in WebForm2.aspx:
'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)
Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/i...te/default.aspx
http://www.aspalliance.com/kenc/passval.aspx
http://www.dotnetbips.com/displayarticle.aspx?id=79
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Sparky Arbuckle" <twa@.secureroot.com> wrote in message
news:1108528696.261435.215090@.f14g2000cwb.googlegr oups.com...
>I want to transfer to a search page from my default page to
> SearchResults.aspx and I want to pass a variable named strSearch.
> So far I have:
> Dim strSearch as string
> strSearch = tbSearch.text
> Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch ")
> It is throwing this error:
> Compiler Error Message: BC30648: String constants must end with a
> double quote
> I do not understand. Help anyone?
anyone else got any suggestions?
Hi,
Your Server.Transfer line should be: -
Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch)
HTH
regards
Joyjit
"Sparky Arbuckle" <twa@.secureroot.com> wrote in message
news:1108528696.261435.215090@.f14g2000cwb.googlegr oups.com...
> I want to transfer to a search page from my default page to
> SearchResults.aspx and I want to pass a variable named strSearch.
> So far I have:
> Dim strSearch as string
> strSearch = tbSearch.text
> Server.Transfer("SearchBrowse.aspx?strSearch=" & strSearch ")
> It is throwing this error:
> Compiler Error Message: BC30648: String constants must end with a
> double quote
> I do not understand. Help anyone?
On 15 Feb 2005, "Sparky Arbuckle" <twa@.secureroot.com> postulated in
news:1108532798.517363.148550@.c13g2000cwb.googlegr oups.com:
> anyone else got any suggestions?
Why the extra quote at the end of the line?
-- ip
Saturday, March 24, 2012
Server Variable in Client Script
I am trying to pass a variable from my VB asp.net script (from for example
Sub Page_Load in mypage.aspx.vb) to my Client side script.
I have found and looked at a very good example "Client and Server Scripting
in Web Pages" but it only shows server side scripting that is written in
HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
variable value from mypage.aspx.vp to my client side script?
Sample from "Client and Server Scripting in Web Pages"
<%@dotnet.itags.org. LANGUAGE="VBSCRIPT" %
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY
<% Dim strMyServerVar
strMyServerVar = 42 %>
.......
The following line of HTML was generated on the client to print the value of
a client variable into the page after the page was sent to the browser. The
value of the client variable has been set equal to the value of the server
variable printed above.
<BR>
<BR>
<SCRIPT LANGUAGE = "JavaScript">
<!--
var x ;
x = <%= strMyServerVar %> ;
if (x == <%= strMyServerVar%>) {
document.write ("<STRONG>The value of the client variable is " + x +
".</STRONG>")
}
//
-->
</SCRIPTFew ways... build your clientside script dynamically from within your server
side script, passing in the values.
Also, could always put the values in a hidden text box and have the
clientside pull from that.
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Bob,
Why would you do this?
The whole point of using a code behind page is so that the programming logic
can be separated from the display. Placing the programming logic in both
places defeats one of the best things about .NET.
Just Dim your variable in the code behind and you're done.
Move this line to the code behind page like this:
Public Class WebForm1
Inherits System.Web.UI.Page
Public strMyServerVar As String = "42"
'--Rest of page code below
And remove the variable declaration from the .aspx page altogether:
Delete This: <% Dim strMyServerVar strMyServerVar = 42 %
Your code will still work the same way. The .aspx page will have access to
the variable because it's declared as Public (you could also declare it as
Protected or Protected Friend)
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
Free code library at:
www.aboutfortunate.com
"Out of chaos comes order."
Nietzche
"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Bob,
Just a quick note. My previous message shows how to do what you want, but I
shouldn't have included the "Why would you do this?" at the top of the
message.
I misunderstood part of your question.
Still, the code I provided does what you need.
Happy programming!
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
Free code library at:
www.aboutfortunate.com
"Out of chaos comes order."
Nietzche
"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Thanks all
The rec from S. Justin Gengo works fine. I felt there was a simple way.
Bob T
"Bob T" <twick10@.hotmail.com> wrote in message
news:e9G7ajs1DHA.2604@.TK2MSFTNGP09.phx.gbl...
> Hi All,
> I am trying to pass a variable from my VB asp.net script (from for example
> Sub Page_Load in mypage.aspx.vb) to my Client side script.
> I have found and looked at a very good example "Client and Server
Scripting
> in Web Pages" but it only shows server side scripting that is written in
> HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a
> variable value from mypage.aspx.vp to my client side script?
>
> Sample from "Client and Server Scripting in Web Pages"
> <%@. LANGUAGE="VBSCRIPT" %>
> <HTML>
> <HEAD>
> <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
> <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
> <TITLE>Document Title</TITLE>
> </HEAD>
> <BODY>
> <% Dim strMyServerVar
> strMyServerVar = 42 %>
> ......
> The following line of HTML was generated on the client to print the value
of
> a client variable into the page after the page was sent to the browser.
The
> value of the client variable has been set equal to the value of the server
> variable printed above.
> <BR>
> <BR>
> <SCRIPT LANGUAGE = "JavaScript">
> <!--
> var x ;
> x = <%= strMyServerVar %> ;
> if (x == <%= strMyServerVar%>) {
> document.write ("<STRONG>The value of the client variable is " + x +
> ".</STRONG>")
> }
> //
> -->
> </SCRIPT>
Server Variable
But on a more general level I would like know a simply command to see all the available server variables on a server with dot.net.
Thanks !!Are you talking about the ServerVariables?
(request.ServerVariables)
There's a whole list of possible items there - - -
All you need to do is to turn on Tracing on your page, and you can see all of them at work.
Excellent --
Request.ServerVariables that is what I was looking for.
However, What does turn on tracing mean? Is that something I do like define the language?
Thanks --
To turn on tracing, go to your page's <@.page directive and add Trace="true", then run the page. You'll see what it does.
Server Variables and IP addresses??
Thank you againIf you want to be able to identify users each time they come to your site, you either need to give them a cookie with a unique value, or have them identify themselves by logging into your site. (A cookie is a small file with values which you send to the browser and ask the browser to send back to you when they re-visit your site.)
As you noted, users don't consistently have the same IP address. Basically, IP addresses are sold off to ISPs and businesses and are handed out to users as they connect to the network, making sure that no two users have the same IP at the same time. The number is just a unique value allowing you to communicate with the particular computer which has the address assigned. Each IP address is a 32-bit value, which we write as 4 8-bit values separated by periods to make them easier to read (192.168.115.30).
Hope this helps,
-Scott
Server.execute
I face a problem
is it possible to access an asp/vbscript variable created in the parent by t
he child in the server.execute.
If so an example block.
TIA.
Raj.going to have to either pass it (form, querystring) or store it and read it
back in (application var, db, cookie, session, etc).
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Raj" <Raj@.discussions.microsoft.com> wrote in message
news:19B6E194-6F51-4EBC-8AD2-CA3330F22E89@.microsoft.com...
> Hi,
> I face a problem
> is it possible to access an asp/vbscript variable created in the parent by
the child in the server.execute.
> If so an example block.
> TIA.
> Raj.
Tuesday, March 13, 2012
Server.MapPath in Global.asax
in an application variable the path of my database. Global.asax is in the
root directory of my web folder and database is in database/database.mdb.
Now, if I start my web site from default.aspx in the root folder all is ok,
but if start it with a page in a nested folder Global.asax can't find the
folder because Server.MapPath use the relative path of nested folder as base
for its search.
What can I do?
Many thanks
SebastianoUse an absolute path for the Server.MapPath argument such as
~/database/database.mdb instead of just database/database.mdb
Patrice
"Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
>
try to use Request.PhysicalApplicationPath to combine path
Thanks.
Lostinet (MS ASP.NET MVP)
lostinetweb@.hotmail.com
--
Need MessageBox,ComboBox,DatePicker,PasswordB
ox,TreeView,ASP.Net RPC ?
http://www.lostinet.com/
"Sebastiano" <info@.sebastianogazzola.it> д?
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
>
Thank you so much, I can't understand why MS did not mention the importance
of the "~" symbol in the path request. I have waisted hours trying to look
for documentation.
- Rashad
"Patrice" <nobody@.nowhere.com> wrote in message
news:upo4Do6IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> Use an absolute path for the Server.MapPath argument such as
> ~/database/database.mdb instead of just database/database.mdb
> Patrice
> "Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
> news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> save
the
database/database.mdb.
> ok,
the
> base
>
Server.MapPath in Global.asax
in an application variable the path of my database. Global.asax is in the
root directory of my web folder and database is in database/database.mdb.
Now, if I start my web site from default.aspx in the root folder all is ok,
but if start it with a page in a nested folder Global.asax can't find the
folder because Server.MapPath use the relative path of nested folder as base
for its search.
What can I do?
Many thanks
SebastianoUse an absolute path for the Server.MapPath argument such as
~/database/database.mdb instead of just database/database.mdb
Patrice
"Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
try to use Request.PhysicalApplicationPath to combine path
--
Thanks.
Lostinet (MS ASP.NET MVP)
lostinetweb@.hotmail.com
--------
Need MessageBox,ComboBox,DatePicker,PasswordBox,TreeVie w,ASP.Net RPC ?
http://www.lostinet.com/
"Sebastiano" <info@.sebastianogazzola.it> д?
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
Thank you so much, I can't understand why MS did not mention the importance
of the "~" symbol in the path request. I have waisted hours trying to look
for documentation.
- Rashad
"Patrice" <nobody@.nowhere.com> wrote in message
news:upo4Do6IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> Use an absolute path for the Server.MapPath argument such as
> ~/database/database.mdb instead of just database/database.mdb
> Patrice
> "Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
> news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> > I want to use Server.MapPath function in Global.asax because I want to
> save
> > in an application variable the path of my database. Global.asax is in
the
> > root directory of my web folder and database is in
database/database.mdb.
> > Now, if I start my web site from default.aspx in the root folder all is
> ok,
> > but if start it with a page in a nested folder Global.asax can't find
the
> > folder because Server.MapPath use the relative path of nested folder as
> base
> > for its search.
> > What can I do?
> > Many thanks
> > Sebastiano