Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Saturday, March 24, 2012

Server.execute

Hi,
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.

Server.Execute

Hiyo

I want to perform a programmatic server-side include, and I think that the
best way would be to use Server.Execute(path, optional textwriter).
Certainly ommitting the textwriter means that I can write to the output of
my page.

...however...

The content I wanted to append to the page is aspx code stored in a database
(surely this isn't the best way - suggestions welcome please!), and so I
figure it would be faster to write the code from the database into the aspx
output like this:

<html><body>test starts<br
string dbaspx = Database.ReadSomeField();
// dbaspx == "<aspx:-- some aspx code --/>"
Server.Execute(dbaspx);

<br>test stops</body></html
Kinda an odd scenario; your thoughts welcome :) Thanks in advance,
BenBen hi,

if you keep the data in DB its probebly static so maybe its betteer to
store the data in application cache.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Where is Server.Execute in .NET?

"Natty Gur" <natty@.dao2com.com> wrote in message
news:O00n72KbDHA.2672@.tk2msftngp13.phx.gbl...
> Ben hi,
> if you keep the data in DB its probebly static so maybe its betteer to
> store the data in application cache.
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
It's a method of the HttpServerUtility class. Similar to Server.Transfer,
except that after executing the target page, control returns to the calling
page. It was more in vogue with classic ASP, since classic ASP is
procedural. You could use it to do a "dynamic include" - include content
from another ASP page conditionally. ASP.Net has better mechanisms for such
things, so it isn't used very often.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"MS News (MS ILM)" <sql_agentmans@.hotmail.com> wrote in message
news:%23DlzaXMbDHA.3768@.tk2msftngp13.phx.gbl...
> Where is Server.Execute in .NET?
>
> "Natty Gur" <natty@.dao2com.com> wrote in message
> news:O00n72KbDHA.2672@.tk2msftngp13.phx.gbl...
> > Ben hi,
> > if you keep the data in DB its probebly static so maybe its betteer to
> > store the data in application cache.
> > Natty Gur, CTO
> > Dao2Com Ltd.
> > 34th Elkalay st. Raanana
> > Israel , 43000
> > Phone Numbers:
> > Office: +972-(0)9-7740261
> > Fax: +972-(0)9-7740261
> > Mobile: +972-(0)58-888377
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!

Server.Execute & HttpHandler

