近来,用MVC5开发自己的一个小网站.网上租用了一个小空间(虚拟主机),可选.net版本为2.0 3.0 3.5 4.0 ,上传网站 后发现是403错误.不能访问.


经与技术人员联系,把虚拟机更换到高版本.net4.5.1上面,还是不行.在本地IIS环境下可以访问.远程服务器下不能访问.

多方查资料未能解决.服务器提供方也无能为力了.只能自己再想办法解决.原来在刚刚购买空间时上传了一个.net2.0的程序,能正常运行.而且服务器上以经安装了相应.net框架,理论上是应该能使用的.本着解决问题不怕麻烦的精神,用VS2013建立了多个版本的网站基本程序,(如: .net4.0 MVC4, .net4.5 MVC4, .net4.5 Mvc5,.net4.5.1 MVC5)发现在.net4.0 MVC4,能够访问,其它的三个都不能访问.遂对比Web.config文件.

<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
--> <configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings> <system.web> <compilation targetFramework="4.0" /> <pages>
<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" />
</namespaces>
</pages>
</system.web> <system.webServer>
<validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true" /> <handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers></system.webServer>
</configuration>

这是.net4.0 MVC4 的Web.config代码

<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="UploadConfig" type="DataModel.Config.UploadConfig,DataModel"/> <section name="WebSiteInfo" type="DataModel.Config.WebSiteInfo,DataModel"/> <section name="UserConfig" type="DataModel.Config.UserConfig,DataModel"/> </configSections>
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WEB-20140601091318.mdf;Initial Catalog=aspnet-WEB-20140601091318;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="LonggerDataEntities" connectionString="metadata=res://*/LonggerDataModel.csdl|res://*/LonggerDataModel.ssdl|res://*/LonggerDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=***;persist security info=True;user id=***;password=***;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v12.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework> <UploadConfig configSource="Config\Upload.config" /> <WebSiteInfo configSource="Config\WebSiteInfo.config" /> <UserConfig configSource="Config\UserConfig.config" /> </configuration>

这是.net4.5.1 MVC5 的Web.config代码

仔细观察发现,在
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
       <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

中间少一条 <add key="PreserveLoginUrl" value="true" /> 这个应该是登录引导用的.应该用处不大.

最主要的是在  <system.webServer>   </system.webServer>  看了网上好多方法,都是在这里面加上<modules runAllManagedModulesForAllRequests="true" />   ,这个我试了,不管用,反而会引发500错误.经过对比,发现需要加入以下代码

  <system.webServer>

    <validation validateIntegratedModeConfiguration="false" />

    <modules runAllManagedModulesForAllRequests="true" />

  <handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers> </system.webServer>

用这段代码替换你的Config文件相应的配置节

当然了,你的配置节里有其它配置,就要自己有选择的添加了.

经测试,成功!!!!现记录下来,一来备忘,二来可以帮助有需要的人.

IIS7.0(虚拟机)发布MVC5程序出现Http403错误的解决方法.的更多相关文章

  1. win10下安装VS2005运行程序出现0x000007b错误的解决方法

    项目工程一运行就报错...真心坑... 方法如下: 1.安装DirectX 9.0c 形成原因是因为DirectX 9.0被损坏, 只需要安装即可. 如果有电脑管家的.在电脑管家里面搜索“Direct ...

  2. vscode下搭建typescript时提示"无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称"错误的解决方法

    根据网上的教程,安装了node.js后,再安装了typescript,,,这时候编译生成或者在vscode的终端里调用npm或者tsc --version时,总是提示 npm : 无法将"n ...

  3. JDBC链接数据库MySQL 8.0 Public Key Retrieval is not allowed 错误的解决方法

    现象 Mybatis和Spring框架整合过程中报 com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Publ ...

  4. iis7.0上发布mvc4.0网站

    步骤如下: 1.右击需要发布的项目,在弹出的菜单中选择“发布...”选项 2.在“发布web”对话框中进行设置,配置文件名称默认为“配置文件1”可以修改为需要的名字,以便识别,也可以不改.发布方法选择 ...

  5. MVC3在IIS7.5发布(部署)报403.14错误的解决办法

    MVC3在IIS7.5发布(部署)报403.14错误的解决办法     错误现象: 报403.14 forbidden错误 web服务器被配置为不列出此目录的内容. 解决办法: 检查站点的处理程序映射 ...

  6. IIS7.5中调试.Net 4.0网站出现无厘头500错误的解决办法 (转)

    刚刚 部署了ii7的dll的有x86写的,就会出现以下这样的问题 iis 7 x86,Could not load file or assembly 'Name' or one of its depe ...

  7. 启动android程序和虚拟机时候出现如下错误的解决方法

    启动android程序和虚拟机时候出现如下错误的解决方法. 错误重现: [2011-07-13 16:22:48 - Emulator] invalid command-line parameter: ...

  8. IIS7常见错误及解决方法

    IIS7常见错误及解决方法   问题一:HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效.  详细错误信息模块 IIS We ...

  9. IIS上发布站点后URL重写失效的解决方法

    在发布网站时URL重写有可能会失效,如果失效的话就需要您设置一下IIS:1.Windows XP系统或Windows 2003系统等使用以下方法:>打开IIS,主目录-〉配置-〉映射-〉在窗体左 ...

随机推荐

  1. iOS block 闭包的学习

    iOS  闭包 学习 理解: 1 .   闭包外界无法访问内部变量 ,它是一个独立的代码块. 2 .   闭包可以作为 一个方法 ,甚至局部变量  全局 变量 3 .   闭包 是一种引用类型   注 ...

  2. 每天一个Linux命令(14)head命令

    head命令用于显示文件的开头的内容.在默认情况下,head命令显示文件的头10行内容.    如果指定了多于一个文件,在每一段输出前会给出文件名作为文件头. 如果不指定文件,或者文件为"- ...

  3. java中如何制作可双击执行的程序--jar打包工具的使用

    假定当前工作目录在E盘: 1.带包编译:javac -d c:\ MyMenuDemo.java 2.DOS命令行切换到c盘,注意,这里一般切换到的是用户文件目录,需要手动切换到C盘根目录 >C ...

  4. pt-table-checksum检验主从数据不一致

    测试环境:主从架构,操作系统liunx 运行pt-table-checksum需要先安装以下依赖包: yum install perl-IO-Socket-SSL perl-DBD-MySQL per ...

  5. nginx日志配置,以及日志轮询

    一.为nginx配置错误日志 Nginx错误日志是调试nginx的重要手段,属于核心功能模块的参数(ngx_core_module)该参数名字为err_log,是放在Main区块中全局配置 err_l ...

  6. Google员工自述:在哈佛教书和在Google工作的差别

    感谢伯乐在线的投递编者按:2003年到2010年期间,原文作者Matt Welsh 是哈佛大学工程和应用科学学院的计算机科学系教授.2010年加入Google,是一名高级工程师.他当前的工作重点是广域 ...

  7. Python 案例一(计算人体体脂率)

    #计算人体体脂率 #输入部分 #身高 personHeight = input("请输入你的身高(m):") personHeight = float(personHeight) ...

  8. Windows下Nginx的启动、停止等命令添加

    Windows下Nginx的启动.停止等命令在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍.1.启动 ...

  9. Docker-使用Dockerfile创建镜像

    Dockerfile是一个文本格式的配置文件,用户可以使用Docker来快速创建自定义的镜像 基本结构 Dockerfile由一行行命令语句组成,并且支持以#开头的注释行 一般而言,Dockerfil ...

  10. Android 动态权限申请

    package com.dragon.android.permissionrequest; import android.Manifest; import android.content.Dialog ...