1

I have a situation where I'm generating my Connection String in an asp page using a functionality.This functionality I may need to completely do from scratch in .net which is redundancy.To avoid this I want to get the connection string variable from the .asp page to the .net page i.e aspx.cs. Is it possible to do this. A couple of options from google I have been able to get are Server.Execute and sending a Web Request through.net to .asp page and get those values.I wanted to know the latency associated with this methods if it is actually possible.

there is a file getconnstring.asp...classic asp file in this file I'm constructing connection string like

strACHConnection="Provider=MSDAORA.1;Password=..."

I want to use this variable value in an asp.net website as in a getconnstring.aspx.cs.Is it possible to do using an Ajax request.

3
  • Can you explain a bit better, what do you mean by "generating a connection string" in an asp page? I hope you don't actually want to have your connection string publicly accessible? Commented Nov 10, 2010 at 9:44
  • Do u mean u want a value(connection string) from ur .cs page to .aspx page? Commented Nov 10, 2010 at 10:31
  • What could possibly be so difficult about constructing a connection string that you'd consider executing an .asp page to get it? The latency of the (internal) request and the possible security risks should be enough to convince you this is probably not a good idea. Commented Nov 10, 2010 at 11:31

2 Answers 2

2

Can can get the connection string or any other information from your .asp application by making a WebRequest from your asp.net application to your .asp app.

However, there will be latency issues depending on where the two reside with respect to each other. So I would get the info once and then save it to a file or something and then read it from there the next time.

Sign up to request clarification or add additional context in comments.

4 Comments

If the connection string is static (i.e. not depend upon current user etc) then I would fetch it from ASP app in Application_Start in global.asax and store it in some static variable. Otherwise, caching it in memory (e.g. ASP.NET Cache) would be better option than storing in file. However, the most important concern would be a security - for example, if your asp app can return connection string to ASP.NET app using HTTP request then it means any user can get it. You need to have some mechanism (asp app being not public, asp app needing some authentication ticket to issue connection string etc)
Can you please elaborate on how to do WebRequest from your asp.net application to your .asp app.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("microsoft.com"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string str = reader.ReadToEnd();
Use Dispose where required! The code got messed up a bit so somethings don't look correct and this is off of the top of my head. Been a while since I did this kind of thing synchronously.
0

I'm posting another answer so I can post some code that doesn't get garbled. Below is a Task based version.

var webRequest = WebRequest.Create("http://www.microsoft.com");
webRequest.GetReponseAsync().ContinueWith(t =>
{
  if (t.Exception == null)
  {
    using (var sr = new StreamReader(t.Result.GetResponseStream()))
    {
      string str = sr.ReadToEnd();
    }
  }
  else
    System.Diagnostics.Debug.WriteLine(t.Exception.InnerException.Message);
});

And here is a sync version that's untested but should get you going.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string str = reader.ReadtoEnd();

6 Comments

The remote server returned an error: (403) Forbidden. Can you provide any help on this
Try browing to the url using your browser first and make sure the url is valid an that it in fact returns the value/info you desire. Once that has been confirmed you should be able ot use the code provided to "automate" it. Nonetheless, from this point forward it becomes difficult to help at a detail level "remotely".
I do think the question has been answered so I'd appreciate an answer accepted :)
Shiv your code works perfectly fine, but it is working for aspx files.The Web Request I create is working only for Defauly.aspx liek pages. When I give the url as an asp page it is giving 403 Forbidden Error.
Are you able to call the asp page using a browser? If using a browser works then using WebRequest should work too, unless there is some server set up for the .asp application that is blocking those requests. Using a WebRequest is almost that same as using a Browser.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.