My problem is that when I am trying to use
Server.Execute("Somehandler.ashx") I am getting HttpException.
[HttpException (0x80004005): Error executing child request for
Somehandler.ashx.]
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,
TextWriter writer, Boolean preserveForm, Boolean setPreviousPage,
VirtualPath path, VirtualPath filePath, String physPath, Exception
error, String queryStringOverride) +3179617
System.Web.HttpServerUtility.Execute(String path, TextWriter writer,
Boolean preserveForm) +747
System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm) +56
System.Web.HttpServerUtility.Transfer(String path) +26According to the documentation HttpServerUtilty.Execute/Transfer only works
with pages... It simply may not work with handlers, because the redirect is
occurring from within the Page Handler framework. If you want to redirect to
a handler you need a physical redirect with Response.Redirect().
+++ Rick --
Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog
"Sam" <foo@.tempuri.org> wrote in message
news:uQSa$XhAGHA.2736@.TK2MSFTNGP11.phx.gbl...
> My problem is that when I am trying to use
> Server.Execute("Somehandler.ashx") I am getting HttpException.
> [HttpException (0x80004005): Error executing child request for
> Somehandler.ashx.]
> System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,
> TextWriter writer, Boolean preserveForm, Boolean setPreviousPage,
> VirtualPath path, VirtualPath filePath, String physPath, Exception error,
> String queryStringOverride) +3179617
> System.Web.HttpServerUtility.Execute(String path, TextWriter writer,
> Boolean preserveForm) +747
> System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
> +56
> System.Web.HttpServerUtility.Transfer(String path) +26
Rick Strahl [MVP] wrote:
> According to the documentation HttpServerUtilty.Execute/Transfer only work
s
> with pages... It simply may not work with handlers, because the redirect i
s
> occurring from within the Page Handler framework. If you want to redirect
to
> a handler you need a physical redirect with Response.Redirect().
> +++ Rick --
>
I need to save Context.Items and it's impossible to redirect. Anyway my
application need only Server.Execute.
Quote from documentation:
"Executes the handler for the specified virtual path in the context of
the current request."
I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:
...
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
...
handler.ProcessRequest(...) // BUT It's only for Page instances (((
...
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString(" Error_executing_child_request_for_handle
r",
objArray2), error);
Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)
I believe that the issue is that .ashx files are handled by the
SimpleHandlerFactory while .aspx files are handled by the
PageHandlerFactory. As Rick indicated in his post, the SimpleHandlerFactory
does not the redirect process that occurs with the transfer process because
this is embedded within the Page handler. It's not that the IHttpHandler is
prohibited; it's because the simple handler doesn't understand what a page
is necessarily.
Now, what are you trying to attempt using a simple handler file in place of
a page file?
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."
"Sam" <foo@.tempuri.org> wrote in message
news:OH$JUKiAGHA.2736@.TK2MSFTNGP11.phx.gbl...
> Rick Strahl [MVP] wrote:
> I need to save Context.Items and it's impossible to redirect. Anyway my
> application need only Server.Execute.
> Quote from documentation:
> "Executes the handler for the specified virtual path in the context of the
> current request."
> I trust, there is no reason to prohibit IHttpHanlder derived classes.
> See Reflected code of HttpServerUtility.ExecuteInternal:
> ...
> else if (!(handler is Page))
> {
> error = new HttpException(0x194, string.Empty);
> }
> ...
> handler.ProcessRequest(...) // BUT It's only for Page instances (((
> ...
> object[] objArray2 = new object[] { handler.GetType().ToString() } ;
> throw new
> HttpException(SR.GetString(" Error_executing_child_request_for_handle
r",
> objArray2), error);
>
> Just remove this first 3 lines of code from assembly.. but I am not MS
> employee :)
Christopher Reed wrote:
> I believe that the issue is that .ashx files are handled by the
> SimpleHandlerFactory while .aspx files are handled by the
> PageHandlerFactory. As Rick indicated in his post, the SimpleHandlerFacto
ry
> does not the redirect process that occurs with the transfer process becaus
e
> this is embedded within the Page handler. It's not that the IHttpHandler
is
> prohibited; it's because the simple handler doesn't understand what a page
> is necessarily.
> Now, what are you trying to attempt using a simple handler file in place o
f
> a page file?
It's not depended on Handler factories or something else. There is not
necessary ashx or aspx or jpg. It's a bug, and this bug must be fixed.
If method signature is: Server.Execute(IHttpHandler handler, ...) why I
have an exception here? Instead it there must be Server.Execute(Page
page,...) if handlers are prohibied. Is MS afraid that someone inherit
ASP.NET :)?
Please vote bugreport:
http://lab.msdn.microsoft.com/produ...0a-e0dc82b43356
Rick Strahl [MVP] wrote:
> According to the documentation HttpServerUtilty.Execute/Transfer only work
s
> with pages... It simply may not work with handlers, because the redirect i
s
> occurring from within the Page Handler framework. If you want to redirect
to
> a handler you need a physical redirect with Response.Redirect().
> +++ Rick --
>
I need to save Context.Items and it's impossible to direct redirect.
Anyway my
application need only Server.Execute.
Quote from documentation:
"Executes the handler for the specified virtual path in the context of
the current request."
I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:
...
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
...
handler.ProcessRequest(...) // BUT It's only for Page instances (((
...
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString(" Error_executing_child_request_for_handle
r",
objArray2), error);
Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)
Next issue: Why I see the same behaviour with
Server.Execute(IHttphandler handler, ...)? Here is IHttpHandler as
method parameter.. and it don't work anyway. Why not System.Web.Page
instead of IHttpHandler, if handlers are prohibited? True is buried
within 3 lines above.
Quote from docs for HttpServerUtility.Execute(IHttpHandler, TextWriter,
Boolean):
"Executes the current request by using a custom HTTP handler that
implements the IHttpHandler interface. A TextWriter object captures
output from the page and specifies whether to clear the QueryString and
Form collections."
Rick Strahl [MVP] wrote:
> According to the documentation HttpServerUtilty.Execute/Transfer only work
s
> with pages... It simply may not work with handlers, because the redirect i
s
> occurring from within the Page Handler framework. If you want to redirect
to
> a handler you need a physical redirect with Response.Redirect().
> +++ Rick --
>
I need to save Context.Items and it's impossible to direct redirect.
Quote from documentation:
"Executes the handler for the specified virtual path in the context of
the current request."
I trust, there is no reason to prohibit IHttpHanlder derived classes.
See Reflected code of HttpServerUtility.ExecuteInternal:
...
else if (!(handler is Page))
{
error = new HttpException(0x194, string.Empty);
}
...
handler.ProcessRequest(...) // BUT It's only for Page instances (((
...
object[] objArray2 = new object[] { handler.GetType().ToString() } ;
throw new
HttpException(SR.GetString(" Error_executing_child_request_for_handle
r",
objArray2), error);
Just remove this first 3 lines of code from assembly.. but I am not MS
employee :)
Next issue: Why I see the same behaviour with
Server.Execute(IHttphandler handler, ...)? Here is IHttpHandler as
method parameter.. and it don't work anyway. Why not System.Web.Page
instead of IHttpHandler, if handlers are prohibited? True is buried
within 3 lines above.
Quote from docs for HttpServerUtility.Execute(IHttpHandler, TextWriter,
Boolean):
"Executes the current request by using a custom HTTP handler that
implements the IHttpHandler interface. A TextWriter object captures
output from the page and specifies whether to clear the QueryString and
Form collections."

