| | 1 | | @using System.Web; |
| | 2 | | @using System.Collections.Specialized; |
| | 3 | |
|
| | 4 | | <div class="container"> |
| | 5 | |
|
| | 6 | | <div class="row"> |
| | 7 | | <div class="col"> |
| | 8 | | <h2>Url Splitter</h2> |
| | 9 | | </div> |
| | 10 | | </div> |
| | 11 | |
|
| | 12 | | <div class="row"> |
| | 13 | | <div class="col"> |
| | 14 | | <div class="input-group mb-3"> |
| | 15 | | <input type="text" id="path" name="path" class="form-control" @bind="Path"> |
| | 16 | | <div class="input-group-append"> |
| | 17 | | <span class="input-group-text" id="urlCount">@pathLength</span> |
| | 18 | | </div> |
| | 19 | | </div> |
| | 20 | | </div> |
| | 21 | | </div> |
| | 22 | | <div class="row"> |
| | 23 | | <div class="col"> |
| | 24 | | <button id="btnPathSplit" name="btnPathSplit" class="btn btn-success float-right" |
| | 25 | | @onclick="Split">Split</button> |
| | 26 | | </div> |
| | 27 | | </div> |
| | 28 | |
|
| | 29 | | <br/> |
| | 30 | |
|
| | 31 | | <!-- Hostname --> |
| | 32 | | <div class="row"> |
| | 33 | | <div class="col-12"> |
| | 34 | | <div class="input-group mb-3"> |
| | 35 | | <div class="input-group-prepend"> |
| | 36 | | <span class="input-group-text">Hostname</span> |
| | 37 | | </div> |
| | 38 | | <input type="text" class="form-control" placeholder="hostname" aria-label="hostname" |
| | 39 | | id="hostname" name="hostname" |
| | 40 | | @bind="hostname" disabled> |
| | 41 | | </div> |
| | 42 | | </div> |
| | 43 | | </div> |
| | 44 | |
|
| | 45 | | <!-- Pathname --> |
| | 46 | | <div class="row"> |
| | 47 | | <div class="col-12"> |
| | 48 | | <div class="input-group mb-3"> |
| | 49 | | <div class="input-group-prepend"> |
| | 50 | | <span class="input-group-text">Pathname</span> |
| | 51 | | </div> |
| | 52 | | <input type="text" class="form-control" placeholder="pathname" aria-label="pathname" |
| | 53 | | id="pathname" name="pathname" |
| | 54 | | @bind="pathName" disabled> |
| | 55 | | </div> |
| | 56 | | </div> |
| | 57 | | </div> |
| | 58 | |
|
| | 59 | | <!-- Params --> |
| | 60 | | <div class="row"> |
| | 61 | | <div class="col-12"> |
| | 62 | | <table id="urlParams"> |
| | 63 | | <thead> |
| | 64 | | <tr> |
| | 65 | | <th>Key</th> |
| | 66 | | <th>Value</th> |
| | 67 | | </tr> |
| | 68 | | </thead> |
| | 69 | | <tfoot></tfoot> |
| | 70 | | <tbody> |
| 13 | 71 | | @foreach (string key in queryString) |
| 2 | 72 | | { |
| | 73 | | <tr> |
| | 74 | | <td><em>@key</em></td> |
| | 75 | | <td><em>@queryString[key]</em></td> |
| | 76 | | </tr> |
| 2 | 77 | | } |
| | 78 | | </tbody> |
| | 79 | |
|
| | 80 | | </table> |
| | 81 | | </div> |
| | 82 | | </div> |
| | 83 | |
|
| | 84 | | </div> |
| | 85 | |
|
| | 86 | | @code { |
| | 87 | | [Parameter] |
| 14 | 88 | | public string Path { get; set; } |
| | 89 | |
|
| | 90 | | int pathLength; |
| | 91 | | string hostname; |
| | 92 | | string pathName; |
| | 93 | | NameValueCollection queryString; |
| | 94 | |
|
| | 95 | | protected override void OnInitialized() |
| 2 | 96 | | { |
| 2 | 97 | | Path = "https://www.alexhedley.com/path?query=this¶m=that"; |
| 2 | 98 | | pathLength = Path.Length; |
| 2 | 99 | | queryString = new NameValueCollection(); |
| 2 | 100 | | } |
| | 101 | |
|
| | 102 | | private void Split() |
| 1 | 103 | | { |
| 1 | 104 | | pathLength = Path.Length; |
| | 105 | |
|
| 1 | 106 | | Uri uri = new Uri(Path); |
| 1 | 107 | | hostname = uri.Host; |
| 1 | 108 | | pathName = uri.AbsolutePath; |
| 1 | 109 | | queryString = HttpUtility.ParseQueryString(uri.Query); |
| 1 | 110 | | } |
| | 111 | |
|
| | 112 | | } |