0

As searching has returned very little, my question is simple yet seems to have a complicated explaination. How does one go about processing and sending aspx pages that don't have a physical location (i.e. the apsx page is built in a string or is an embedded resource) to the client? I've had a look at the SimpleWorkerRequest but the only thing I could find was that it needed a physical file to play with. I've also looked at HttpWorkerRequest which was suggested on a page I cant find that it doesnt need physical pages. Also browsed across AspNetServer by lcomplete but I found it hard to follow as half of it seems to be complletely unused, half the comments are in simplified chinese, and half english. If anyone could shed a little light on this it would be greatly appreciated.

3
Contributors
13
Replies
76
Views
2 Years
Discussion Span
Last Post by Smalls
0

Hi

Can I ask why you would want to do this? Can you not have a physical aspx page that can be rendered according to whatever needs you have. You obviously have some logic somewhere as you mention building a string, so could this logic be applied to rendering a physical aspx page?

0

I would like to embed the pages to keep file count down and also so they will be hidden. The mentioning of them being is a string was mainly for example as it would have to either be passed as a string or at least an object of some sort.

0

Hi

This smells bad. I mean that nicely in that it smells of a bad design. There are many ways to ensure that your pages are protected from unauthorised use (if that is your concern) and with a properly design and architected site your file count shouldn't be too large unless it is a huge web site.

What type of page would you be serving to the browser that you want to do this via a non physical aspx page? The more info you can give us the more we can either come up with a solution to your explicit question or think of a more suitable and best practice approach.

0

Well... it will be an application which will dl, install, and manage game servers via steam, have permission based user login, etc etc all through a hosted web interface

0

Hi

I'm not totally versed with steam but this doesn't sound like it is a huge site. Have you already got a site in development or are you exploring options at this stage?

Also, what level of programming are you at? I don't want to teach you to suck eggs if you already know a lot of stuff.

0

I know enough to get to where I want/need to be, but this one has me looking for answers

It is going to be a realtivley small site (10-15 pages I think). I've got a webserver made capable of serving aspx pages, I cant seem to find a way to render them from say a string or object instead of a file.

Edited by Smalls

1

In addition to routing to a single ASPX page you could also consider creating this using ASP.NET MVC. This would allow you to use controllers to return a string of HTML to a view meaning that you could have one view that multiple controllers (back end code) would then serve the HTML string to the single view. Admittedly, this is still a bad approach as your server side code would be building presentation code which breaks the "separation of concerns".

However, MVC also supports the passing of Models to a View. Models (classes) contain your data and the View can be strongly typed to a Model allowing you to build objects in your server side code and pass these to the View.

0

I'm just looking for a way to pass the file contents instead of the path to the file. Once I get this out of the way, everything else should be easy to do.

Also I know nothing of MVC...

Edited by Smalls

0

So if I understand correctly, you have a file on your sever (let's say a PDF file for example) and instead of the user of your site clicking a link that directly accesses that PDF file you want to stream it to them?

Will you know the path to that file from a code perspective?

0

Not quite... Something like a pdf can just be sent to the client. What I'm after is, instead of the aspx pages sitting in a directory on the server, have the aspx pages as embedded resources in the application itself. Sending embedded reosurces isnt a problem until its an aspx page. The problem I'm having is that SimpleWorkerRequest wont take anything but a physical address to the aspx file. I'm just trying to find a way to pass the file itself or its contents to the host to have it rendered to html so it can be sent.

Heres a slimmed down of what I have at the moment.

private static void StartServer()
{
    SimpleHost host = (SimpleHost)ApplicationHost.CreateApplicationHost(
        typeof(SimpleHost), "/", System.IO.Directory.GetCurrentDirectory());

    HttpListener listener = new HttpListener();
    listener.Prefixes.Add("http://localhost:8080/");
    listener.Start();
    Console.WriteLine("Listening for requests");

    while (true)
    {
        HttpListenerContext context = listener.GetContext();
        string page = context.Request.Url.LocalPath.Replace("/", "");
        Console.WriteLine(page);
        string query = context.Request.Url.Query.Replace("?", "");
        using (var writer = new StreamWriter(context.Response.OutputStream))
        {
            host.ProcessRequest(page, query, writer);
        }
        context.Response.Close();
    }
}

public class SimpleHost : MarshalByRefObject
{
    public void ProcessRequest(string page, string query, TextWriter writer)
    {
        SimpleWorkerRequest swr = new SimpleWorkerRequest(page, query, writer);
        HttpRuntime.ProcessRequest(swr);
    }
}
0

Can anyone give a rundown on how to get HostingEnvironment.RegisterVirtualPathProvider(new CustomVirtualPathProvider()); to work?
All I can get from it is 'operation is not valid due to the current state of the object.'

Edited by Smalls

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.