Server.Execute against same page hangs ASP.NET

We have a page which sends a copy of itself via email to customers. To
enable this, the page calls Server.Execute on itself into a text stream and
strips its own output down to HTML presentable to the customer.
In our Test environment (but not our DEV or Local envs) we are experience an
ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot
the server before any of our other ASP.NET apps will work.
This is a sample of the code which appears to be the culprit. We commented
out the Server.Execute and substituted some junk text to build sbText and th
e
code worked fine on our test environment again.
-- Locks server
StringBuilder sb = new StringBuilder();
sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
sb.Append(erNumber);
System.IO.TextWriter textwriter = new System.IO.StringWriter();
StringBuilder sbText = new StringBuilder(textwriter.ToString());
Server.Execute(sb.ToString(), textwriter);
Is there any known issue with Server.Execute on itself?I expect it would just cause a recursive request of the page requesting
server.execute - and hang your server?
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> We have a page which sends a copy of itself via email to customers. To
> enable this, the page calls Server.Execute on itself into a text stream
and
> strips its own output down to HTML presentable to the customer.
> In our Test environment (but not our DEV or Local envs) we are experience
an
> ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
reboot
> the server before any of our other ASP.NET apps will work.
> This is a sample of the code which appears to be the culprit. We
commented
> out the Server.Execute and substituted some junk text to build sbText and
the
> code worked fine on our test environment again.
> -- Locks server
> StringBuilder sb = new StringBuilder();
> sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> sb.Append(erNumber);
> System.IO.TextWriter textwriter = new System.IO.StringWriter();
> StringBuilder sbText = new StringBuilder(textwriter.ToString());
> Server.Execute(sb.ToString(), textwriter);
> Is there any known issue with Server.Execute on itself?
It shouldn't, but I'll look into it.
The call to Server.Execute occurs only within a postback when a button on
the page is pushed to generate the email. As I said, this poses no problem
whatsoever on our local machines (5 developers) or on our development server
environment. Only in our Test env is there an issue.
"John Timney (Microsoft MVP)" wrote:

> I expect it would just cause a recursive request of the page requesting
> server.execute - and hang your server?
> --
> Regards
> John Timney
> Microsoft Regional Director
> Microsoft MVP
>
> "Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in messa
ge
> news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> and
> an
> reboot
> commented
> the
>
>

Server.Execute against same page hangs ASP.NET

We have a page which sends a copy of itself via email to customers. To
enable this, the page calls Server.Execute on itself into a text stream and
strips its own output down to HTML presentable to the customer.

In our Test environment (but not our DEV or Local envs) we are experience an
ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must reboot
the server before any of our other ASP.NET apps will work.

This is a sample of the code which appears to be the culprit. We commented
out the Server.Execute and substituted some junk text to build sbText and the
code worked fine on our test environment again.

-- Locks server
StringBuilder sb = new StringBuilder();
sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
sb.Append(erNumber);
System.IO.TextWriter textwriter = new System.IO.StringWriter();
StringBuilder sbText = new StringBuilder(textwriter.ToString());
Server.Execute(sb.ToString(), textwriter);

