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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:48:08+00:00 2026-05-24T02:48:08+00:00

I have user global.asax and I have write this code in my ASP.NET application

  • 0

I have user global.asax and I have write this code in my ASP.NET application :

    <%@ Application CodeBehind="Global.asax.cs" Language="C#" %>

<script RunAt="server">
    public void Application_Start()
    {
        string str = Context.Request.Url.AbsoluteUri.Replace("http", "https");
        Context.RewritePath(str);
    }
</script>

but it gives me this :

"Request is not available in this context"
  • 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-24T02:48:10+00:00Added an answer on May 24, 2026 at 2:48 am

    From http to https you need to make redirect.

    The main reason the RewritePath is not working is because the http and https work on different ports. Also the Application Start is not the place to call this thinks. The BeginRequest is the one.

    So if you like to change all the request automatically to https, use this code.

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;
        string cTheFile = HttpContext.Current.Request.Path;
        string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);
        if (sExtentionOfThisFile.Equals(".aspx", StringComparison.InvariantCultureIgnoreCase))
        {
            if (!app.Context.Request.IsSecureConnection)
            {
                Response.Redirect(app.Context.Request.RawUrl.Replace("http://", "https://"), true);
                return;
            }
        }
    
        // rest of your code here and below
    }
    

    You can also use this module to make this switching automatically.

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

Sidebar

Related Questions

I have created an asp.net application in which i have used global.asax. I have
I created a global.asax file for an asp.net application. I run some code in
I have an asp.net application, and I am using FormsAuthantication. When the user closes
I have implemented SQL Server session mode for an asp.net application. <sessionState mode=SQLServer compressionEnabled=true
In the Global.asax's Application_Error() method in my MVC3 application, I have the following code
In an ASP.NET (2.0) application I use FormsAuthentication. In the Global.asax / Application_AuthenticateRequest method
In my global.asax I have url routing setup like below: routes.MapPageRoute(User Logon, {Vendor}/Logon, ~/Logon.aspx);
I have the Global.asax like the code below: public class MvcApplication : System.Web.HttpApplication {
Our code relies on checking the Context.User.Identity value in the Global.asax Application_AuthenticateRequest(...) method to
I have a situation where I user IoC (WindsorContainer) in a .Net web application,

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.