Click here to Skip to main content
15,887,746 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 6:34
Kirk 1038982126-Apr-18 6:34 
GeneralRe: Fun with double Pin
raddevus26-Apr-18 13:19
mvaraddevus26-Apr-18 13:19 
GeneralRe: Fun with double Pin
Super Lloyd26-Apr-18 13:40
Super Lloyd26-Apr-18 13:40 
GeneralRe: Fun with double Pin
Peter_in_278026-Apr-18 15:03
professionalPeter_in_278026-Apr-18 15:03 
GeneralRe: Fun with double Pin
#realJSOP7-May-18 8:33
mve#realJSOP7-May-18 8:33 
GeneralRe: Fun with double Pin
Super Lloyd7-May-18 11:51
Super Lloyd7-May-18 11:51 
GeneralRe: Fun with double Pin
#realJSOP8-May-18 1:10
mve#realJSOP8-May-18 1:10 
Generaldotnet core web api : generate sub-webs for users Pin
raddevus20-Apr-18 10:43
mvaraddevus20-Apr-18 10: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
C#
[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 11:35
mveRichard Deeming20-Apr-18 11:35 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus20-Apr-18 12:06
mvaraddevus20-Apr-18 12:06 
PraiseRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland20-Apr-18 21:13
mveRickZeeland20-Apr-18 21:13 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 7:00
mvaraddevus21-Apr-18 7:00 
PraiseRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland21-Apr-18 7:02
mveRickZeeland21-Apr-18 7:02 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 7:06
mvaraddevus21-Apr-18 7:06 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland21-Apr-18 7:21
mveRickZeeland21-Apr-18 7:21 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 8:35
mvaraddevus21-Apr-18 8:35 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus21-Apr-18 11:31
mvaraddevus21-Apr-18 11:31 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland21-Apr-18 20:01
mveRickZeeland21-Apr-18 20:01 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus22-Apr-18 3:24
mvaraddevus22-Apr-18 3:24 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
RickZeeland22-Apr-18 3:44
mveRickZeeland22-Apr-18 3:44 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
englebart26-Apr-18 1:53
professionalenglebart26-Apr-18 1:53 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus26-Apr-18 2:04
mvaraddevus26-Apr-18 2:04 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
Marc Clifton2-May-18 12:43
mvaMarc Clifton2-May-18 12:43 
GeneralRe: dotnet core web api : generate sub-webs for users Pin
raddevus3-May-18 1:31
mvaraddevus3-May-18 1:31 
GeneralWell - its not private any more... PinPopular
Duncan Edwards Jones9-Apr-18 23:47
professionalDuncan Edwards Jones9-Apr-18 23: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.