.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to do a redirect from URL returned in XML

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
I have the following code:Protected Sub SendButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SendButton.Click Dim req As WebRequest = Nothing Dim rsp As WebResponse = Nothing Try Dim fileName As String = "C:\data.xml" Dim uri As String = "http://www.myURL.com/punchout/Default.aspx" req = WebRequest.Create(uri) req.Method = "POST" req.ContentType = "text/xml" Dim writer As New StreamWriter(req.GetRequestStream()) writer.WriteLine(GetTextFromXMLFile(fileName)) writer.Close() rsp = req.GetResponse() Catch webEx As WebException Catch ex As Exception Finally If req IsNot Nothing Then req.GetRequestStream().Close() Response.Write("A<BR>") End If If rsp IsNot Nothing Then rsp.GetResponseStream().Close() Response.Write("B<BR>") End If End Try End Sub Private Function GetTextFromXMLFile(ByVal file As String) As String Dim reader As New StreamReader(file) Dim ret As String = reader.ReadToEnd() reader.Close() Return ret End FunctionAt the other end I am returning the following XML response

View Complete Post

More Related Resource Links

Response.Redirect slow


I'm in the middle of migrating servers and on the new server Response.Redirect is extremely slow. It takes around 20 seconds for the browser to get the redirect. This is something that was quick on the existing server. It's an ASP.NET 2.0 application, both servers are running IIS6.

Additionally, if I "manually" do the redirect, it's fast. For example:

Existing way:


takes around 20 seconds on the new server

New way:

Response.Status = "302 Moved Temporarily";
Response.AddHeader("Location", url);

is fast on the new server.

Any ideas why Response.Redirect would be so slow on the new server?

Where to Filter the companies returned by the EF?



I am just starting with dynamic data. I have an enttity framework called UsersModel.edmx.

It returns a list of all companies in the tblCompany table. This list is really big.

I need to filter the list returned to all user controls on the client so that it only returns the company that have a CompanyTypeId= 2 or CompanyTypeId= 3 and company name != "".

1 - Is it possible to filter the company list returned on the server so that I can filter only once for all the controls that use that on the client?

My ideas was to do something like this using linq and lambda but I am not sure how:

return tblCompanys.Where(c => c.CompanyTypeId == 2 || c.CompanyTypeId == 3 && ).Where(c=>c.CompanyName != "").OrderBy(c => c.CompanyName).Distinct().OrderBy(c=>c.CompanyName);

2 - I have created a partial class and a metadata class and added the DisplayColumn attribute to use the company name and sort by company name ascending.

Could I use the code to filter the returned companies in this? where?

namespace MarsMedicalModel
    [DisplayColumn("CompanyName", "CompanyName")]
    public partial class t

Automatically redirect to HTTPS and check if SSL is active



I've set in the web.config:

    <!-- User Authentication -->
    <authentication mode="Forms">
      <forms loginUrl="~/Page/View/Content/Login.aspx" timeout="2880" requireSSL="true" />

This works fine. If there is no ssl connection, the login form doesn't continue. But I would like to check if ssl is active (in codebehind) and, if it's possible, to automatically the user to the https page if he's currently on http. (I could do this job by manually redirect with page.response("https://url.../login.aspx"); but this is not really generic. For example if the webapp is moved to another domain it doesn't work anymore... I'm looking for something like: FormsAuthentication.RedirectWithSSL(); or so... :D)


Profile not being save after redirect.



I am trying to save values into a Profile on Page1, then redirect to Page2 and access those values.  However, after the page redirects the profile values are blank as if they were never saved.   When stepping through the code I can see that they are being save on Page 1.

I suppose I could use session variables to store the information but I don't understand why saving the profile doesn't work.

private void PayWithPayPal()
        ProfileCommon profile = this.Profile;

        if (Global.CurrentUserName.Length > 0)
            profile = this.Profile.GetProfile(Global.CurrentUserName);
        profile.FirstName = uxFirstNameShipping.Text;
        profile.LastName = uxLastNameBilling.Text;
        profile.ShippingAddress.AddressLineOne = uxAddressLineOneShipping.Text;
        profile.ShippingAddress.AddressLineTwo = uxAddressLineTwoShipping.Text;
        profile.ShippingAddress.City = uxCityShipping.Text;
        profile.ShippingAddress.State = uxStateShipping.Text;
        profile.ShippingAddress.ZipCode = uxPostalCodeShipping.Text;

        Response.Redirect("~/expresspayment.aspx", false);

protected void Page_Load(object sender, EventArgs e)
        ProfileCommon p

Redirect to a mobile page

Hi please can anyone help? I have a simple website with a home page called defaut.aspx, also I have a page with in this site called mobile.aspx. My question is, bearing in mind that I posses very little knowledge of VB, what code do I need to place in the default.aspx to detect what kind of device someone is using and redirect them to the mobile page (mobile.aspx)? This needs to be quite up-to-date preferably for blackberry and nokia devices?


Detecting PPC device on startup page to redirect?

