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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:39:41+00:00 2026-06-16T21:39:41+00:00

I am trying to store the url in a Session to be picked up

  • 0

I am trying to store the url in a Session to be picked up later when I redirect the Response to tidy up my URL. This is in the Global.asax file. I am taking the original response and storing the url in a session

    protected void Application_Error(object sender, EventArgs e)
    {
        Exception exception = Server.GetLastError();
        HttpException httpException = exception as HttpException;

        // get the url
        var url = Request.RawUrl;

        // store in session
        Session["requestUrl"] = url;

        if (exception is HttpException && ((HttpException)exception).GetHttpCode() == 404) {
            Response.Redirect("/CMS/CMS");
        }

    }

If I look at the Session contents it is in there

I then try to extract this in my CMS/CMS Action but the variable url is null??:

    public ActionResult CMS(String aspxerrorpath)
    {
        var url = Session["requestUrl"]; // this is null??

        Response.StatusCode = 404;
        Response.TrySkipIisCustomErrors = true;
        return View();
    }

Any Ideas?

  • 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-06-16T21:39:42+00:00Added an answer on June 16, 2026 at 9:39 pm

    Sorry I have no idea why the session is not working but if you want to tidy your urls then rewrite the path, don’t redirect:

    protected void Application_Error(object sender, EventArgs e)
    {
        var exception = Server.GetLastError();
        var httpException = exception as HttpException;
    
        if (exception is HttpException && ((HttpException)exception).GetHttpCode() == 404) 
        {
            Server.ClearError();
    
            // get the url
            var url = Request.RawUrl;
    
            var routeData = new RouteData();
            routeData.Values["controller"] = "Cms";
            routeData.Values["action"] = "Cms";
            routeData.Values["aspxerrorpath"] = url;
    
            IController cmsController = new CmsController();
            var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
            cmsController.Execute(rc);
        }
    }
    

    This way you don’t need to perform an additional redirect and you don’t need to be relying on Session.

    You might also checkout the following post from where I borrowed the code.

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

Sidebar

Related Questions

I am trying to store a URL in the configuration file, but it does
I'm trying to store a url such as: http://localhost/pro_print/index.php#page=home in a variable, but I
I am trying to get the public URL of a given file stored in
I am trying to store a byteArrayInputStream as File on a FTP Server .
I'm trying to store and retrieve numbers in android so later I can do
I'm trying to store the session state in a master page to keep track
I am trying to generate an URL for my pdf file stored on my
I'm trying to achieve this url on my users profile in a cleaner way:
Im trying to store a list,collection of data objects in Hbase. For example ,a
I'm trying to store an image into an SQL database without using temporary files.

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.