Login to asp.net site from another app, then receive filestream - asp.net

I have an ASP.NET application with pages that use reportviewer. Can someone give me a hint on how to approach the following requirement:
I want to get the report as PDF file from the page, without user interaction. I know I can render the report to a filestream, but since there's no user opening it in a browser, I need to collect the filestream from another application that might run during the night.
There might be other approaches, like a webservice for example that could return the filestream to me, but this would also mean, I have to modify the setup of the datasources that the report receives it's data from. There are a lot of controls on the page, for supplying filter parameters. By using the page life cycle I can use what's already there.
I thought about wget, but haven't tried it yet, and I'm not sure how complicated logging in will be with cookies. I do have full control over the asp.net application though, so if I can modify something there to make it easier, I'd do it.

You can use the "WebClient" in .net application to get the response from the site.
Please refer the below link:
http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.80).aspx

Related

Is there anyway to load up a asp.net page object and render its contents to string from a console application?

I am trying to use aspx pages as an email templates. There will likely be a bunch of objects on the page which will be used as replacements in the html. Because it's an aspx page I'll be able to use databinding, repeaters, etc. At run time, I want to be able to instantiate the aspx page from its path, pass in a bunch of properties, and then get the rendered result of the page and email it. This seems pretty straightforward from a asp.net website (maybe using BuildManager or Server.Execute.) However, I want to be able to use the same templates via a console application by just loading up a page object from its filepath. Is this possible?
You could host your own webserver. Like the Cassini webserver.
In my own application (a Windows-based Desktop-CMS), I include a web server, too (non-Cassini). It works very well, also it does not serve ASP.NET but plain, HTML.
As I did some research back then, I first wanted to use the Cassini, too, but at some point, I found out that too much user privileges were required to run it successfully; this may not be an issue to you, but keeping this in mind and try to run it early with the permissions of the later user, might be a good idea.

Legitamate cross site communication

I am building a website, within a large intranet, that wraps and adds functionality to another site within the same intranet. I do not have access to the other site's source and they do not provide any api's for the functionality they provide. I need to, somehow, have my server-side code go to that site, fill in some forms, then press a submit button.
Is this possible? If so, how can I accomplish this?
Note: I am working in asp.NET if that matters at all.
Not the most efficient, but maybe WatiN can get you started:
http://watin.sourceforge.net/
Just look at the URL the form is supposed to submit to and the method it employs (POST or GET) and then send a request to that URL using the same method and put the field you want as parameters
Your server-side code is basically a web client to the other web site. You will need to write the code to send the HTML form data to the other web site and process the response. I would start with the System.Net.WebClient class. Take a look at System.Net.WebClient.UploadValues. That class/method will enable you to POST the form data to the web site via a NameValueCollection.

ASP3 And ASP.NET session sharing

Is there a way to share the session between ASP3 And ASP.NET?
Thanks
Despite all of Microsoft's best efforts to make ASP and ASP.NET coexist effortlessly, one area remains a stumbling block... session state. Fortunately the advantages of ASP.NET's upgraded session state management far outweigh the inconvenience of not being able to pass "Classic" session information to .NET. Unfortunately there is no simple solution; the most I can offer is an easy to implement workaround.
In trying to find a suitable resolution, I've come across two good options that are worth mentioning. The first involves parsing the session information out to hidden form fields on a "Classic" intermediate page and then submitting the page to a .NET intermediate page that loads the form fields into the session state. This is a good, simple solution, however it doesn't work both ways. In .NET you cannot specify the page that you submit to. Each page has to PostBack to itself.
The second option is probably closer to an actual solution than to a workaround. Billy Yuen at Microsoft has developed an effective solution. The code is elegant, the integration appears to be seamless, but I couldn't get it to work on my system (remember I said that there was no simple solution, not that there was no solution at all). If this solution works for you, great! You won't need my code and you'll be happily passing session information from "Classic" to .NET like it's going out of vogue, thanks for stopping by.
Ok, if you're still reading let me briefly describe the workaround I've created. It requires a database, but it is not important which type of database (though the code is written for SQL Server). When a page (source page) wants to redirect to another page (destination page) that uses a different version of ASP, it calls an intermediate page. The source intermediate page takes each session variable and adds it to the database along with a Globally Unique ID (GUID). Since "Classic" and .NET use different SessionID formats it is not possible to use SessionID, hence the use of a GUID. The source intermediate page then passes the GUID to the destination intermediate page through a Querystring variable. The destination intermediate page retrieves the session information from the database, cleans up after itself, and then redirects to the destination page. It's similar to the first workaround, but supports transferring state in both directions.
Code Usage
Installation
Run the SQL Query in "ASPSessionState.sql" on the database which will hold the temporary Session information.
Copy the .asp and .aspx.* (SessionTransfer.aspx and SessionTransfer.aspx.cs) files to a folder on your website.
Update connection object information in the "SessionTransfer.asp" and "SessionTransfer.aspx.cs" files. It is located in three places in each file (sorry about not consolidating the connection info).
Compile the aspx files.
The .asp and .aspx.* files must all reside in the same folder to work.
Usage
For use in a Hyperlink (Anchor Tag) or a Response.Redirect, set the destination URL to be one of the following:
From a ASP "Classic" page:
SessionTransfer.asp?dir=2aspx&url=<asp_dotnet_url>
From an ASP.NET page:
SessionTransfer.aspx?dir=2asp&url=<asp_classic_url>
The code will transfer the Session information and Redirect the user to the url specified by or .
Download
You can download the code from here: session_transfer.zip (4.6 KB).
Could take a look at NSession it allows sharing session state between Classic ASP and ASP.Net using State server. Pretty easy to setup just configure App to use State Server for session and register a couple of dll files.

