.net-4.0 - 将 ASP.Net MVC4 站点转换为 Azure

标签 .net-4.0 azure asp.net-mvc-4 azure-web-roles

我创建了一个 ASP.Net MVC 4 网站,其中有几个在 ~/App_Start/RouteConfig 文件中注册的自定义路由。

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Empty",
            url: "",
            defaults: new { controller = "Home", action = "Index", id = 0 }
        );

        routes.MapRoute(
            name: "Session",
            url: "{id}",
            defaults: new { controller = "Home", action = "Index" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

该网站在 Azure 之外运行良好,甚至可以在 Azure 模拟器中运行,但是当我将其移至 Azure 时,它​​的表现就像没有路由一样。例如,当我尝试导航到网站的根目录时,我收到一条错误消息:

403 - Forbidden: Access is denied.

You do not have permission to view this directory or page using the credentials that you supplied.

这让我觉得这条路线根本不起作用,所以我尝试转到另一个页面,例如 http://myapp.cloudapp.net/1234 (这应该将 1234 发送到家庭 Controller 的索引操作中。但是该操作给了我一个 404 错误。

我已经检查了我的配置和新的 ASP.Net MVC 4 Azure 项目,它们似乎是相同的。我还读过this这提供了一些指导,但最终没有帮助。

关于如何解决此问题有什么建议吗?

更新

这是一个 WebRole 项目,正在使用 .Net 4.0(我已经从 4.5 向下转换)。

最佳答案

您是否尝试过按照本文 http://www.sunilhaste.com/2011/04/403-forbidden-access-is-denied-error.html 设置默认页面

  1. After you have uploaded your Web Role to Azure, you try to access the application and suddenly you get "403-Forbidden, Access denied" error.
  2. You are able access a page by providing it's complete url ex :- http://xyz.cloudapp.net/Pages/Home.aspx.
  3. You don't have a default.aspx page present at the root level of your website. Solution :- The first thing that you should do is, to check whether you have added below tag to the web.config file inside system.webserver tag or not.

   <add value="Pages/Home.aspx"/>

我也遇到过类似的问题,通过将角色设置为 2008 R2 解决了我的问题。有人在链接文章的评论中说

change OS CONFIGURATION from MS SERVER 2008 SP2 to MS SERVER 2008 R2

另请参阅以下内容 Asp.net and Azure - Can't no longer show my web application建议检查您有 <modules runAllManagedModulesForAllRequests="true" />

此外,我假设您要确保将 MVC4 文件部署到 Azure。您的 RDP 已连接到计算机并检查了事件日志等吗?

关于.net-4.0 - 将 ASP.Net MVC4 站点转换为 Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12882116/

相关文章:

asp.net - 在同一请求中调用PasswordSignIn和SendTwoFactorCode

javascript - 客户端文件大小结束格式验证。为什么 JS 会阻止文件上传?

entity-framework - 关于基于ASP.NET MVC Onion的体系结构的观点

c# - 中继命令可以执行和任务

asp.net - ASP.NET 4 中是否可以默认打开 HTML 编码?

c#动态行为?

azure - Microsoft Graph API,有应用程序权限请求时需要区域

应用服务计划的 Azure 函数应用超时

c# - 将事件设置为空

azure - 使用 PowerShell 在 Azure AD 上启用诊断日志的命令是什么?