What problem have you had when you tried?
Jeff
What problem have you had when you tried?
Jeff
Quick quesiton. Is it considered a good practice or at least not a bad practice to remove all code except the page declaration from an aspx page that will be called by Server.Execute? The reason why I would do this is to elminate the garbage htm tags that get passed back into my requesting page.
Thanks,
Fatthippo
A little more info for you. I'm requesting the aspx file to get to its methods in aspx.cs. Sooooo that's why i'm removing everything from the aspx page accept the page declaration. That way the server.execute doesn't return anything but the methods output from the codebehind file.
Back to my question - Is this a hack? Is there a better solution?
Hello,
That's a good idea. You can also use Response.Rederect() or cross-page to another page which you want to show. They seems similar with each other.
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?
>
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.)
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 ?Hi,
I need to retrieve the HTML string of one of my ASP pages, and whenever I make the attempt using my code, it brings the entire server to a hault for quite a while. The server's hardware specs are perfectly fine, and I've narrowed it down to the Server.Execute line. Is there anything I can do here? Here's my code:
StringWriter sw =new StringWriter();Server.Execute("page.aspx", sw);String strHtmlCode = sw.GetStringBuilder().ToString();
Thanks!
Use HttpWebRequest/HttpWebResponse:
//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
String strHtmlCode = GetHtmlPage("http://domain/page.aspx");
This may be because page.aspx may be huge page and it will take long time in processing. Because of this, your current page execution will stop:)
Cheers
Bhavesh
lad.bhavesh:
This may be because page.aspx maybe huge page and it will take long time in processing. Because of this,your current page execution will stop:)
Cheers
Bhavesh
Including the one image and stylesheet, it's about 55 KB.
Mikesdotnetting:
Use HttpWebRequest/HttpWebResponse:
//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}String strHtmlCode = GetHtmlPage("http://domain/page.aspx");
I apologize - I should have been more clear on the context here. A session needs to be maintained in order to access this page. Is there anything else I can use? And believe me, I've tried googling :). I'm sure it's out there somewhere, but I can't seem to find it.
Will this do you?
http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx
That'll do it, thanks!
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
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
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
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."