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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:35:22+00:00 2026-05-28T06:35:22+00:00

In an ASP.NET MVC aspx page I have the following script: <script type=text/c# runat=server>

  • 0

In an ASP.NET MVC aspx page I have the following script:

<script type="text/c#" runat="server">
    string rl = Request.RawUrl;
</script>

the Request is underlined in Visual Studio with the following error:
An object reference is required for the non-static method, field, or property System.Web.UI.Page.Request.get

However this: <%=Request.RawUrl%> works fine.

Can you please tell me how I can get the RawUrl into the rl string variable in the script? Thanks!

This is a continuation of How to make a variable on an aspx page visible to multiple content sections on that page in ASP.NET MVC?

I basically am trying to declare an object on the page and referring to it in different parts of the page.

  • 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-28T06:35:22+00:00Added an answer on May 28, 2026 at 6:35 am

    Like that:

    <%
        string rl = Request.RawUrl;
    %>
    

    or in your particular case:

    <script type="text/C#" runat="server">
        string rl = HttpContext.Current.Request.RawUrl;
    </script>
    

    UPDATE:

    According to your comment you want to use this variable from everywhere. In this case I would recommend you writing a custom helper that will be accessible in all views:

    public static class HtmlExtensions
    {
        public static string GetSomeValue(this HtmlHelper htmlHelper)
        {
            var context = htmlHelper.ViewContext.RequestContext.HttpContext;
            var value = context.Items["__some_key__"] as string;
            if (value != null)
            {
                // the value was found in the HTTP context => no need
                // to recalculate it
                return value;
            }
    
            value = ... do some expensive calculation to fetch the value
            // store the value in the HTTP context so that the next time
            // someone calls this helper from within the current HTTP context
            // doesn't need to perform the expensive operation
            context.Items["__some_key__"] = value;
            return value;
        }
    }
    

    and then when you need the value somewhere:

    <%= Html.GetSomeValue() %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET web page(Not MVC ) (HomePage.aspx) and another page (PRiceList.aspx).I have
I have a simple ASP.NET MVC application, like movie sample. In the list.aspx page
ASP.NET MVC I have one page Index.aspx where I'm loading two usercontrols into divs.
If i have an ASP.NET MVC 2 Web Application with the following Views: Main.aspx
I am using FckEditor in Create.aspx page in asp.net mvc application. Since I need
I'm following the tutorial located at: http://www.asp.net/learn/mvc/tutorial-20-cs.aspx I created my own .Menu() method to
I have been working through Microsoft's ASP.NET MVC tutorials, ending up at this page
My web application is an Asp.Net MVC pattern. None of the .aspx pages have
Some texts on ASP.NET MVC state that there are no runat server tags, even
I have the following code in my Site.Master page of an almost empty ASP.NET

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.