开发者

How to use RoleEnvironment.CurrentRoleInstance.Id in _LogOnPartial.cshtml or _Layout.cshtml file?

I am 开发者_运维百科unable to use RoleEnvironment.CurrentRoleInstance.Id in cshtml file of mvc 3 razor. An error for RoleEnvironment says that it does not exist in the current context. However, I have added the namespace as below in web.config file of Views folder. Note that "Microsoft.WindowsAzure.ServiceRuntime" namespace is added as the last namespace. Could you please let me know how to fix this? I want to output the current instance's id on the top of the page for every page without having to code in all pages.


So its compiling and executing correctly? Are you sure you are starting the azure project (so it runs under the Compute Emulator) and not starting the site directly for debug?

I just tried it and it works fine for me, had to add this to config:

<system.web>
<compilation debug="true" targetFramework="4.0">
  <assemblies>
      <add assembly="Microsoft.WindowsAzure.ServiceRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

And my view _Layout.cshtml:

@using Microsoft.WindowsAzure.ServiceRuntime
@RenderBody()
@RoleEnvironment.CurrentRoleInstance.Id

And in my debug I get something like (AzureDelete was my project name):

deployment(1).AzureDelete.MvcWebRole1_IN_0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