[SOLVED] Multiple Virtual Directories same physical folder and Main method

Answered Closed
0
0

Hi,

First let me postulate my “definition” (rather understanding) of a Wisej (Web) application: A physical folder with a bin subdirectory and a Web.config file.

Consider now the case where such an “application” can be accessed by multiple virtual directories, for example

http://www.MySite.com/client1
http://www.MySite.com/client2

http://www.MySite.com/clientN

Depending on the virtual directory “clientX”, the application decides which page to show, which database to use and so on. More than one users of each clientX can have separate sessions at the same time.

My question is, when does the “Main” method of Program run? When the application starts (when the pool is recycled, web.config changes, first request is processed)?
Or each time a new user makes a request, i.e. a new session starts? If I need to do some initialization per client, do I have to do it for all clients the first time, or can I wait till the first user of that client hits the page and runs Main, and then do the initialization of the corresponding client?

In general, do you see problems with the above configuration? Would it be better to replicate the application to many physical folders ? Losing of course the laziness of pushing a correction to all clients in one go !

And last but not least, is my initial “definition” of a Wisej (web) application correct? 🙂

Best,
Alex

 

  • You must to post comments
Best Answer
0
0

Hi Alex,

A wisej application is configured exactly as an ASP.NET/MVC app. So yes, you need an app folder, a /bin, and a web.config + a start up page and application.json.

The start up page (usually Default.html) can be configured in web.config to be the default document or can be addressed directly in the url, just like any web site.

Additionally, wisej supports a simple “pretty url” system through the json config file. Where you don’t need to specify the extension. For example: mysite.com/client1 or mysite.com/client2 will cause wisej to process client1.json and client2.json and if the json specifies an html page, wisej will internally redirect to that startup page. Tne html startup page is needed since the browser must load a page with a reference to the wisej.wx bootstrap script.

To answer you question about Main. The Program.Main method is execute when a new session is created. So it’s executed only once when an application is loaded the first time for a specific user.

Your client#.json files can each refer to a different startup method in the same class and redirect to the same startup html file if you wish. You can have Program.Main1(), Main2(), etc. There is no need to duplicate the apolication in Wisej. You can have several sub application within the same project. See also the configuration page in the /docs.

HTH

Best,
Luca

  • You must to post comments
0
0

You can use the settings property. See the last item here: https://docs.wisej.com/docs/concepts/configuration

Application.Configuration.Settings is a dynamic object so if you add:

"settings:" {value1: 1, somestring: "hello"}

You can access them:

int value1 = Application.Configuration.Settings.value1;
string value2 = Application.Configuration.Settings.somestring;

Or

int value1 = Application.Configuration.Settings["value1"];
string value2 = Application.Configuration.Settings["somestring"];
  • You must to post comments
0
0

Hi Luca,

How can I access the .json file contents from within the server code? In the scenario we have been talking with each client having their own clientX.json, it would be great to put client-specific setting in the individual .json files, but can we read them later?

Best,
Alex

  • You must to post comments
0
0

I’m not sure, but I don’t think Global.asax will work since Wisej doesn’t create an ASP.NET session.

  • You must to post comments
0
0

Thank you, Luca! TCH ! (This Certainly Helps). Actually my main question was whether the Global.asax is supported in Wisej… I suppose I could have tried before asking.

Alex

  • You must to post comments
0
0

Hi Alex,

Global.asax.OnSessionStart is executed always when a new session is initialized. It’s the same as the start up method defined in Default.json – usually Program.Main. It is executed only when a new session is created for a client. There are no subsequent sessions for a client, it’s always the first one for that client.

Global.asa.OnApplicationStart is executed only once when the application is loaded. To run something only once when your application is loaded the first time you can use a static constructor for the start up class: static Program() { … }.

You can also define static members in Program or any other class in your app and share them across sessions.

If you want to identify a specific client, regardless of the session, you may have to store a cookie that survives the session, see Application.Cookies.

HTH

Best,

Luca

  • You must to post comments
0
0

Hi,

So, if I want to do a “client-level” initialization, i.e. some code that runs only when the first session of a specific client starts, but not for the subsequent sessions, where do i put it?

I am looking for something like a Global.asax, OnSession_start, where I check if more sessions of this client have started and I do not run the code, or if this is the first session of this client  I run the code. Along these lines, in OnApplication_start I could run code for the initialization of all clients/all sessions.

Best,

Alex

  • You must to post comments
Showing 7 results