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 244265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:59:25+00:00 2026-05-11T20:59:25+00:00

I use the following MSDN code on my master page to detect if the

  • 0

I use the following MSDN code on my master page to detect if the browser accepts cookies:

protected void Page_Load(object sender, EventArgs e)
{
    if(!this.IsPostBack) {
        if(Request.QueryString["CookieTest"] == null) {
            Response.Cookies["TestCookie"].Value = "Test";
            Response.Redirect("CookieCheck.aspx.redirect=" + Server.UrlEncode(Request.Url.ToString())));
        }
        else if((string)Request.QueryString["Test"] == "passed") {
            // my stuff...
        }
    }
}

The CookieCheck.aspx contains the following:

protected void Page_Load(object sender, EventArgs e)
{
    if(Request.Cookies["TestCookie"] == null)
        Response.Redirect(Request.QueryString["redirect"] + "?Test=notPassed", true);
     else
        Response.Redirect(Request.QueryString["redirect"] + "?Test=passed", true);
}

Within the web.config i have defined the following:

<customErrors mode="On" defaultRedirect="Error.aspx" />

Now the recognizing of the cookies works well, but I have this problem: Whenever an error occurs on the page and I should be redirected to Error.aspx (and this worked before the whole cookie detection thing), the redirection seems stuck in an infinite loop and appends more and more “?Test=passed” to the URL. I should mention that the Errors.aspx also has the same masterpage and thus also performs the cookie check. However I have no clue why the redirection doesn’t stop. Is there a way to solve this problem other than to exlude the Errors.aspx page from having the master page? Thank you very much.

  • 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-11T20:59:25+00:00Added an answer on May 11, 2026 at 8:59 pm

    If the CookieCheck.aspx page also uses the same Master page it will keep redirecting recursively, make sure that CookieCheck.aspx is not using the same MasterPage.

    I’d rather recommend not using MasterPages for this, Master Pages by design are for Visual Inheritance not code Inheritance, if you wish to make some special type of pages that checks for the the browser ability to use cookies, you can have a new base class for these pages

    public abstract class CookieEnabledPage : Page
    {
    }
    

    and add your logic to this class, then whenever you need to make a new page with this behavior you inherit from this base class. I think this is a much cleaner way of doing what you want.

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

Sidebar

Related Questions

I came across the following code on msdn: unsafe static void SquarePtrParam (int* p)
I use following code: Create a retry policy, when error, retry after 1 second,
I just use following code to add an image to my project, var paper
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have an array of objects, and i use following code to get in
The following MSDN example promises to demonstrate how to use the .NET BackgroundWorker from
I can use the following code for tiny little queries: DECLARE @sql VARCHAR(8000) SET
When I use the following code to write to Application Event log, everything works
For the following code, I would expect result to equal 2, because the MSDN
I have the following code: public void DrawLetter(int Cell, string Letter, int X, int

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.