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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:58:20+00:00 2026-05-23T07:58:20+00:00

I am planning on creating a custom route using ASP.NET Web Pages by dynamically

  • 0

I am planning on creating a custom route using ASP.NET Web Pages by dynamically creating WebPage instances as follows:

IHttpHandler handler = System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath("~/Default.cshtml");

How can I supply an object to the underlying WebPage object so that it can become the web pages’s “Model”? In other words I want to be able to write @Model.Firstname in the file Default.cshtml.

Any help will be greatly appreciated.

UPDATE

By modifying the answer by @Pranav, I was able to retrieve the underlying WebPage object using reflection:

    public void ProcessRequest(HttpContext context)
    {
        //var page = (WebPage) System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(this.virtualPath);

        var handler = System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(this.virtualPath);
        var field = handler.GetType().GetField("_webPage", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        var page = field.GetValue(handler) as System.Web.WebPages.WebPage;

        var contextWrapper = new HttpContextWrapper(context);
        var pageContext = new WebPageContext(contextWrapper, page, context.Items[CURRENT_NODE]);

        page.ExecutePageHierarchy(pageContext, contextWrapper.Response.Output);
    }

Unfortunately this is not reliable as it does not work in Medium Trust (BindingFlags.NonPublic is ignored if application is not running in full trust). So while we have made significant progress, the solution is not yet complete.

Any suggestions will be greatly appreciated.

  • 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-23T07:58:20+00:00Added an answer on May 23, 2026 at 7:58 am

    The Model property of a WebPage comes from the WebPageContext. To set a Model, you could create a WebPageContext with the right parameters:-

    var page = (WebPage)WebPageHttpHandler.CreateFromVirtualPath("~/Default.cshtml");
    var httpContext = new HttpContextWrapper(HttContext.Current);
    var model = new { FirstName = "Foo", LastName = "Bar" };
    var pageContext = new WebPageContext(httpContext, page, model);
    
    page.ExecutePageHierarchy(pageContext, httpContext.Response.Output);
    

    The model instance should now be available as a dynamic type to you in your page.

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

Sidebar

Related Questions

I'm creating a custom MembershipProvider for an ASP.NET MVC website, and I was planning
I'm planning on creating a browser based RTS game using ASP.NET and MySQL. I
I'm planning on creating a small web app using PHP. The last time I
We're planning to create a web application where users can build custom forms, choosing
I'm planning on creating a view using this SQL SELECT, but the explain for
I am creating an ASP.NET application in which the administrator of the program will
I am new in creating web applications in Windows. I am planning to do
So, I'm planning on creating a reminder app for WP7 using the Microsoft.Phone.Scheduler class,
I'm planning on creating a game that contains a landscape with objects on it.
I'm planning on creating a social networking + MP3 lecture downloading / browsing /

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.