Is there any known issue with Server.Execute on itself?I expect it would just cause a recursive request of the page requesting
server.execute - and hang your server?

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> We have a page which sends a copy of itself via email to customers. To
> enable this, the page calls Server.Execute on itself into a text stream
and
> strips its own output down to HTML presentable to the customer.
> In our Test environment (but not our DEV or Local envs) we are experience
an
> ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
reboot
> the server before any of our other ASP.NET apps will work.
> This is a sample of the code which appears to be the culprit. We
commented
> out the Server.Execute and substituted some junk text to build sbText and
the
> code worked fine on our test environment again.
> -- Locks server
> StringBuilder sb = new StringBuilder();
> sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> sb.Append(erNumber);
> System.IO.TextWriter textwriter = new System.IO.StringWriter();
> StringBuilder sbText = new StringBuilder(textwriter.ToString());
> Server.Execute(sb.ToString(), textwriter);
> Is there any known issue with Server.Execute on itself?
It shouldn't, but I'll look into it.

The call to Server.Execute occurs only within a postback when a button on
the page is pushed to generate the email. As I said, this poses no problem
whatsoever on our local machines (5 developers) or on our development server
environment. Only in our Test env is there an issue.

"John Timney (Microsoft MVP)" wrote:

> I expect it would just cause a recursive request of the page requesting
> server.execute - and hang your server?
> --
> Regards
> John Timney
> Microsoft Regional Director
> Microsoft MVP
>
> "Chuck Haeberle" <Chuck Haeberle@.discussions.microsoft.com> wrote in message
> news:6F2D019E-2D08-48EC-AC32-0DF6BBDAD3DE@.microsoft.com...
> > We have a page which sends a copy of itself via email to customers. To
> > enable this, the page calls Server.Execute on itself into a text stream
> and
> > strips its own output down to HTML presentable to the customer.
> > In our Test environment (but not our DEV or Local envs) we are experience
> an
> > ASP.NET lockup. The WHOLE asp.net architecture freezes, and we must
> reboot
> > the server before any of our other ASP.NET apps will work.
> > This is a sample of the code which appears to be the culprit. We
> commented
> > out the Server.Execute and substituted some junk text to build sbText and
> the
> > code worked fine on our test environment again.
> > -- Locks server
> > StringBuilder sb = new StringBuilder();
> > sb.Append(base.AppRoot).Append("/ER/OOWLetter.aspx?ERNumber=");
> > sb.Append(erNumber);
> > System.IO.TextWriter textwriter = new System.IO.StringWriter();
> > StringBuilder sbText = new StringBuilder(textwriter.ToString());
> > Server.Execute(sb.ToString(), textwriter);
> > Is there any known issue with Server.Execute on itself?
>

server.execute and virtual paths

I'm trying to execute an aspx page by calling Server.Execute.
The aspx page I'm trying to execute is in a different web app from the aspx
page containing the Server.Execute statement. A slightly clearer explanation
..
Page1 exists in WebApp1. In the code-behind of Page2 in WebApp2, I have put
Server.Execute("Path to Page1 in WebApp1").
When I call Server.Execute(String) using "http://localhost/WebApp1/Page1.asp
x", everything works ok and Page1 pops up in a new window.
But when I try to use the same path with the overloaded version, Server.Exec
ute(String, TextWriter), I get an error saying I must pass in a virtual path
. So I pass in "../WebApp1/Page1.aspx" as the path. But now I get this error
:
The virtual path '/WebApp1/Page1.aspx.cs' maps to another application, which
is not allowed.
But I can execute the same page using Server.Execute(String) and "http://...
"!!
So, is my virtual path wrong? Or is it something else?
(I need to use the overloaded version Server.Execute(String, TextWriter) so
that I can capture the output from Page1 and NOT have it popup in a new wind
ow.)Hmmm, sorry peoples...
Forget my first post...it seems my dlls weren't recompiling correctly and Se
rver.Execute(String) plus "http://..." seemed to work cos it was using some
old code but in fact that doesn't work.
So, it seems I can't use Server.Execute to execute pages in another web app.
Is there another way to accomplish this?
Cheers, Dune
"Dune" wrote:

