Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:57:54+00:00 2026-05-31T23:57:54+00:00

I am trying to detect incoming url in asp.net page and making some decision

  • 0

I am trying to detect incoming url in asp.net page and making some decision on the base of that url But I am facing some problem here is my c# code the detect the url and also condtions

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
        String url = Request.ServerVariables["HTTP_REFERER"];
        if (url != "http://172.17.0.221:84/CP.aspx")
        {
            Response.Redirect("http://a.sml.com.pk");
        }
        else
        {
            Response.Redirect("http://172.17.0.221:85/MilkSale.aspx");
        }

       }        
    }    

</script>

But When I call the page from http://172.17.0.221:84/CP.aspx then it gives this error:

This webpage has a redirect loop.

The webpage at http://172.17.0.221:85/MilkSale.aspx has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.

Can any one tell me what may the error in this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:57:55+00:00Added an answer on May 31, 2026 at 11:57 pm

    If your script statement is also on the MilkSale.aspx page, then it will fire every time the page is hit; in effect, it will redirect to itself forever (or, in this instance, until asp.net detects that it is requesting the same page over and over again).

    To begin with:

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
        String url = Request.ServerVariables["HTTP_REFERER"];
        if(!String.IsNullOrEmpty(url))
        {
            if (!url.ToUpper().Contains("CP.ASPX"))
            {
                Response.Redirect("http://a.sml.com.pk");
            }
            else if (!url.ToUpper().Contains("MILKSALE.ASPX") && !url.ToUpper().Contains("CP.ASPX"))
            {
                Response.Redirect("http://172.17.0.221:85/MilkSale.aspx");
            }
        }
    
       }        
    } 
    

    Then this will fix the first issue. However, you then have to consider some other issues with your code;

    1. You are doing case insensitive string matching.
    2. You have IP addresses hard coded in your urls

    1) is pretty easy to use; you can use String.Compare(url, referrer, StringComparison.InvariantCultureIgnoreCase) for example. In my code, I have used .ToUpper() but this is still fraught with issues (but makes for a compact example)

    2) Is more difficult; you should really disassociate your redirect mechanism from the root url, or else you’ll have to change your code everytime you change site. Either use the property HttpContext.Current.Request.Url.PathAndQuery or, preferably, look at URL rewriting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to detect and remove those fields that after a sync are still
I'm trying to detect if the user landed on my page through a google
I'm trying to detect whether a string holds a dash but nothing seems to
I'm trying to detect if the current page is being delivered via SSL in
i am trying to detect Collision of two sprites in the following way...but when
I'm trying to detect shake events in my application so that I would be
I am trying to write an iPhone App that should monitor the any incoming
I am trying to detect if a text input field has any character that
Trying to detect when a user clicks Cancel but the $_POST on using var_export($_POST)
In trying to detect a right mouse click with jquery, I noticed that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.