ASP.Net Context.User.Identity weirdness

I have an ASP.Net 3.0 SP1 app that uses Form Authentication.
While testing, I noticed that if I viewed a page that another user was viewing, the other users name would be displayed in the control on my master page. The Context.User.Identity is also for the other user.
If I switch to different page that no one else is viewing the Context.User.Identity is correct.
I stumped and would appreciate suggestions.
Thanks in advance.
Chris
Maybe because output caching is enabled for the page: if the page is cached server-side with VaryByParam=none, all users will get the same copy from the cache.
I can only think of two things that can cause this:
You're storing user-specific data in a place shared between requests (e.g. in a static(C#)/shared(VB) variable, in the ASP.NET Cache, in the Application object, ...)
You have output caching enabled.
Check for:
OutputCache directives in your aspx and ascx files,
system.web/caching element in your web.config file(s),
Calls to the HttpCacheability.SetCacheability method.
If you can't find the problem:
Try creating a simplified version of your application until you get the simplest possible version that still reproduces the undesirable behaviour.
During this process of simplification you'll likely discover the problem for yourself. If not, post some code from the simplified version.
Make sure you are not using a link that comes with the authentication ticket when using a cookieless browser.
Also make sure to review any other that might be sharing the data among requests. Just like DOK said, but remember Application isn't the only way you could be doing that.
It looks like the issue was caused because I setting targetframe="_self" or Target="_self". I removed all these and everything seem to be working fine.
One other note: If I were to refresh the page it would also display the page with the correct user.

How can I know when .aspx call is finished?

I am building a Flex Application that calls a .aspx page on the same webserver which builds a PDF report using SQL Reporting Services. When the report is built it prompts the user to open or save the PDF.
We are trying to find a way to display a Progress Bar to let the user know that the report they requested is being built, and then destroy the Progress Bar once the report is finished being built.
I've tried opening a new window using JavaScript and trying to catch when the window closes, as well as trying XMLHTTPRequest, but nothing to seems to work.
Does anyone have any suggestions?
There are 2 options:
Use the FileReference class in Flex to programmatically invoke your aspx file. You will be able to track the progress of the call from within Flex by listening to its events. But the users can only save the PDF, not open it.
Have an intermediate HTML page that displays a loading icon and then refresh itself to your PDF generating ASPX page. Encode your aspx url along with parameters etc and set it as a parameter to this intermediate page so it knows what to load.
If you don't have control over the page to be able to put JavaScript on it to hit a URL (or call back to the parent/opener), then you might consider whipping up an aspx page of your own to host a ReportViewer control, and display the report inside of that. This would require you to create a .NET website with a page and a web.config - you wouldn't need to do more than make it receive any parameters your report needs, and it would be do-able via inline-to-the-aspx code as opposed to requiring in-depth .NET knowledge.
Or, you could hit the SS-RS API and render the report directly. Here, you'd craft a URL with parameters for the report on the SS-RS API site to accept. I think, though I don't know for sure, that the SS-RS UI uses the API itself behind the scenes. By default the API is hosted in a site called "reportserver" - you might sniff HTTP traffic while the report is being rendered to get you started with the URL that you'd need to hit.
Another option not mentioned here is to create a .Net webservice, add it to your flex project and when it hits the result handler you know the file is created at that point.

Resources