> I'm trying to execute an aspx page by calling Server.Execute.
> The aspx page I'm trying to execute is in a different web app from the asp
x page containing the Server.Execute statement. A slightly clearer explanati
on...
> Page1 exists in WebApp1. In the code-behind of Page2 in WebApp2, I have pu
t Server.Execute("Path to Page1 in WebApp1").
> When I call Server.Execute(String) using "http://localhost/WebApp1/Page1.a
spx", everything works ok and Page1 pops up in a new window.
> But when I try to use the same path with the overloaded version, Server.Ex
ecute(String, TextWriter), I get an error saying I must pass in a virtual pa
th. So I pass in "../WebApp1/Page1.aspx" as the path. But now I get this err
or:
> The virtual path '/WebApp1/Page1.aspx.cs' maps to another application, whi
ch is not allowed.
> But I can execute the same page using Server.Execute(String) and "http://.
."!!
> So, is my virtual path wrong? Or is it something else?
> (I need to use the overloaded version Server.Execute(String, TextWriter) s
o that I can capture the output from Page1 and NOT have it popup in a new wi
ndow.)
>
You're going to be stuck with Response.Redirect, I think.
Dale Preston
MCAD, MCSE, MCDBA
"Dune" <Dune@.discussions.microsoft.com> wrote in message
news:0B7B2BBD-9D95-4ACC-B5E4-8EF63726EE86@.microsoft.com...
> Hmmm, sorry peoples...
> Forget my first post...it seems my dlls weren't recompiling correctly and
Server.Execute(String) plus "http://..." seemed to work cos it was using
some old code but in fact that doesn't work.
> So, it seems I can't use Server.Execute to execute pages in another web
app.
> Is there another way to accomplish this?
> Cheers, Dune
> "Dune" wrote:
>
aspx page containing the Server.Execute statement. A slightly clearer
explanation...
put Server.Execute("Path to Page1 in WebApp1").
"http://localhost/WebApp1/Page1.aspx", everything works ok and Page1 pops up
in a new window.
Server.Execute(String, TextWriter), I get an error saying I must pass in a
virtual path. So I pass in "../WebApp1/Page1.aspx" as the path. But now I
get this error:
which is not allowed.
"http://..."!!
so that I can capture the output from Page1 and NOT have it popup in a new
window.)

server.execute and virtual paths

I'm trying to execute an aspx page by calling Server.Execute.

The aspx page I'm trying to execute is in a different web app from the aspx page containing the Server.Execute statement. A slightly clearer explanation...

Page1 exists in WebApp1. In the code-behind of Page2 in WebApp2, I have put Server.Execute("Path to Page1 in WebApp1").

When I call Server.Execute(String) using "http://localhost/WebApp1/Page1.aspx", everything works ok and Page1 pops up in a new window.

But when I try to use the same path with the overloaded version, Server.Execute(String, TextWriter), I get an error saying I must pass in a virtual path. So I pass in "../WebApp1/Page1.aspx" as the path. But now I get this error:

The virtual path '/WebApp1/Page1.aspx.cs' maps to another application, which is not allowed.

But I can execute the same page using Server.Execute(String) and "http://..."!!

So, is my virtual path wrong? Or is it something else?
(I need to use the overloaded version Server.Execute(String, TextWriter) so that I can capture the output from Page1 and NOT have it popup in a new window.)Hmmm, sorry peoples...

Forget my first post...it seems my dlls weren't recompiling correctly and Server.Execute(String) plus "http://..." seemed to work cos it was using some old code but in fact that doesn't work.

So, it seems I can't use Server.Execute to execute pages in another web app.
Is there another way to accomplish this?

Cheers, Dune

"Dune" wrote:

> I'm trying to execute an aspx page by calling Server.Execute.
> The aspx page I'm trying to execute is in a different web app from the aspx page containing the Server.Execute statement. A slightly clearer explanation...
> Page1 exists in WebApp1. In the code-behind of Page2 in WebApp2, I have put Server.Execute("Path to Page1 in WebApp1").
> When I call Server.Execute(String) using "http://localhost/WebApp1/Page1.aspx", everything works ok and Page1 pops up in a new window.
> But when I try to use the same path with the overloaded version, Server.Execute(String, TextWriter), I get an error saying I must pass in a virtual path. So I pass in "../WebApp1/Page1.aspx" as the path. But now I get this error:
> The virtual path '/WebApp1/Page1.aspx.cs' maps to another application, which is not allowed.
> But I can execute the same page using Server.Execute(String) and "http://..."!!
> So, is my virtual path wrong? Or is it something else?
> (I need to use the overloaded version Server.Execute(String, TextWriter) so that I can capture the output from Page1 and NOT have it popup in a new window.)
You're going to be stuck with Response.Redirect, I think.

Dale Preston
MCAD, MCSE, MCDBA

