添加WebRole.cs - 并将其称为 - 在现有的ASP.NET MVC的网站转换为Web角色 [英] Add WebRole.cs - and have it called - in an existing ASP.NET MVC site converted to web role

查看:254
本文介绍了添加WebRole.cs - 并将其称为 - 在现有的ASP.NET MVC的网站转换为Web角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC 4个网站,在Azure中运行WebRole非常清楚。在ASP.NET MVC项目启动自身,在这之后我增加了一个Azure的云服务项目,解决方案,并添加了ASP.NET项目/网站作为服务的角色之一(所以在显示出来角色文件夹)。

I have an ASP.NET MVC 4 site running perfectly well in an Azure WebRole. The ASP.NET MVC project was started on its own, after which I added an Azure Cloud Service project to the solution and added the ASP.NET project/site as one of the 'roles' of the service (so it shows up in the 'Roles' folder).

我的问题是,我想有工作的ASP.NET MVC项目中的WebRole.cs文件,但不管是什么,我试图做的,看来部署时,只是从来没有被调用。的OnStart和运行的倍率(我知道,绝不能离开环路) - 这些只是显然并没有得到所谓

My problem is that I would like to have working a WebRole.cs file within the ASP.NET MVC project, but no matter what I've tried to do, it appears that when deployed, it just never gets called. OnStart and the override of Run (which I know, must never leave the loop) -- these just apparently never get called.

但是,如果你启动一个新的CloudService项目并添加,从一开始那段时间,一个ASP.NET MVC项目时,它会自动在它WebRole.cs文件,所以我的猜测是,我需要的地方设置的东西对于WebRole.cs(实际上来讲,WebRole类,它继承RoleEntryPoint)到被调用。什么可能这样呢?

But if you startup a new CloudService project and add, at that time from the start, an ASP.NET MVC project, it automatically has a WebRole.cs file in it, so my guess is that I need to configure something somewhere for the WebRole.cs (actually speaking, the WebRole class, which inherits RoleEntryPoint) to get called. What might that be?

using System;
using System.Web;
//using Microsoft.WindowsAzure.StorageClient;
using System.Diagnostics;
using System.Threading;

namespace Us.WebUI
{
    public class WebRole : Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint
    {
        public override bool OnStart()
        {
            return true; //return base.OnStart(); // CALL THIS???
        }

        public override void Run()
        {
            while (true) {
                Thread.Sleep(TimeSpan.FromSeconds(30));
                try {
                    EmailFuncs.SendEmailToUs("An email from our WebRole?????", "Email me this, email me that.");
                }
                catch { }
            }
        }

    }
}

更新:谢谢,这个问题已经有了答案。不过,我会补充:在做这个,而它显然是工作(完全部署和仿真器),做了充分的突然我有问题,发布该网站的。一个蔚蓝发布后花了3小时:

UPDATE: Thanks, the question has been answered. But I will add: On doing this, while it clearly was working (fully deployed and in emulator), that suddenly I was having problems doing a full publish of the site. After a azure publish took 3 hours:

验证存储账户XYZ...>上传数据包...> - 更新中... [在这里住了3小时],它失败,此错误:服务器遇到一个内部错误。请重试请求。这么一件事我想知道的,难道我需要WebRole.cs覆盖调用OnStop?

Verifying storage account 'xyz'... > Uploading Package... > - Updating... [stayed here for 3 hours], it failed with this error: The server encountered an internal error. Please retry the request. So one thing I was wondering is, did I need to override OnStop in WebRole.cs?

更新2:那些previous问题是固定的,并没有任何关系这个问题。其实,我已经学会了这一点:如果你曾经在你的构建产生的任何警告,天青往往不会与他们的工作,即使它们不会导致在本地或其他主机的问题。从那时起,我已经更加好学,以解决建设警告(但这个关键与警告codeS关掉你想忽略许多警告类型!)。

UPDATE 2: Those previous problems were fixed, and had nothing to do with this issue. Actually, I've learned this: If you ever have any warnings generated in your build, Azure often will not work with them even when they don't cause problems locally or in other hosts. Since then, I've been much more studious to tackling build warnings (but critical to this is turning off with warning codes the many warning types you want to ignore!).

推荐答案

添加类到继承RoleEntryPoint足够您的Web项目,它应该只是工作。你尝试在模拟器中设置断点?

Adding a class to your Web Project which inherits from RoleEntryPoint is sufficient, it should just work. Did you try setting a breakpoint in the emulator?

但您可能会遇到的是, EmailFuncs.SendEmailToUs 需要从应用程序/ web.config中的信息,并且这个信息不可用。你需要知道你的 WebRole 类在不同的进程(不是你的Web应用程序)运行时,它不使用你的web.config的意思。如果你想WebRole.cs读取配置文件中的信息,你需要在添加这些设置<一个href=\"http://blogs.msdn.com/b/windowsazure/archive/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core.aspx\"相对=nofollow> WaIISHost.exe.config

What you might be experiencing is that EmailFuncs.SendEmailToUs requires info from the app/web.config and that this info is not available. You need to know that your WebRole class runs in a different process (not your web application), meaning it's not using your web.config. If you want the WebRole.cs to read info from the configuration file, you'll need to add these settings in WaIISHost.exe.config

这篇关于添加WebRole.cs - 并将其称为 - 在现有的ASP.NET MVC的网站转换为Web角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