none
access the WebRole:RoleEntryPoint in Global.asax application_onStart RRS feed

  • General discussion

  • Hi...

     I am declaring some properties in WebRole.CS which is inheriting the RoleEntryPoint as default...

    Now i wanted to access the webrole object (which is created by Azure)  in AppStart method of Global.asax file

    Is that possible?

    if not possible means tell me some other ways to get an interaction between the WebRole.cs & Global.asax file...


    bin hex

    • Changed type Bin Hex Wednesday, September 5, 2012 7:48 AM
    Sunday, September 2, 2012 2:39 PM

All replies

  • I'm not sure if there's a simple way to do that, but it might be better to tell us what you are trying to do, instead
    Sunday, September 2, 2012 4:56 PM
  • Tom,

    Thanks for replying....I am trying to establish the Application context @ ApplicationStart of Global.asax file...

    The AppContext will contain the object to access the Azure Table Storage...But i could get Response from Azure Storage Server (reason : http://msdn.microsoft.com/en-us/library/microsoft.servicehosting.serviceruntime.rolemanager.aspx )

    I got the Solution for creating the TableStorageObj in Application start using http://blog.smarx.com/posts/try-to-create-tables-only-once this post...

    But i could'nt establish the AppContext in the  class "FirstRequestInitialization"

    Now i am searching a way to Create a AzureStorage object in AppStart and store that object in the AppContext...



    bin hex

    Sunday, September 2, 2012 6:26 PM
  • Hi Bin,

    I am not sure what's "AppContext" means (HttpContext ?), would you like to explain it, please? Thank you.

    It seems that you want create a table storage object in Application_start method (Global.asax file) and access it in role entry's method? Refer to Azure application life cycle,

    startup task - role's onstart method - role's run method & application_start method.

    As you see, the WebRole Run() method is called and at the same time IIS starts the websites - so at this point Application_Start will get called for the first time. So it's hardly to say which method will be complete first. I am not sure it's a good way to do this, why not just declare something in onstart method?

    Azure life cycle:

    http://blog.syntaxc4.net/?p=271

    BR,

    Arwind


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Monday, September 3, 2012 5:55 AM
    Moderator
  •  Arwind,

     I couldnt access the Azure Storage in ApplicationStart as IIS runs in integrated mode...(http://msdn.microsoft.com/en-us/library/microsoft.servicehosting.serviceruntime.rolemanager.aspx)

    "The Windows Azure fabric runs IIS 7.0 in integrated mode. In integrated mode, the Application_Start event does not support access to the request context or to the members of the RoleManager class provided by the Windows Azure SDK runtime API. If you are writing an ASP.NET application that accesses the request context or calls methods of the RoleManager class from the Application_Start event, you should modify it to initialize in the Application_BeginRequest event instead."

     So i followed this post, http://blog.smarx.com/posts/try-to-create-tables-only-once#comment-638329129

     Now, I can access Azure Storage in Application_BeginRequest.I want to store the Storage Reference objects in the Asp.net Application state, But i dont know how to store this in to Asp.net application state...


    bin hex

    Monday, September 3, 2012 6:03 AM
  • Hi Bin,

    Base on my understanding, this is not means you cant access Azure Storage in Application_start method, it's just means HttpContext is not supported, so i think you can acess storage object in Global.asax file.

    For "Now, I can access Azure Storage in Application_BeginRequest.I want to store the Storage Reference objects in the Asp.net Application state, But i dont know how to store this in to Asp.net application state...", which reference object do you want to store? Storage Connection or data? If you want to store storage connection, just declare a static variable, if data, please store them in Caching service.

    BR,

    Arwind


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    Monday, September 3, 2012 8:49 AM
    Moderator
  • Hi,

    Based on my understanding you want to create objects that interacts with storage and put them in asp.net application state. If you look at the blog what steve mentioning in that blog is a kind of creating the required tables for your application at once and keep them ready, instead you create them on the fly.

    It is very similar to the databsae approach, usually in production environment we will create DB, table structures and other related objects through one time script and point our application to DB to do the persistent operations.

    Steve is trying to do the similar kind of thing with table storage here. He mentioned there are several ways and one of them is through application_beginrequest

    Application_beginrequest fires every time when a new request comes to the site. And the job that you are trying to achieve is create tables which is one time job for the application. typically one time jobs are advised to handle through scripts. Lot of powershell scripts avaiable to create the tables in table storage for your application.

    if you are trying to create table storage reference object and want to reuse it across the application, i feel instead of doing that make use of a facade class that uses storage API internally and performance the operations you want. It is not advised to keep the heavy objects in the memory and get into problems like concurrency, freshness etc..

    Hope it helps.



    Please mark the replies as Answered if they help and Vote if you found them helpful.

    Monday, September 3, 2012 8:57 AM
  • Arwind,

     As you told once OnStart is return, The IIS App is started and at the same time the Run() method also started...

     Is there any way to communicate between the Run() method and the ApplicationStart()?


    bin hex

    Monday, September 3, 2012 10:12 AM
  • Hi Bin,

    it is not possible to communicate between run method and application start.

    Run method is the event provided by PaaS platform of azure and the application start method is provided by asp.net infrastructure.

    The role events will be fired when there is any change happens at role level. You need to understand that role is a high level container for your PaaS application and the website is a property under that. In a web role you can have more than one site.

    Also i recommend you to go through this post to understand role and its lifecycle.

    You can refer to my previous post on the same thread and let me know for any more questions.



    Please mark the replies as Answered if they help and Vote if you found them helpful.

    Monday, September 3, 2012 10:29 AM
  • Hi Bin,

    I think you need some mediators to do with this, perhaps store them in files, storage, caching service, etc.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework


    Monday, September 3, 2012 10:30 AM
    Moderator
  • i could not use caching in OnStart..

    If i use azure storage for storing i cant access it in Application_start...

    I will try storing the serialized data in local file storage in Azure Compute


    bin hex

    Monday, September 3, 2012 11:00 AM
  •  I can understand... Each class object will be run under different process... but i want to communicate in between this two process for passing some data... 


    bin hex

    Monday, September 3, 2012 11:01 AM
  • As mentioned, Role is a high level container and practically there is not common process that helps you in memory sharing that can be access from asp.net traditional objects.

    You can keep the data you want to share in table storage (easy to share) and access it from your asp.net site.

    But still, if you are talking about event sequence, there is not gurantee that your run and application events will be in sync.



    Please mark the replies as Answered if they help and Vote if you found them helpful.

    Monday, September 3, 2012 11:07 AM
  • Kumar,

     Yes storing it in Table is bit easy but retrieving from table at Application_start is not possible... 

     For synchronizing between event i can wait until my desired table will be loaded with data... 



    bin hex

    Monday, September 3, 2012 11:17 AM
  • Yes, the problem is application_start is too early to access the role environment.

    You can change the eventing to session start or application_beginrequest if its feabile.



    Please mark the replies as Answered if they help and Vote if you found them helpful.

    Monday, September 3, 2012 11:35 AM
  • Veerendra Kumar,

     If i am using session start means, my storage elements will be initialized for every session creation so its not feasible...

     I have tried Application_beginRequest... There i am getting exception "Remote Host not reachable" after several retries from Azure storage Client...


    bin hex

    Monday, September 3, 2012 11:42 AM
  • is the storage accessible from any other events? can you check once.

    BTW, begin request will be next level to you session on start it fires for every request that comes whereas session on start fires only on start of session. You can check if the object is initialized in the event and if not initialize it (singleton pattern). You might endup doing the same with begin request event also.



    Please mark the replies as Answered if they help and Vote if you found them helpful.

    Monday, September 3, 2012 12:17 PM
  •  I have tried with Application start and Application Begin Request... Both not working...

     Do you think the issue is related with this post ?

    bin hex

    Monday, September 3, 2012 12:25 PM
  • See my reply to your other post to see if it solves the problem.


    Tuesday, September 4, 2012 2:43 AM
  • Thanks for all... 

     Its working... The error "A socket operation was attempted to an unreachable network " because of proxy...
    Thank you very much...
    http://support.microsoft.com/kb/2468871 : using this fix we can access the httpresponse in Application_Start...

    bin hex

    Wednesday, September 5, 2012 7:48 AM