"Dune" <Dune@.discussions.microsoft.com> wrote in message
news:0B7B2BBD-9D95-4ACC-B5E4-8EF63726EE86@.microsoft.com...
> Hmmm, sorry peoples...
> Forget my first post...it seems my dlls weren't recompiling correctly and
Server.Execute(String) plus "http://..." seemed to work cos it was using
some old code but in fact that doesn't work.
> So, it seems I can't use Server.Execute to execute pages in another web
app.
> Is there another way to accomplish this?
> Cheers, Dune
> "Dune" wrote:
> > I'm trying to execute an aspx page by calling Server.Execute.
> > The aspx page I'm trying to execute is in a different web app from the
aspx page containing the Server.Execute statement. A slightly clearer
explanation...
> > Page1 exists in WebApp1. In the code-behind of Page2 in WebApp2, I have
put Server.Execute("Path to Page1 in WebApp1").
> > When I call Server.Execute(String) using
"http://localhost/WebApp1/Page1.aspx", everything works ok and Page1 pops up
in a new window.
> > But when I try to use the same path with the overloaded version,
Server.Execute(String, TextWriter), I get an error saying I must pass in a
virtual path. So I pass in "../WebApp1/Page1.aspx" as the path. But now I
get this error:
> > The virtual path '/WebApp1/Page1.aspx.cs' maps to another application,
which is not allowed.
> > But I can execute the same page using Server.Execute(String) and
"http://..."!!
> > So, is my virtual path wrong? Or is it something else?
> > (I need to use the overloaded version Server.Execute(String, TextWriter)
so that I can capture the output from Page1 and NOT have it popup in a new
window.)

Thursday, March 22, 2012

Server.execute fired twice

I am trying to calling sendmail.aspx page from a submitjob.aspx page to send email using server.execute ("sendmail.aspx?jobID=4"). The mail was send, however, it send twice. There got be a simple fix for this problem. Any helps are appreciated.

Thanks

-Ron

Well this is not enough to decide. Maybe there is something in yourcode that is calling submitjob.aspx twice. Can we have a look at thecode-behind you have ?
regards

Server.Execute reference created objects

Hi,

I have a basic aspx page, in the Page_Init procedure I have a
server.execute of another aspx page that adds some html code to my
first page. However it also adds a control (an htmlimage), now my
question is how to I get access to that control from the class in my
first page? Whenever I try to access it I get a "object reference not
set to an instance..." error.

Thank you,
JonathanWell, I think you should knew the object name of that control, you can use
FindControl function.

the code should be something like this, I giving an example of FindControl
with TextBox

CType(FindControl("MyTextBox"), TextBox).Text = "Hello"

Change the "MyTextBox" to your object name, and "TextBox" to the object
type.

Tee

"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.c om...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan
Hi Sophos:

I'm not sure how Server.Execute can return an HtmlImage "control".
Server.Execute renders the page you ask it to execute, and you fetch
the same HTML a client would see if they requested the page with a
browser.

StringWriter writer = new StringWriter();
Server.Execute("otherpage.aspx",writer);
string html = writer.ToString();
writer.Close();

You should have an image tag in the string, an image tag put in by an
HtmlImage control. You could use regular expressions or String.IndexOf
to search for the image tag, but you won't find a control.

HTH,

--
Scott
http://www.OdeToCode.com

On 9 Jul 2004 12:12:33 -0700, sophos@.postmaster.co.uk (Sophos) wrote:

>Hi,
>I have a basic aspx page, in the Page_Init procedure I have a
>server.execute of another aspx page that adds some html code to my
>first page. However it also adds a control (an htmlimage), now my
>question is how to I get access to that control from the class in my
>first page? Whenever I try to access it I get a "object reference not
>set to an instance..." error.
>Thank you,
>Jonathan
You can't directly do what it is you're trying to do but here's a work
around:

In your WebForm2, add code like this:
WebForm1 wf1 = (WebForm1)Context.Handler;

That will make WebForm1 available to the page you called with
Server.Execute. Now, in WebForm1, create an image control with its visible
property set to false, or even an array to hold the information you want to
copy. Set the protection of the image control to public.

Create a property to return the image:

public System.Web.UI.WebControls.Image MyImage
{
get { return Image1; }
set { Image1 = value; }
}

If you choose to use an array to get the values into, create a public
property in WebForm1 to return the array value:

private object imagePropertyValues[];

public object ImagePropertyValues[]
{
get { return imagePropertyValues; }
set { imagePropertyValues = value; }
}

In the code of your WebForm2, copy the properties you wish back to the
WebForm1 control or WebForm1 array. You can also copy the image object,
itself:

wf1.MyImage = Image1; // this line is in WebForm2.aspx.cs

