[Mono-list] Re quest object

Ben Joldersma ben at skullsquad.com
Thu Jun 26 15:02:48 EDT 2008


Allen,

What I typically do in situations like this is create a separate class that
handles my application logic, and then create two wrapper programs that
consume the class:

public class MyApp {
    public void Execute( params string[] args )
    {
        foreach( string arg in args )
        {
            System.Console.WriteLine( arg );
        }
    }
}

//compile this into an assembly and reference it in two projects, one
ASP.NET project and one command line project:

//ASP.NET project, find your Page_Load method:

void Page_Load()
{
    MyApp myApp = new MyApp();
     myApp.Execute( Request.QueryString["arg1"], Request.QueryString["arg2"]
);
}

//CLI project:

public class CLIClient
{
    public static void Main( string[] args )
    {
        MyApp myApp = new MyApp();
        myApp.Execute( args );
    }
}

there's also some neat command line argument parsing libraries out there,
that can help you along this path a bit as well.

good luck!

--ben

On Thu, Jun 26, 2008 at 11:40 AM, Iggy MA <iggy.ma at gmail.com> wrote:

>
> You are actually talking about 2 different things. Request.QueryString
> works
> only in Asp.Net and refers to the Url Query String. If you had a url like
> www.mysite.com?id=2, then id=2 would be the querystring, so you would do
> System.Console.WriteLine( Request.QueryString["id"] ); and the output would
> be 2. This will not work in a regular program because there is no url
>
>
>
> http://iggyma.blogspot.com/
>
>
>
>
> theallan wrote:
> >
> > Hello all,
> >
> > I'm afraid this is probably a total newbie question, but I can't seem to
> > find an answer for it. I'm looking to write a C# program which can be
> used
> > either on a CLI or as a web-based script. To this end I want to be able
> to
> > use the 'Request.QueryString' array to retrieve GET data. So I do
> > something like this:
> >
> > public class Test
> > {
> >       static void Main()
> >       {
> >               System.Console.WriteLine( Request.QueryString["hello"] );
> >       }
> > }
> >
> > But when I compile it I get:
> >
> > $ gmcs test.cs
> > test.cs(6,43): error CS0103: The name `Request' does not exist in the
> > current context
> > Compilation failed: 1 error(s), 0 warnings
> >
> > I don't understand what I am doing wrong. Does this work only in an
> > ASP.NET environment, am I missing a 'using' statement? I can't seem to
> > find any documentation for this. Any suggestions would be greatly
> > appreciated!
> >
> > Thanks
> > Allan
> >
>
> --
> View this message in context:
> http://www.nabble.com/Request-object-tp18139827p18140555.html
> Sent from the Mono - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>



-- 
ben joldersma
software architect
http://skullsquad.com
[o]: 206.973.8003
[c]: 206.349.2852
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20080626/7dd09990/attachment.html 


More information about the Mono-list mailing list