错误在Azure上运行MVC4 [英] Error running MVC4 on Azure

查看:97
本文介绍了错误在Azure上运行MVC4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有时让我们开始在Azure上MVC4网站上有错误。从来没有见过我们的本地服务器上的这些错误。部署数据库和应用程序的Azure之后,发生了故障启动网页如果申请授权,在网站上闲置一段时间后(误差可能是由超时造成的)。如下所示的code是简单的:

We sometimes getting an error starting our MVC4 site on Azure. Never seen these errors on our local servers. After deploying the database and the application to Azure, troubles occur starting the homepage if authorization is requested and after a period of inactivity on the site (error likely caused by a timeout). The code is as simple as depicted below:

[InitializeSimpleMembership]
[Authorize(Roles = "Administrator")]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

请求主页有时会失败:

Requesting the homepage sometimes fails:

[Win32Exception (0x80004005): Access is denied]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
....
System.Data.SqlClient.SqlConnection.Open() +96
System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +88
System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +239
System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) +762
WebMatrix.WebData.SimpleRoleProvider.GetRolesForUser(String username) +54
...

如何prevent这个(超时)错误?感谢您的帮助!

How to prevent this (timeout) error? Thanks for any help!

推荐答案

移动从InitializeSimpleMembershipAttribute.cs以下行(过滤器),以AuthConfig.cs:

Move the following line from InitializeSimpleMembershipAttribute.cs (a Filter) to AuthConfig.cs:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

所以,code将看起来像:

So the code will look like:

public static class AuthConfig
{
    public static void RegisterAuth()
    {
        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
        ...

也许你需要在你的web.config(节的System.Web)以及以下内容:

Perhaps you need the following in your web.config (section system.web) as well:

<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
 <providers>
  <clear/>
  <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
 </providers>
</roleManager>
<membership defaultProvider="SimpleMembershipProvider">
 <providers>
  <clear/>
  <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
 </providers>
</membership>

这篇关于错误在Azure上运行MVC4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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