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

  • SEARCH
  • Home
  • 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 6057699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:31:02+00:00 2026-05-23T08:31:02+00:00

I am trying to compile the following code: public static void RequireOrPermanentRedirect<T>(this System.Web.UI.Page page,

  • 0

I am trying to compile the following code:

public static void RequireOrPermanentRedirect<T>(this System.Web.UI.Page page, string QueryStringKey, string RedirectUrl, out T parsedValue)
{
    string QueryStringValue = page.Request.QueryString[QueryStringKey];

    if (String.IsNullOrEmpty(QueryStringValue))
    {
        page.Response.RedirectPermanent(page.ResolveUrl(RedirectUrl));
    }

    try
    {
        parsedValue = (T)Convert.ChangeType(QueryStringValue, typeof(T));
    }
    catch
    {
        page.Response.RedirectPermanent(RedirectUrl);
    }
}

But I am getting a compiler error:

Error   1   The out parameter 'parsedValue' must be assigned to before control leaves the current method

Its an extension method which I have been using for a while but I wanted to extend it a little bit so that I didnt have to reparse the value to use it inside the page.

Current usage:

Page.RequireOrPermanentRedirect<Int32>("TeamId", "Default.aspx");
int teamId = Int32.Parse(Request.QueryString["TeamId"]);

What I wanted to be able to do:

private Int32 teamId;

protected void Page_Load(object sender, EventArgs e)
{
    Page.RequireOrPermanentRedirect<Int32>("TeamId", "Default.aspx", out teamId);
}

The current (working) code I have just creates and throws away a T value:

try
{
    T value = (T)Convert.ChangeType(QueryStringValue, typeof(T));
}
  • 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-23T08:31:03+00:00Added an answer on May 23, 2026 at 8:31 am

    The method is fine, but you need to do something in the case that an Exception happens, since you don’t re-throw. That means you could exit the method (after an exception in ChangeType) without giving it a value.

    In this case, maybe:

    catch
    {
        parsedValue = default(T);
        page.Response.RedirectPermanent(RedirectUrl);        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I'm trying to download a web page with the following code: public partial
I am trying to compile the following code: private String dataToString(){ Map data =
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
i am trying to compile this very simple piece of code class myList {
I'm having problems when trying to compile the following code: I first tried compiling
I am trying to create instance of class javax.servlet.ServletException with following code public class
Should the following code give a warning? class Foo { public void Do() {
I am trying to get the following code to compile but am getting errors
While trying to compile the code below: template <class T> struct scalar_log_minimum { public:
I have a question regarding the following code: abstract class a { public static

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.