I was wondering (since a search didn't find any posts) if there is a way for my startup page to detect what kind of device (PocketPC or web browser specifically) is loading the page and if it is a PocketPC, then redirect to the mobile pages? I will only be using PocketPC's exclusively as a mobile device.

Thanks for any suggestions!



I need to open a new window with Response.Redirect, Is it possible?

Cannot redirect HTTP headers already sent


I have been working on an registeration page for my web site in asp.net.After the person succesfully registers , another page is called which sends an email.After the email is sent it should redirect to the default page . I came accross this error when trying to redirect after sending the email.

"Cannot redirect HTTP headers already sent"

.What could the problem be?

Here is the code

//send email
MailMessage mail = new MailMessage();
mail.To =strName ;
mail.From = "GiftWorld@yahoo.com";
mail.BodyFormat = MailFormat.Text;
mail.Subject = "Thank you for registering -Gift World.com";
mail.Body = "Thank you for registering -Gift World.com";
SmtpMail.SmtpServer = "mara.strathmore.edu" ;

Adding a cookie to a response.redirect vs. httpWebRequest


Hello, I will try to be as clear as I can be.  I'm sure this question has been asked but I can't find a suitable answer for this particular situation.

I need to be able to redirect the browser to a new 3rd party page while at the same time supplying a cookie required for some form of authentication on the 3rd party site.

I have managed to get this to work in the following manner:


'SessionID is predetermined by another HttpWebRequest/Response  

Dim sessionCookie As New Cookie("ezproxy", sessionID.Substring(1), "/", ".someother.site")

Dim CookieJar As New CookieContainer


rRequest = HttpWebRequest.Create("where I want to go")

rRequest.CookieContainer = CookieJar

rRequest.Method = "GET"


'Make the request and get the response.

rResponse = rRequest.GetResponse()


'Save cookie(s)

If (rResponse.Cookies.Count <> 0) Then

For Each cook

Redirect to Security Questions if Site accessed from unrecognized computer?


I'm fairly new to ASP.NET and i'm using the Membership Provider.  I have the need to do similar to some banking sites. Baically I need to track "authorized" computers/ip's for a user.  If the user accesses the site form a recognized Computer/IP then the user is allowed into the app after successful login.  If the computer/IP is not recognized I need to redirect them to a screen to answer the security question setup in fhte Membership Provider.

Has anyone done anything like this or can anyone point me to any examples?  I did a search, but can't seem to find anything.

My idea is to maintain a list of authorized computers/IP addresses and check them on initial login.  If the IP address isn't found I can redirect them to the questions.  My concern is that they are then actually authenticated and could enter any of the site URL's as an authenticated user.

Any suggestions greatly appreciated. 

how to evaluate nothing value returned by sql datareader in vb.net


When a sql query returns NULL , I can use the following code to evaluate:

While (dr.Read())
                If IsDBNull(dr(0)) Then
                End If
            End While


When a sql query returns nothing, neither IsDBNull nor is Nothing works.  I don't know why some sql queries return null while some return nothing when there are no data returned.  But anyway, can somebody tell me how to evaluate nothing value returned in sql datareader in vb.net?  When I put the cursor over signInfo variable in debug mode, I can see Nothing show as its value.  But the line does not work

if signInfo is Nothing then 


Thank you!

301 Redirect in sharepoint 2007



We are going live with our new site on internet shortly and we wnat to do an 301 redirect from old url to our new url. e.g. our url http://www.abc.com/def/ and the new url http://www.abc.com/efg/klm/zzz.aspx  [The domain is same]. It will raise a 404 if we are not set the 301 redirect.

Please let me know how can we do this?

Using the BDC API how to catch the returned code when executing a stored procedure?

using BDC API, how can i catch the return code a stored procedure returns?

I tried Entity.Execute to execute a generic method. However, it returns an empty Entity table.

I know you can do it by setting up an output variable. I prefer returning an integer for tracking errors.

Any ideas?



Problem with Mobility Redirect


I recently tried to activate the MobilityRedirect feature in order to let users type /m to get the mobile view of a site.  It works fine on the base site of my site collection but nowhere else. I used the following command in stsadm:

stsadm -o activatefeature -name MobilityRedirect -url http://(my server name)

Am I missing something really silly?  I can't imagine that I have to activate it on each site individually.

The remote server returned an error: (405) Method Not Allowed.



{System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
   at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
   at System.Net.WebClient.UploadFile(Uri address, String fileName)
   at System.Net.WebClient.UploadFile(String address, String fileName)
   at Test.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\WebSite1\Test.aspx.cs:line 35}

Windows application, automated process will run on local user system...
trying to upload a file to website folder. website address:

System.Net.WebClient wc = new WebClient();
wc.UploadFile(website address, "c:/1.pdf");

Getting error from above line.. Am doing something wrong??
I dont want to use ftp or share folder logic..
is there any other way to upload the files to server??

Capture Url and do redirect



I am writing a http module, Want to find out how can i capture a URL and the do a redirect in case of certin conditions met?

Exit Popup and response.redirect

Hi, I have a requirement to show an Exit Popup on one of our processing pages. I am showing the exit popup by registering a client side javascript like window.onbeforeunload = ShowExitPopUp(); The popup executes fine if you close the window, or try to type in a different URL. However the issue is that my processing page is also performing a "Response.Redirect" on the server side once the process completes. When response.redirect happens the exitpopup also shows up. Is there a way to have the exit popup not show up in that case? Since my server side code is running through an UpdatePanel, so I have tried registering the following, in an attempt to remove ExitPopup from client side. However this doesn't work since server side redirection happens before end request. Sys.WebForms.PageRequestManager.getInstance().add_endRequest(RemoveExitPopup); Has anyone faced a similar situation and handled it?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend