与窗体身份验证我的ASP.NET应用程序MVC2阻止甚至图片,样式和脚本的访问 [英] My ASP.NET MVC2 application with Forms Authentication is blocking access even to Images, Styles and Scripts

查看:122
本文介绍了与窗体身份验证我的ASP.NET应用程序MVC2阻止甚至图片,样式和脚本的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序MVC2使用窗体身份验证就可以了。

脚本,图片和样式都堵塞,未记录的用户,因此,在登录页面看起来可怕。

它运作良好的地方,问题是,当我发布到服务器。

有没有人有任何想法,为什么????

PS:服务器IIS 7.5版本

我的的Web.config

 <结构>
  <&的System.Web GT;
    <全球化文化=PT-BR的UICulture =PT-BR/>
    <的httpRuntime requestValidationMode =2.0/>
    <的customErrors模式=关/>
    <编译调试=真targetFramework =4.0>
      <&集会GT;
        <添加组件=System.Web.Abstractions,版本= 4.0.0.0,文化=中性公钥= 31BF3856AD364E35/>
        <添加组件=System.Web.Routing,版本= 4.0.0.0,文化=中性公钥= 31BF3856AD364E35/>
        <添加组件=System.Web.Mvc,版本= 2.0.0.0,文化=中性公钥= 31BF3856AD364E35/>
      < /组件>
    < /编译>    <网页和GT;
      <&命名空间GT;
        <添加命名空间=System.Web.Mvc/>
        <添加命名空间=System.Web.Mvc.Ajax/>
        <添加命名空间=System.Web.Mvc.Html/>
        <添加命名空间=System.Web.Routing/>
        <添加命名空间=Admin.Models/>
      < /命名空间>
    < /页>    <身份验证模式=表格>
      <形式的名称=AGAuthloginUrl =〜/主页/登录超时=120/>
    < /认证>
  < /system.web>  < system.webServer>
    <验证validateIntegratedModeConfiguration =FALSE/>
    <模块runAllManagedModulesForAllRequests =真/>
  < /system.webServer>  <&运行GT;
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
      < dependentAssembly>
        < assemblyIdentity名称=System.Web.Mvc公钥=31bf3856ad364e35/>
        < bindingRedirect oldVersion =1.0.0.0NEWVERSION =2.0.0.0/>
      < / dependentAssembly>
    < / assemblyBinding>
  < /运行>  <&是connectionStrings GT;
      <添加名称=DBContainer connectionString=\"metadata=res://*/Database.DB.csdl|res://*/Database.DB.ssdl|res://*/Database.DB.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= thewebserver.com,5158;初始目录= thedatabase;坚持安全信息= TRUE;用户ID = theuser;密码= thepassword; MultipleActiveResultSets =真放; QUOT;的providerName =System.Data这。 EntityClient/>
  < /&是connectionStrings GT;< /结构>


解决方案

我有完全相同的问题。

原因竟然是IIS的身份验证配置。通过启用匿名身份验证(并启用窗体身份验证和禁用Windows身份验证)注销时,脚本,风格和形象成为访问。

I'm developing a MVC2 application and using Forms Authentication on it.

The scripts, images and styles are all blocked to unlogged users and, consequently, the login page looks awful.

It works well local, the problem is when I publish to the server.

Does anyone has any idea WHY????

PS: The server IIS is version 7.5

My Web.config:

<configuration>
  <system.web>
    <globalization culture="pt-BR" uiCulture="pt-BR" />
    <httpRuntime requestValidationMode="2.0"/>
    <customErrors mode="Off" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.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=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="Admin.Models" />
      </namespaces>
    </pages>

    <authentication mode="Forms">
      <forms name="AGAuth" loginUrl="~/Home/Login" timeout="120" />
    </authentication>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

  <connectionStrings>
      <add name="DBContainer" connectionString="metadata=res://*/Database.DB.csdl|res://*/Database.DB.ssdl|res://*/Database.DB.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=thewebserver.com,5158;Initial Catalog=thedatabase;Persist Security Info=True;User ID=theuser;Password=thepassword;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

</configuration>

解决方案

I had exactly the same problem.

The cause turned out to be the IIS authentication configuration. By enabling Anonymous Authentication (and enabling Forms Authentication and disabling Windows Authentication) the scripts, styles and images became accessible when logged off.

这篇关于与窗体身份验证我的ASP.NET应用程序MVC2阻止甚至图片,样式和脚本的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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