您已请求的页面类型未被提供,因为它已被明确禁止

时间:2015-01-14 14:36:20

标签: c# asp.net-mvc-4

我正在尝试创建一个可以在不登录asp.net mvc 4的情况下访问的页面。当debbugging我可以看到它进入控制器的操作。 我将此添加到我的web.config中,以便用户无需登录即可访问该页面

<location path="Security/Licensing">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>

我尝试添加

<add key="webpages:Enabled" value="true" />

到web.config文件并将runAllManagedModulesForAllRequests设置为false

如果用户已登录,页面也能正常工作我在Windows 7上使用IIS 7.5

Web.config文件

&#13;
&#13;
<appSettings>
    <add key="webpages:Enabled" value="true" />
  </appSettings>
  <location path="Security/Licensing">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
  <system.web>
    <globalization culture="en-GB" />
    <customErrors mode="Off">
      <error statusCode="403" redirect="errorUrl" />
    </customErrors>
    <httpRuntime targetFramework="4.5" />
    <machineKey decryption="Auto" />
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms name=".PORTALASPXAUTH" loginUrl="loginUrl" timeout="540" protection="All" cookieless="UseCookies" enableCrossAppRedirects="true" domain="localhost" requireSSL="false" slidingExpiration="false" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>
    <sessionState timeout="3600" mode="InProc" />
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="MvcPaging" />
      </namespaces>
    </pages>
    <httpHandlers>
      <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
      <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
    </httpHandlers>
    <httpModules>
      <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
    </httpModules>
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions>
          <remove fileExtension=".cshtml" />
          <add fileExtension=".cshtml" allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
    <staticContent>
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
    </staticContent>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
    </modules>
    <handlers>
      <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
      <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
&#13;
&#13;
&#13;

控制器

    [AllowAnonymous]
    public ActionResult Index()
    {
        LicensingViewModel licensingViewModel = LicensingHelper.GetLicensingViewModule(companyAccessor, userAccessor);

        return View(licensingViewModel);
    }

1 个答案:

答案 0 :(得分:0)

您根本不需要在location中指定web.config属性。

在呈现页面的操作上使用AllowAnonymous属性:

[AllowAnonymous]
public ActionResult Foo()
{
    return View();
}