That will let you retrieve property values back in WebForm1 but will not let
you dynamically control the values in WebForm2. If you want to dynamically
control the values in WebForm2, then create public properties or objects in
WebForm1 to hold those values prior to calling Server.Execute("WebForm2").
Then in the code for WebForm2, retrieve those values from the WebForm1
object you created in the first line of code above.

It's only slightly convoluted but you can, by using these concepts, set
values in WebForm2 and use those values in WebForm1 after WebForm2 completes
execution.

The one thing you cannot do is to change a value in WebForm2 controls after
WebForm2 returns. Think of WebForm2 as a method, and when it completes
execution, its fields are out of scope and cannot be accessed.

Dale

"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.c om...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan

Server.Execute reference created objects

Hi,
I have a basic aspx page, in the Page_Init procedure I have a
server.execute of another aspx page that adds some html code to my
first page. However it also adds a control (an htmlimage), now my
question is how to I get access to that control from the class in my
first page? Whenever I try to access it I get a "object reference not
set to an instance..." error.
Thank you,
JonathanWell, I think you should knew the object name of that control, you can use
FindControl function.
the code should be something like this, I giving an example of FindControl
with TextBox
CType(FindControl("MyTextBox"), TextBox).Text = "Hello"
Change the "MyTextBox" to your object name, and "TextBox" to the object
type.
Tee
"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.com...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan
Hi Sophos:
I'm not sure how Server.Execute can return an HtmlImage "control".
Server.Execute renders the page you ask it to execute, and you fetch
the same HTML a client would see if they requested the page with a
browser.
StringWriter writer = new StringWriter();
Server.Execute("otherpage.aspx",writer);
string html = writer.ToString();
writer.Close();
You should have an image tag in the string, an image tag put in by an
HtmlImage control. You could use regular expressions or String.IndexOf
to search for the image tag, but you won't find a control.
HTH,
Scott
http://www.OdeToCode.com
On 9 Jul 2004 12:12:33 -0700, sophos@.postmaster.co.uk (Sophos) wrote:

>Hi,
>I have a basic aspx page, in the Page_Init procedure I have a
>server.execute of another aspx page that adds some html code to my
>first page. However it also adds a control (an htmlimage), now my
>question is how to I get access to that control from the class in my
>first page? Whenever I try to access it I get a "object reference not
>set to an instance..." error.
>Thank you,
>Jonathan
You can't directly do what it is you're trying to do but here's a work
around:
In your WebForm2, add code like this:
WebForm1 wf1 = (WebForm1)Context.Handler;
That will make WebForm1 available to the page you called with
Server.Execute. Now, in WebForm1, create an image control with its visible
property set to false, or even an array to hold the information you want to
copy. Set the protection of the image control to public.
Create a property to return the image:
public System.Web.UI.WebControls.Image MyImage
{
get { return Image1; }
set { Image1 = value; }
}
If you choose to use an array to get the values into, create a public
property in WebForm1 to return the array value:
private object imagePropertyValues[];
public object ImagePropertyValues[]
{
get { return imagePropertyValues; }
set { imagePropertyValues = value; }
}
In the code of your WebForm2, copy the properties you wish back to the
WebForm1 control or WebForm1 array. You can also copy the image object,
itself:
wf1.MyImage = Image1; // this line is in WebForm2.aspx.cs
That will let you retrieve property values back in WebForm1 but will not let
you dynamically control the values in WebForm2. If you want to dynamically
control the values in WebForm2, then create public properties or objects in
WebForm1 to hold those values prior to calling Server.Execute("WebForm2").
Then in the code for WebForm2, retrieve those values from the WebForm1
object you created in the first line of code above.
It's only slightly convoluted but you can, by using these concepts, set
values in WebForm2 and use those values in WebForm1 after WebForm2 completes
execution.
The one thing you cannot do is to change a value in WebForm2 controls after
WebForm2 returns. Think of WebForm2 as a method, and when it completes
execution, its fields are out of scope and cannot be accessed.
Dale
"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.com...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan

server.execute question

server execute to redirect a page on load however the code after
server.execute is still run, how to prevent thisIt sounds like you want to use Server.Transfer instead of Server.Execute.
Here's more info:
http://SteveOrr.net/faq/TransferRedirect.aspx
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"joe" <joe@.discussions.microsoft.com> wrote in message
news:49119539-8089-47E0-A37F-A72618211C7F@.microsoft.com...
> server execute to redirect a page on load however the code after
> server.execute is still run, how to prevent this

server.execute question

server execute to redirect a page on load however the code after
server.execute is still run, how to prevent thisIt sounds like you want to use Server.Transfer instead of Server.Execute.

