Click here to Skip to main content
13,768,837 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Fun with double Pin
Kirk 1038982126-Apr-18 7:34
memberKirk 1038982126-Apr-18 7:34 
GeneralRe: Fun with double Pin
raddevus26-Apr-18 14:19
mvpraddevus26-Apr-18 14:19 
GeneralRe: Fun with double Pin
Super Lloyd26-Apr-18 14:40
memberSuper Lloyd26-Apr-18 14:40 
GeneralRe: Fun with double Pin
Peter_in_278026-Apr-18 16:03
professionalPeter_in_278026-Apr-18 16:03 
GeneralRe: Fun with double Pin
John Simmons / outlaw programmer7-May-18 9:33
professionalJohn Simmons / outlaw programmer7-May-18 9:33 
GeneralRe: Fun with double Pin
Super Lloyd7-May-18 12:51
memberSuper Lloyd7-May-18 12:51 
GeneralRe: Fun with double Pin
John Simmons / outlaw programmer8-May-18 2:10
professionalJohn Simmons / outlaw programmer8-May-18 2:10 
Generaldotnet core web api : generate sub-webs for users Pin
raddevus20-Apr-18 11:43
mvpraddevus20-Apr-18 11:43 
First of all, the code is super insecure.

This code allows anyone to hit a URL on my web site and create a user directory and one html file (which I fill in with their user name).
** EDIT **
I've implemented SSL on the site (as of 2018-04-25) so you can use the HTTPS version to try it if you like:
https://newlibre.com[^]
** END EDIT **

Usage
I've posted this at my web site : NewLibre.com[^]
To try it out you just hit : http://newlibre.com/api/values/<username> where <username> is a string representing the user name you'd like to create. It cannot include characters that don't work in a directory (because it creates a directory based upon your user name).
Sample
Here's a sample you can try : http://newlibre.com/api/values/superstar

If someone gets there before you, it simply notices that the directory and file is already created and redirects you there.

What Happens
When you navigate to the URL (get) the system:
1. creates a directory under my web site named after your username
2. generates a default html file with your user name in it
3. redirects you to the newly created page and loads it.

I'm Being Absurd
Isn't this absurd!?! I'm letting you navigate to a URL and generate a new folder and html page on my web server.

I know this opens me up for everyone create a new folder and just being mean-spirited but this is a prototype and I'm amazed at how simple the code is.

Also, they are created in a subdir and I will just delete the subdir. Smile | :)

I hope you find this interesting (and Weird & Wonderful).

This Is all The code it takes to do that
[HttpGet("{userName}")]
        public HttpResponse Get(string userName)
        {
            var currentDir = Directory.GetCurrentDirectory();
            DirectoryInfo di = Directory.CreateDirectory(Path.Combine(currentDir,@"wwwroot\allUsers\",userName));
            string allHtml = $"<!doctype html><html><head><title>newlibre\\{userName}</title></head><body>newlibre\\{userName}</body></html>";
            string htmlFileName = Path.Combine(di.FullName, $"{userName}.htm");
            if (!System.IO.File.Exists(htmlFileName))
            {
                System.IO.File.AppendAllText(htmlFileName, allHtml);
            }
            var newUrl = "http://" + HttpContext.Request.Host + "/allUsers/" + userName + "/" + $"{userName}.htm";
            Response.Redirect(newUrl);
            return Response;
        }


EDIT
I've altered the default page which is generated when you enter your userName, so it now looks like :


https://i.stack.imgur.com/rXxXB.png^

The new template that is created loads the daily dilbert strip!!
I hope you find that quite cool.
Also, if you type a dilbert.com daily strip link and click the button it will get that one and display it on your page (ie link will be like http://dilbert.com/2018-04-01)

New Content Each Day
Also, when you visit your page each day the newest dilbert will be displayed.
Although depending upon browser, it may take a manual refresh.

EDIT 2 - New Feature
I've now made it possible to generate your new (sub) web site based upon your user name by :
1) entering your user name in the text box
2) pressing the [Create UserName] button.

I simply added it at the top of the default page (which is ugly)
https://i.stack.imgur.com/zrgDW.png[^]

So now you can just go to the main web site (NewLibre.com[^]) and try it out.

I Know
This is getting ridiculous and needs to be an article. This is the prototype to something much larger.

EDIT 3 - More features
I now add a little message that the home page is created for the new user.
It looks like :
https://i.stack.imgur.com/Ivwr1.png[^]

I'll stop now. Smile | :)
I'm far enough with the prototype that it shows me what I can do.
More to come with a real article soon (hopefully).

modified 25-Apr-18 13:46pm.

GeneralRe: dotnet core web api : generate sub-webs for users Pin
Richard Deeming20-Apr-18 12:35
mvpRichard Deeming20-Apr-18 12:35 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus20-Apr-18 13:06
mvpraddevus20-Apr-18 13:06 
PraiseRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland20-Apr-18 22:13
mvpRickZeeland20-Apr-18 22:13 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 8:00
mvpraddevus21-Apr-18 8:00 
PraiseRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland21-Apr-18 8:02
mvpRickZeeland21-Apr-18 8:02 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 8:06
mvpraddevus21-Apr-18 8:06 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland21-Apr-18 8:21
mvpRickZeeland21-Apr-18 8:21 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 9:35
mvpraddevus21-Apr-18 9:35 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 12:31
mvpraddevus21-Apr-18 12:31 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland21-Apr-18 21:01
mvpRickZeeland21-Apr-18 21:01 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus22-Apr-18 4:24
mvpraddevus22-Apr-18 4:24 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland22-Apr-18 4:44
mvpRickZeeland22-Apr-18 4:44 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
englebart26-Apr-18 2:53
memberenglebart26-Apr-18 2:53 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus26-Apr-18 3:04
mvpraddevus26-Apr-18 3:04 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
Marc Clifton2-May-18 13:43
protectorMarc Clifton2-May-18 13:43 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus3-May-18 2:31
mvpraddevus3-May-18 2:31 
GeneralWell - its not private any more... PinPopular
Duncan Edwards Jones10-Apr-18 0:47
professionalDuncan Edwards Jones10-Apr-18 0:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181116.1 | Last Updated 18 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid