WebShell is a request driven RESTful design pattern so it's mainly depending on HTTP request, WebShell Dispatcher analyze the request to get Command and the verb of request (POST, GET, PUT and DELETE) and then invoke the command to execute the appropriate method.
i.e. this URL #http://localhost:11507/Pages/security/login by ignoring the part "11507/Pages/" which is inserted by Visual studio built-in web server so security is the name of command and login is a sub-command or method inside the command in this case login is a method so according to request verb security command will execute login_get() or login_post()
Editing web.config file to enable WebShell to manage web application
a. add the following custom section to <configSections>...</configSections>
<section name="webShell" type="WebShell.Utilities.Configuration.Section.WebShellSection,WebShell.Utilities" />
b. add WebShell section to web.config file
c. override asp.net handler to use WebShell Handler<webShell> <commands> <add name="dispatcher" providerType="WebShell.Providers.Command.DispatcherCommand,WebShell.Providers.Command"></add> <add name="security" providerType="WebShell.Providers.Security.Security,WebShell.Providers.Security"></add> <add name="presenter" providerType="WebShell.Providers.UI.Presenter,WebShell.Providers.UI"></add> <add name="logger" providerType="WebShell.Providers.Log.Logger,WebShell.Providers.Log"></add> </commands> <settings> </settings> </webShell><system.web> <httpHandlers> <add verb="*" path="*" type="WebShell.ShellHandler,WebShell" /> </httpHandlers>
4. Create new command add class that implements ICommand WebShell interface class, this Command class will mapped to HTTP URL using WebShell config file commands section for example we will create command that mange users (registration, roles and profile) so we will create users command like this
using System; using System.Collections.Generic; using System.Text; using WebShell.ClassLibrary; using System.Web; using WebShell.Utilities; using WebNote.ViewModels; using WebNote.DB.Business; using System.Web.Script.Serialization; using System.Reflection; namespace WebNote.Users { [WebShell.ClassLibrary.LoginRequired()] public class UsersCommand:ICommand { static IPresenter presenter = ObjectBuilder.CreateFrom(WebShellConfig.GetCommandType("presenter")).Data as IPresenter; #region ICommand Members public IResult Execute(string command) { IResult result = new Result(); string strCommandName = GetCommand(command); string strMethodName = strCommandName.ToLower() + "_" + HttpContext.Current.Request.HttpMethod.ToLower(); MethodInfo mi = ObjectBuilder.GetMethodInfo(this, strMethodName); result = mi.Invoke(this, null) as IResult; return result; } public string GetCommand(string command) { string strCommandName = command.ToLower(); if (strCommandName.StartsWith("/")) { strCommandName = strCommandName.Remove(0, 1); } if (strCommandName!= string.Empty)strCommandName = strCommandName.Split('/')[0]; else strCommandName = "default"; return strCommandName; } #endregion #region Command URL Methods public IResult Default_GET() { IResult result = new Result(); result = presenter.GetViewHTML("home.htm"); return result; } public IResult Default_POST() { IResult result = new Result(); dynamic view = new NoteView(); presenter.SetViewModel(view, HttpContext.Current.Request); return result; } IResult Register_GET() { IResult result = new Result(); result = presenter.GetViewHTML("adduser.htm"); return result; } IResult Register_POST() { IResult result = new Result(); HttpRequest httpRequest = HttpContext.Current.Request; dynamic view = new UserView(); presenter.SetViewModel(view, httpRequest); long userId = WebNoteBiz.AddUser(view.Email, view.Password); WebShell.Utilities.User.Id = userId; WebShell.Utilities.User.Email = view.Email; HttpContext.Current.Session["activeMI"] = "public_notes"; HttpContext.Current.Response.Redirect(AppData.GetBaseUrl()); return result; } #endregion } }
and then update WebShell config file to map command to group of web request that starts with Users like this url #http://localhost/users/register
<webShell> <commands> <add name="users" providerType="WebNote.Users.UsersCommand,WebNote.Users"></add>
You can see that Users is the command and Register is a method, for more details you can download example web application (WebNote) to see more details about WebShell.