问题:

我已经构建了一个.net4.5 ASP.NET MVC4 Web应用程序,该应用程序在本地可以正常运行(IIS Express和开发服务器),但是一旦将其部署到我的Web服务器上,它就会引发403错误。 我已经在服务器上安装了.Net 4.5RC,甚至尝试了aspnet_regiis -i ,每个人都建议使用MVC / .Net的早期版本解决问题,但没有帮助。

有任何想法吗?

编辑 :有关情况的更多信息。 该服务器是32位的,我还有其他4个运行良好的MVC3应用程序。 只是我的MVC4应用无法正常工作。

I have build a .net4.5 ASP.NET MVC4 web app which works fine locally (IIS Express & dev server) but once i deploy it to my web server it throws the 403 error.I have installed .Net 4.5RC on the server and even tried the aspnet_regiis -i bit that everyone recommended for their issues with previous versions of MVC/.Net but it did not help.Any ideas?EDIT : More info about the situation.The server is 32bit and I have 4 other MVC3 applications that work fine.It is just my MVC4 app that is not working.

问题:

ASP.NET MVC4 Bootstrap 3应用程序从Microsoft Visual Studio Express 2013 for Web IDE运行。

Chrome控制台始终显示错误

http://localhost:52216/admin/fonts/glyphicons-halflings-regular.woff2
Failed to load resource: the server responded with a status of 404 (Not Found)

此文件存在于解决方案资源管理器的fonts目录中。 构建操作设置为“内容”,复制到输出目录为“不要像其他字体文件一样复制”。 使用NuGet将Bootstrap 3添加到解决方案中。 如何解决这个问题,以免发生此错误? 应用程序正确显示Glyphicon和FontAwesome图标。 此错误始终在应用程序启动时发生。

ASP.NET MVC4 Bootstrap 3 application is running from Microsoft Visual Studio Express 2013 for Web IDE.Chrome console shows always errorThis file exists in the fonts directory in the Solution Explorer.Build action is set to “Content” and Copy to Output directory is “Do not copy like in other font files”.Bootstrap 3 is added to the solution using NuGet.How to fix this so that this error does not occur?Application shows Glyphicon and FontAwesome icons properly.This error always occurs at application startup.

问题:

我已经按照本教程进行了很好的工作,直到我修改了我的DbContext以获得额外的构造函数。 我现在遇到了解决方案的问题,不知道如何解决这个问题。 是否有一种简单的方法可以强制它抓住无参数构造函数,或者我接近这个错误?

带有两个构造函数的DbContext :

public class DashboardDbContext : DbContext
{
    public DashboardDbContext() : base("DefaultConnection") { }

    public DashboardDbContext(DbConnection dbConnection, bool owns)
        : base(dbConnection, owns) { }
}

SiteController构造函数:

private readonly IDashboardRepository _repo;

public SiteController(IDashboardRepository repo)
{
    _repo = repo;
}

库:

DashboardDbContext _context;

public DashboardRepository(DashboardDbContext context)
{
    _context = context;
}

UnityResolver代码:

public class UnityResolver : IDependencyResolver
{
    private readonly IUnityContainer _container;

    public UnityResolver(IUnityContainer container)
    {
        _container = container;
    }

    public object GetService(Type serviceType)
    {
        try
        {
            return _container.Resolve(serviceType);
        }
        catch (ResolutionFailedException)
        {
            return null;
        }
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        try
        {
            return _container.ResolveAll(serviceType);
        }
        catch (ResolutionFailedException)
        {
            return new List<object>();
        }
    }

    public IDependencyScope BeginScope()
    {
        var child = _container.CreateChildContainer();
        return new UnityResolver(child);
    }

    public void Dispose()
    {
        _container.Dispose();
    }
}

WebApiConfig:

var container = new UnityContainer();
container.RegisterType<IDashboardRepository, DashboardRepository>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityResolver(container);

WebApi调用出错:

System.InvalidOperationException:尝试创建“SiteController”类型的控制器时发生错误。 确保控制器具有无参数的公共构造函数。

at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) 
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request) 
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) 
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()

InnerException:System.ArgumentException:Type’Dashboard.Web.Controllers.SiteController’没有默认构造函数。

at System.Linq.Expressions.Expression.New(Type type) 
at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType) 
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator) 
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)

该教程非常棒,并且在我添加第二个构造函数之前一直很好用。

I have followed this tutorial which has worked great, until I modified my DbContext to have an additional constructor.I am now having issues with the resolution and not sure what to do to fix this.Is there an easy way to force it to grab the parameterless constructor or I am approaching this incorrectly?DbContext with two constructors:SiteController constructor:Repository:UnityResolver code:WebApiConfig:Error from WebApi Call:System.InvalidOperationException: An error occurred when trying to create a controller of type ‘SiteController’.Make sure that the controller has a parameterless public constructor.InnerException: System.ArgumentException: Type ‘Dashboard.Web.Controllers.SiteController’ does not have a default constructor.The tutorial was great and has been working well for me up until I added the second constructor.

问题:

我正在尝试将MVC网站发布为Azure webrole。

当我在本地运行它时,一切正常。

但是,一旦我将它发布到Azure并浏览到一些MVC操作,我就会收到此错误:

‘/’应用程序中的服务器错误。

运行时错误

描述:处理您的请求时发生异常。 此外,执行第一个异常的自定义错误页面时发生另一个异常。 请求已终止。

我不明白错误处理程序如何遇到异常,因为错误是以默认方式处理的:

public class FilterConfig
{
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }
}

这是我的web.config:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
        <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

这是Error.cshtml:

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Error";
}

<h2>
    Sorry, an error occurred while processing your request.
</h2>

什么可能导致此异常,为什么我不能在本地重现它?

I’m trying to publish an MVC website as an Azure webrole.When I run it locally, everything works fine.But once I publish it to Azure and surf to some MVC action, I get this error:Server Error in ‘/’ Application.Runtime ErrorDescription: An exception occurred while processing your request.Additionally, another exception occurred while executing the custom error page for the first exception.The request has been terminated.I don’t understand how the error handler can encounter an exception, because errors are handled in the default way:This is my web.config:This is Error.cshtml:What can cause this exception, and why can’t I reproduce it locally?

问题:

我创建了一个ASP.NET MVC 3项目,并在开发时使用IIS Express作为Web服务器。 当我尝试调试时,我收到以下错误消息。

怎么解决这个问题?

‘/’应用程序中的服务器错误。

访问被拒绝。 描述:访问提供此请求所需的资源时发生错误。 可能未配置服务器以访问请求的URL。

错误消息401.2。:未授权:由于服务器配置登录失败。 验证您是否有权根据您提供的凭据和Web服务器上启用的身份验证方法查看此目录或页面。 请与Web服务器的管理员联系以获取其他帮助。

I have created an ASP.NET MVC 3 project, and am using IIS Express as the web server when developing.When I try to debug, I get the error message below.How can this be solved?Server Error in ‘/’ Application.Access is denied.Description: An error occurred while accessing the resources required to serve this request.The server may not be configured for access to the requested URL.Error message 401.2.: Unauthorized: Logon failed due to server configuration.Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.Contact the Web server’s administrator for additional assistance.