Here's more info:
http://SteveOrr.net/faq/TransferRedirect.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"joe" <joe@.discussions.microsoft.com> wrote in message
news:49119539-8089-47E0-A37F-A72618211C7F@.microsoft.com...
> server execute to redirect a page on load however the code after
> server.execute is still run, how to prevent this

Server.Execute with parameters does not work

Hello.
I have an ASP.NET web application in which one page needs to execute another
page and retrieve it's results. The page to be called needs a couple
parameters passed in the URL. However, when I do this, the Server.Execute
fails. From tracing this is because the URL parameters are not properly
being accessed from the called page, so the functions in that page fail
because they are passed invalid parameters. I believe I am formatting my
Server.Execute function improperly. Any ideas? Thanks in advance.
HttpContext.Current.Server.Execute("~/Qstnr/SubmitQstnr.aspx?qId=2&sId=11",
pageResponse);
Ryan TaylorServer.Execute doesn't support query strings, it wants a path to the apx
file you want to create an instance of.
-- bruce (sqlwork.com)
"Ryan Taylor" <rtaylor@.stgeorgeconsulting.com> wrote in message
news:OvPtvCpuEHA.4044@.tk2msftngp13.phx.gbl...
> Hello.
> I have an ASP.NET web application in which one page needs to execute
another
> page and retrieve it's results. The page to be called needs a couple
> parameters passed in the URL. However, when I do this, the Server.Execute
> fails. From tracing this is because the URL parameters are not properly
> being accessed from the called page, so the functions in that page fail
> because they are passed invalid parameters. I believe I am formatting my
> Server.Execute function improperly. Any ideas? Thanks in advance.
>
HttpContext.Current.Server.Execute("~/Qstnr/SubmitQstnr.aspx?qId=2&sId=11",
> pageResponse);
> Ryan Taylor
>
Yeah,
I ended up coming to this conclusion. Server.Execute seems to call the page
within the context of the page it is called in. As such, If the calling page
has the URL parameters that I wanted in the page to be called, then the
called page can retrieve those parameters from the calling page URL.
Thanks.
Ryan

Server.Execute with parameters does not work

Hello.

I have an ASP.NET web application in which one page needs to execute another
page and retrieve it's results. The page to be called needs a couple
parameters passed in the URL. However, when I do this, the Server.Execute
fails. From tracing this is because the URL parameters are not properly
being accessed from the called page, so the functions in that page fail
because they are passed invalid parameters. I believe I am formatting my
Server.Execute function improperly. Any ideas? Thanks in advance.

HttpContext.Current.Server.Execute("~/Qstnr/SubmitQstnr.aspx?qId=2&sId=11",
pageResponse);

Ryan TaylorServer.Execute doesn't support query strings, it wants a path to the apx
file you want to create an instance of.

-- bruce (sqlwork.com)

"Ryan Taylor" <rtaylor@.stgeorgeconsulting.com> wrote in message
news:OvPtvCpuEHA.4044@.tk2msftngp13.phx.gbl...
> Hello.
> I have an ASP.NET web application in which one page needs to execute
another
> page and retrieve it's results. The page to be called needs a couple
> parameters passed in the URL. However, when I do this, the Server.Execute
> fails. From tracing this is because the URL parameters are not properly
> being accessed from the called page, so the functions in that page fail
> because they are passed invalid parameters. I believe I am formatting my
> Server.Execute function improperly. Any ideas? Thanks in advance.
>
HttpContext.Current.Server.Execute("~/Qstnr/SubmitQstnr.aspx?qId=2&sId=11",
> pageResponse);
> Ryan Taylor
Yeah,

I ended up coming to this conclusion. Server.Execute seems to call the page
within the context of the page it is called in. As such, If the calling page
has the URL parameters that I wanted in the page to be called, then the
called page can retrieve those parameters from the calling page URL.

Thanks.

Ryan

Server.Execute vs Server.Transfer

Hello,
I have read that you can workaround the common problem of the Thread.Abort exception by using the server.execute method instead of server.transfer when transfering to another page.

I started using server.transfer in order to make the URLReferrer property of the HTTP request show up properly when using smart navigation in the app. This worked fine, but I get the Thread.Abort execeptions now and then.

Will server.execute still allow the HTTP Request to contain a valid URLReferrer value like the server.transfer call did?

Thanks.From the docs (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassTransferTopic2.asp):

"Transfer calls End which raises a ThreadAbortException exception upon completion."