2012-04-17 69 views
3

我有一個MVC 3應用程序,是給我一個401錯誤,當我試圖從遠程服務器訪問它,但是當我從我的本地計算機上運行它,它與任何錯誤運行。MVC 3 401未經授權的服務器託管

遠程服務器IIS 7配置爲允許這兩種形式和匿名訪問和成功提供靜態文件(內容文件),它只有當我嘗試訪問我得到問題的MVC應用程序。

當我瀏覽到MVC應用程序時,出現提示「Windows安全 - 服務器需要用戶名和密碼。警告:此服務器請求以不安全的方式發送您的用戶名和密碼(沒有安全連接的基本身份驗證)。「

我試着輸入所有我能想到的密碼,並沒有給我的訪問。

當我點擊取消,我得到一個服務器錯誤,說:「401 - 未經授權:由於憑據無效,訪問被拒絕。您沒有權限使用您提供的憑據查看此目錄或頁面。我已經被重定向到LogOn

我的web.config文件看起來像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=152368 
    --> 
<configuration> 
    <configSections> 
    <section name="razorJSSettings" type="RazorJS.Configuration.RazorJSSettings, RazorJS" /> 
    </configSections> 
    <connectionStrings> 
    <!--<add name="ApplicationServices" 
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" 
     providerName="System.Data.SqlClient" />--> 
    <add name="ApplicationServices" connectionString="Data Source=SOURCE; Initial Catalog=thedb; User ID=thedbuser; Password='thedbuserpassword';" /> 
    <add name="GestmeDataContext" connectionString="metadata=res://*/Models.Gestme.csdl|res://*/Models.Gestme.ssdl|res://*/Models.Gestme.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SOURCE;initial catalog=thedb;persist security info=True;user id=thedbuser;password=thedbuserpassword;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <appSettings> 
    <add key="webpages:Version" value="1.0.0.0" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <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.Helpers, Version=1.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=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <customErrors mode="Off" /> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/Account/LogOn" timeout="2880" /> 
    </authentication> 
    <membership> 
     <providers> 
     <clear /> 
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 
     </providers> 
    </membership> 
    <profile> 
     <providers> 
     <clear /> 
     <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /> 
     </providers> 
    </profile> 
    <roleManager enabled="true"> 
     <providers> 
     <clear /> 
     <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" /> 
     </providers> 
    </roleManager> 
    <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> 
    <httpHandlers> 
     <add path="razorjs.axd" verb="GET" type="RazorJS.RazorJSHandler" /> 
    </httpHandlers> 
    </system.web> 
    <system.webServer> 
    <httpErrors errorMode="Detailed" /> 
    <asp scriptErrorSentToBrowser="true"/> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <handlers> 
     <add name="RazorJSHandler" path="razorjs.axd" verb="GET" type="RazorJS.RazorJSHandler" /> 
    </handlers> 
    </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-2.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.8.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <razorJSSettings handlerPath="~/razorjs.axd"> 
    <!-- If empty all paths are valid --> 
    <allowedPaths> 
     <add path="~/Scripts" /> 
    </allowedPaths> 
    </razorJSSettings> 
</configuration> 

什麼都可能導致從服務器返回401錯誤的問題?它可能是從數據庫到服務器或aspnet_*表的連接嗎?

回答

5

所以,實際的原因是有點愚蠢。我對擁有與其操作結果關聯的[Authorize]屬性的主頁面有部分視圖。

只是爲了防止其他人得到相同的錯誤!

+0

我有同樣的問題。謝謝,你救了我幾個小時! – 2012-12-05 08:36:26

+0

很高興聽到它! – 2012-12-06 16:58:26

1

我相信這是因爲您使用的是AspNetWindowsTokenRoleProvider。這是試圖在本地服務器上獲取用戶角色,而不是從Windows窗體獲取。

你應該指定SqlRoleProvider。

+0

謝謝您的建議!我在答案中更新了我的web.config。我仍然得到提示 – 2012-04-17 19:18:11

1

請到在IIS默認網站「身份驗證方法」和「集成Windows Authenticaton」檢查。這可能是工作。

+0

該應用程序不在域中,並且不承認任何域名信譽:/我試過了,它仍然無效 – 2012-04-18 13:22:23

+0

它是否在所有瀏覽器中都有? – 2012-04-18 14:28:19

相關問題