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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:36:24+00:00 2026-05-13T14:36:24+00:00

protected void Application_BeginRequest(object sender, EventArgs e) { const int maxFileSizeKBytes = 10240; //10 MB

  • 0
protected void Application_BeginRequest(object sender, EventArgs e)
    {


        const int maxFileSizeKBytes = 10240; //10 MB
        const int maxRequestSizeKBytes = 305200; //~298 MB

        if (Request.ContentLength > (maxRequestSizeKBytes * 1024))
        {
            Response.Redirect(".aspx?requestSize=" + Request.ContentLength.ToString());
        }


        for (int i = 0; i < Request.Files.Count; i++)
        {
            if (Request.Files[i].ContentLength > (maxFileSizeKBytes * 1024))
            {
                Response.Redirect(".aspx?fileSize=" + Request.Files[i].ContentLength.ToString());
            }
        }

    }

This code is in Global.asax.cs page.
I need to redirect to the page that triggered this check. And I need to know the ticketId or projectId parameter. For example I create new ticket at the View Project page /Project/ViewProject.aspx?projectId=1 I need to redirect to this page with a meaningful message to the user, because I think that redirecting to another page to display the error message is not a good idea.

  • 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-13T14:36:24+00:00Added an answer on May 13, 2026 at 2:36 pm

    Why don’t you put these checks in the Load handler of a base Page class that ViewProject (and anything else needing the checks) derives from? Then you can just make an error Label visible if the check fails. Untested code:

    public class BasePage : Page{
      protected virtual Label ErrorLabel { get; set; };
      protected override OnLoad(object sender, EventArgs e) {
        base.OnLoad(sender, e);
    
        const int maxFileSizeKBytes = 10240; //10 MB
        const int maxRequestSizeKBytes = 305200; //~298 MB
    
        if (Request.ContentLength > (maxRequestSizeKBytes * 1024))
        {
            ErrorLabel.Text = "Request length "+Request.ContentLength+" was too long."
            ErrorLabel.Visible = true;
        }
    
    
        for (int i = 0; i < Request.Files.Count; i++)
        {
            if (Request.Files[i].ContentLength > (maxFileSizeKBytes * 1024))
            {
                ErrorLabel.Text = "File length "+ Request.Files[i].ContentLength +" was too long."
                ErrorLabel.Visible = true;
            }
        }
      }
    }
    
    public class ViewProject : BasePage {
      protected override Label ErrorLabel {
        get { return LocalErrorLabel; } // something defined in HTML template
        set { throw new NotSupportedException(); }
      }
    }
    

    This way you stay on the same page and you already have ticketId and projectId.

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

Sidebar

Related Questions

Global.asax Code protected void Application_BeginRequest(object sender, EventArgs e) { string fullOrigionalpath = Request.Url.ToString(); if
In globa.asax.cs i use this code for cultre protected void Application_BeginRequest(object sender, EventArgs e)
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.GetLeft.Value = invited.GetInviteCountByWeb().ToString(); HttpCookie
protected void Button3_Click(object sender, EventArgs e) //export { GridView2.AllowPaging = false; GridViewExportUtil.Export(Сводка.xls, this.GridView2); GridView2.AllowPaging
protected void GridView1_DataBound(object sender, EventArgs e) { GridView1.Columns[0].ItemStyle.Width = 400; <asp:GridView ID=GridView1 runat=server DataSourceID=ObjectDataSource1
protected void Button1_Click(object sender, EventArgs e) { System.Collections.ArrayList list = new System.Collections.ArrayList(); list.Add(abc); list.Add(xyz);
Then: protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { CheckBoxList1.Items.Add(new ListItem(item1)); CheckBoxList1.Items.Add(new
I have this: protected void Page_Load(object sender, EventArgs e) { nome_Txt.Text = Profile.dados_pessoais.nome; }
I have setup custom error as follows.. protected void Application_Error(Object sender, EventArgs e) {
Here’s my code behind: protected void gvviewapproval_RowUpdated(object sender, GridViewUpdatedEventArgs e) { using (SqlConnection cn

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.