hello,
i am having trouble doing something. when a user triggers a certain
event in my app, i need to initiate another web request to one of my
other webpages, programmaticall y. currently, i do this via a WebRequest
-- i attach the default credentials and get the response stream. that
part works. like so:
WebRequest request = HttpWebRequest. Create(reportAs pxURL);
request.Credent ials = CredentialCache .DefaultCredent ials;
WebResponse response = request.GetResp onse();
//Read response to a string
Stream stream = response.GetRes ponseStream();
StreamReader sr = new StreamReader(st ream);
string html = sr.ReadToEnd();
//insert html into my PDF-maker
ConvertToPDF(ht ml);
what *doesnt* work, is trying to share user info between the user's
session in my app, and the web request (in this case, to the report
ASPX page). i need to pass some user info into the report-generating
ASPX. i understand that the Session objects cannot be shared, because
WebRequest (presumably) opens a new session.
but what about cookies? elsewhere in my app i use a cookie to store
session info, so when a user goes to a different virtual-directory in
the app, i can pick up their info seamlessly. but when i tried this
technique w/ the above (hitting the report-generating APSX), the .aspx
page cannot seem to find the cookie.
or is there perhaps a better way to do this? since its an
apppage-to-apppage call w/i the same project, can i programmaticall y
load up the 2nd page, rather than do a WebRequest?
thanks!
matt 6 1714 ma**@mailinator .com wrote:
but what about cookies? elsewhere in my app i use a cookie to store
session info, so when a user goes to a different virtual-directory in
the app, i can pick up their info seamlessly. but when i tried this
technique w/ the above (hitting the report-generating APSX), the .aspx
page cannot seem to find the cookie.
btw, heres the abstract helper-class code i use to set/get cookie info:
(first page, store some user value)
//create cookie
HttpCookie cookie = new HttpCookie(cook ieName);
context.Respons e.Cookies.Add(c ookie);
//optional cookie persist
if (rememberMe == true)
context.Respons e.Cookies[cookieName].Expires =
DateTime.Now.Ad dMonths(1);
//(called from elsewhere) add to cookie
HttpCookie cookie = context.Request .Cookies[cookieName];
cookie.Values[itemName] = itemValue;
context.Respons e.Cookies.Add(c ookie);
(second page, retrieve some user value)
//get from cookie
HttpCookie cookie = context.Request .Cookies[cookieName];
if (cookie != null)
value = cookie.Values[itemName];
....like i mentioned, that works for my cross-virtual-directory pages.
but it doesnt seem to work when trying to retrieve cookie data from the
WebRequest .aspx page (same project/virtual-directory).
thanks!
matt
Matt,
at first reading it seems to me that you aren't "OOP-ifying" your code. If
some other page has a method that you need to call from your current page,
that method should be in a separate class library that your first page can
reference and use, without having to resort to a WebRequest. If you need
session, provide it with a reference to System.Web and / or pass in the
HttpContext.Cur rent property to the method.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ma**@mailinato r.com" wrote: ma**@mailinator .com wrote:
but what about cookies? elsewhere in my app i use a cookie to store
session info, so when a user goes to a different virtual-directory in
the app, i can pick up their info seamlessly. but when i tried this
technique w/ the above (hitting the report-generating APSX), the .aspx
page cannot seem to find the cookie.
btw, heres the abstract helper-class code i use to set/get cookie info:
(first page, store some user value)
//create cookie
HttpCookie cookie = new HttpCookie(cook ieName);
context.Respons e.Cookies.Add(c ookie);
//optional cookie persist
if (rememberMe == true)
context.Respons e.Cookies[cookieName].Expires =
DateTime.Now.Ad dMonths(1);
//(called from elsewhere) add to cookie
HttpCookie cookie = context.Request .Cookies[cookieName];
cookie.Values[itemName] = itemValue;
context.Respons e.Cookies.Add(c ookie);
(second page, retrieve some user value)
//get from cookie
HttpCookie cookie = context.Request .Cookies[cookieName];
if (cookie != null)
value = cookie.Values[itemName];
....like i mentioned, that works for my cross-virtual-directory pages.
but it doesnt seem to work when trying to retrieve cookie data from the
WebRequest .aspx page (same project/virtual-directory).
thanks!
matt
peter,
often do i placed shared methods into common libraries. however that
isnt quite the situation here.
i have many .ASPX pages that produce reports, via DataRepeaters -- each
repeater uses a unique and sometimes complex HTML table to display the
results. in each report page, the Page_Load retrieves data & binds it
to that page's repeater (it does so w/ some user preferences as far as
the query goes).
now i need a PDF version for some of these reports. since i can pass in
HTML into a PDF-component, it seemed the thing to do was extract the
rendered HTML of a given report, and plop it into the PDF.
that seems sound, but the only problem is passing in the user's
preferences (stored in session) to the report -- no problem when they
were viewing the report as a webpage. problem when im trying to do a
WebRequest on the report.
i could certainly re-use the same data-generating method, as it is
indeed in a library. however, the DataRepeaters define HTML table at
design time, and it would seem trickier to learn how to produce said
table+repeaters at runtime, than it would be to figure out how to pass
state (user prefs) to these pages, and suck up their final HTML.
matt
Try using Cache instead of Session, but with a unique key such as the
sessionid, and pass that on the querystring.
Peter
--
Co-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
"ma**@mailinato r.com" wrote:
peter,
often do i placed shared methods into common libraries. however that
isnt quite the situation here.
i have many .ASPX pages that produce reports, via DataRepeaters -- each
repeater uses a unique and sometimes complex HTML table to display the
results. in each report page, the Page_Load retrieves data & binds it
to that page's repeater (it does so w/ some user preferences as far as
the query goes).
now i need a PDF version for some of these reports. since i can pass in
HTML into a PDF-component, it seemed the thing to do was extract the
rendered HTML of a given report, and plop it into the PDF.
that seems sound, but the only problem is passing in the user's
preferences (stored in session) to the report -- no problem when they
were viewing the report as a webpage. problem when im trying to do a
WebRequest on the report.
i could certainly re-use the same data-generating method, as it is
indeed in a library. however, the DataRepeaters define HTML table at
design time, and it would seem trickier to learn how to produce said
table+repeaters at runtime, than it would be to figure out how to pass
state (user prefs) to these pages, and suck up their final HTML.
matt
this won't work. access to session is serialized, so only one request (page)
can access the same session at a time. if you page calls another, that page
can not acces session until the calling page exits.
you could store your user info in a database (or application) and pass an id
to the url.
-- bruce (sqlwork.com)
<ma**@mailinato r.comwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
hello,
i am having trouble doing something. when a user triggers a certain
event in my app, i need to initiate another web request to one of my
other webpages, programmaticall y. currently, i do this via a WebRequest
-- i attach the default credentials and get the response stream. that
part works. like so:
WebRequest request = HttpWebRequest. Create(reportAs pxURL);
request.Credent ials = CredentialCache .DefaultCredent ials;
WebResponse response = request.GetResp onse();
//Read response to a string
Stream stream = response.GetRes ponseStream();
StreamReader sr = new StreamReader(st ream);
string html = sr.ReadToEnd();
//insert html into my PDF-maker
ConvertToPDF(ht ml);
what *doesnt* work, is trying to share user info between the user's
session in my app, and the web request (in this case, to the report
ASPX page). i need to pass some user info into the report-generating
ASPX. i understand that the Session objects cannot be shared, because
WebRequest (presumably) opens a new session.
but what about cookies? elsewhere in my app i use a cookie to store
session info, so when a user goes to a different virtual-directory in
the app, i can pick up their info seamlessly. but when i tried this
technique w/ the above (hitting the report-generating APSX), the .aspx
page cannot seem to find the cookie.
or is there perhaps a better way to do this? since its an
apppage-to-apppage call w/i the same project, can i programmaticall y
load up the 2nd page, rather than do a WebRequest?
thanks!
matt ma**@mailinator .com wrote:
or is there perhaps a better way to do this? since its an
apppage-to-apppage call w/i the same project, can i programmaticall y
load up the 2nd page, rather than do a WebRequest?
there was indeed a better way to do this. instead of a WebRequest
(useful for out-of-site grabs), use an Execute -- like so:
StringWriter writer = new StringWriter();
Server.Execute( ""somePage.aspx ", writer);
string bodyHTML = writer.ToString ();
....and that grabs it. more, it also maintains state between the two!
excellent!
thanks,
matt This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Meghna |
last post by:
Hi,
I was wondering if some one would be able to help me with this. I am
trying to share a session across two servers and I seem to be
experiencing some problems. I was wondering if anybody has already
tried something like this before and hence be able to provide some
guidance in this regard. Any suggestions, pointers or redirections to
useful links is welcome.
Thanks in advance for your help,
|
by: Dennis Gavrilov |
last post by:
Hi, All!
I have two questions: strategic and technical.
Technical one first:
I need to share an array of objects (implemented as hashes, having
references to other objects and hashes, sharing done after blessing)
between all of the mod_perl2 threads. The structure can grow quite big
- tenths of thousands of array elements. It can grow as system
operates (not possible to construct at apache startup). Sharing array
is OK, but inserting...
|
by: James Johnson |
last post by:
Dear C#dex,
I define a variable: HttpWebRequest webRequest and run the following
request
webRequest = WebRequest.Create(TARGET_URL) as HttpWebRequest;
The webRequest object returns values and in the debugger I can see the
value I want in the property
|
by: John Dalberg |
last post by:
Is there a Visual Studio plugin to enhance coding productivity? Say for
example I want to program a function to go to a webpage and retrieve it.
For a beginner, the person doesn't know what function or class to use.
After googling, he finds out he needs to use httpWebRequest.
Howver the VS documentation has a one line example:
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
Is there a better way to...
|
by: Piotr Strycharz |
last post by:
Hi all
I do have a problem.
How can I transfer user to another server using POST. The problem is that
Server.Transfer (preserves form data) works just in current server.
Response.Redirect - uses GET method. However I have to open remote server
page using POST method. Normally this can be achieved using <form
ACTION="remote-page-url"> tag. However this is impossible with ASP.NET.
Also, using WebRequest class is not good solution, as I...
| |
by: Jon Spivey |
last post by:
Hi,
I'm using webrequest to scrape some urls, works fine, however one url seems
to be throwing an error when it doesn't recognise the user agent. So I need
to set the user agent to something like MSIE, I've tried these
WebRequest.Headers.Set("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1;)")
WebRequest.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1;)")...
|
by: antonyliu2002 |
last post by:
We are extending a web application written in classic ASP long time
ago. We will add more components to this web application in ASP.NET
2.0.
To use the web application, our web users will have to log in with
their user name and password.
Well, instead of adding components to the existing classic ASP web
application, we could have just put the extended components into a new
web application. But then this would require them to log...
|
by: mc |
last post by:
I would like to be able to send from an ASP.NET page an email which when recieved takes the form of
a "Sharing Invitation for a RSS Feed" (http://office.microsoft.com/en-us/outlook/HA101595391033.aspx)
I've found a MSDN article about it (http://msdn2.microsoft.com/en-us/library/bb176432.aspx) but that
example is presented as a vb(a) script from within outlook.
Can this functionality be emulated from sending an email from C#?
TIA
|
by: limperger |
last post by:
Hello everybody!
I have just found out that the sharing properties of a single database (mdb file on a network), accessed by 3 users, change depending on the user accessing the database. That is, with the file opened by 2 users at the same time, in my computer, the sharing properties appeared as set to share (not exclusive) and single entry-lock. Nevertheless, in the computer of the other user, the sharing properties are set to exclusive mode...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |