Web Server - Default WebEvent

Is it possible to contribute in the Gadgeteer source code?

Should be very nice to add such code in the WebServer class

        /// <summary>
        /// Gets the WebServerManager instance, which is handled as a singleton. 
        /// </summary>
        /// <returns>The <see cref="T:GTM.NetworkModule.WebServerManager"/> instance</returns>
        public static WebServerManager GetInstance()
            if (serverManager == null)
                serverManager = new WebServerManager();
                serverManager.DefaultEvent = new WebEvent("index.html");
                serverManager.DefaultEvent.ResponseData = Encoding.UTF8.GetBytes("<html><head></head><body><h1>Hey, it works:-)</h1><p>Your own .NET Gadgeteer Web Server is up and running!</p></body></html>");
                serverManager.DefaultEvent.ContentType = "text/html";

And this code in the WebServerManager class:

        /// <summary>
        /// Update the Default Web Event for the server so that an http GET request can be processed.
        /// </summary>
        /// <returns>A <see cref="T:GTM.NetworkModule.WebEvent"/> object that is used to update data and respond to incoming requests.
        /// </returns>
        public static WebEvent GetDefaultWebEvent()
            return WebServerManager.GetInstance().DefaultEvent;

In this way it would be possible to access the Default WebEvent!!!

Your own .NET Gadgeteer Web Server is up and running! is not an option for a professional purpose!!!

Could you just use extension methods (Extension Methods (C# Programming Guide) | Microsoft Learn)?


public static WebServerManager GetInstance(this WebServerManager)

public static WebEvent GetDefaultWebEvent(this WebServerManager)

then you don’t need to change the core

btw, is serverManager static as well?

I know Extension Methods… the problem is that WebServerManager is “internal” so i cannot have extension methods…

The place to contribute this is http://gadgeteer.codeplex.com/workitem/list/basic

But I think there’s something you’re not doing or understanding. I can’t quite pinpoint it though. To me you only see the “hey it’s running” text if you don’t provide your own handler for a site. (although I agree, it would be better to have some more generic text there that says something like “You’ve reached the default website for <device/URI>.” rather than the text you see today)

The use case is:

if the client try to open a link that do notte exist the homepage will bhe shown.

i think this cannot be donne with the actual code.
isn’t ?

thanks for the link… i LL re ad later.

Page not found is usually generates a 404 error, not redirected to the home page - but your call. From the quick look I made at the code http://gadgeteer.codeplex.com/SourceControl/changeset/view/24955#200081 I believe that text is only added when there is no handler at all - so if you add a handler then you should have any page you want.

404 is the standard pattern for a full web server. but doen’t matyer… re ad again my sue case. that si what i would like to do… and configuring even a full web server si possibile using some configuration.

anyway look better at the code… getwebeventbyid.

if no web event found for the path specified it will sue the default handler. and… i would like just to change that default… i think it s easy and general purpose!