Asp.net mvc 3 如何删除不需要的WWW身份验证标头

Asp.net mvc 3 如何删除不需要的WWW身份验证标头,asp.net-mvc-3,iis-7,icalendar,plesk,Asp.net Mvc 3,Iis 7,Icalendar,Plesk,从一个MVC应用程序中,我正在寻找一个具有身份验证的iCal订阅,下面是这个问题的答案: 正在使用DDay.iCal库从数据库中的事件动态创建iCal流 此解决方案在本地开发服务器上运行良好:OSX日历和Outlook都可以订阅应用程序并从中接收更新 但是,在web主机的共享服务器上,日历和Outlook的身份验证都失败。也就是说,在(正确的)失败后,他们都不断地向我询问用户和密码 编辑:如果我将浏览器指向日历URL,则验证也会失败 编辑:获取更奇怪的Firefox身份验证并获取iCal文件。

从一个MVC应用程序中,我正在寻找一个具有身份验证的iCal订阅,下面是这个问题的答案:

正在使用DDay.iCal库从数据库中的事件动态创建iCal流

此解决方案在本地开发服务器上运行良好:OSX日历和Outlook都可以订阅应用程序并从中接收更新

但是,在web主机的共享服务器上,日历和Outlook的身份验证都失败。也就是说,在(正确的)失败后,他们都不断地向我询问用户和密码

编辑:如果我将浏览器指向日历URL,则验证也会失败

编辑:获取更奇怪的Firefox身份验证并获取iCal文件。Safari、Chrome和IE验证失败

如果我用相同的凭证指向日历URL,我就成功了(即,我得到了所需的iCal文件)。当然,同样的凭证也可以用于登录MVC应用程序

编辑-我想我知道发生了什么,但我不知道如何修复它。在my
OnAuthorization()
中,我只添加了
WWW Authentication Basic
,但通过Fiddler,我可以看到提供了三种类型的身份验证:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Secure Calendar"
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
... etc ...
在这一点上,只有Firefox响应基本授权,这是成功的

GET <<URL>> HTTP/1.1
...
Authorization: Basic <<encoded credentials>>
谢谢,
Eric

哈哈,答案在于IIS配置

我要求主机管理员关闭其他身份验证,这破坏了除iCal提要之外的所有功能

现在他们又重新打开了一些,MVC站点和带有身份验证的日历提要一样工作。。。唷!非常非常灿烂的笑容

以下是我们最终的IIS配置:

Name                        Status         Response Type
Anonymous Authentication    Enabled
ASP.NET Impersonation       Disabled
Basic Authentication        Disabled       HTTP 401 Challenge
Digest Authentication       Disabled       HTTP 401 Challenge
Forms Authentication        Enabled        HTTP 302 Login/Redirect
Windows Authentication      Enabled        HTTP 401 Challenge
我不知道为什么会这样,或者还有什么东西会坏,但今天我很高兴

WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
由Windows身份验证使用。由于您最终启用了匿名身份验证,所有
WWW-Authenticate
标题将不会出现。

简易方法:

如果希望从每个新创建的域中删除此“X-Powered-By-Plesk”头,可以在“默认主机模板”的“httpdocs”文件夹中创建一个默认的web.config文件

此默认网站模板通常位于“C:\inetpub\vhosts.skel\0\httpdocs”下。 创建新网站时,默认情况下将使用该web.config文件

<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
      <httpProtocol>
        <customHeaders>
          <remove name="X-Powered-By-Plesk" />
        </customHeaders>
      </httpProtocol>
    </system.webServer>
  </configuration>

提示1:您可以使用此方法删除任何不需要的自定义头(以避免向坏人透露太多关于您服务器的信息):


提示2:如果要删除任何动态头文件(如著名的“服务器”头文件),则需要使用外部规则操作

  <configuration>
    <system.webServer>
      <rewrite>
        <outboundRules>
          <rule name="StripHeader_Server" patternSyntax="Wildcard">
            <match serverVariable="RESPONSE_SERVER" pattern="*"/>
            <action type="Rewrite" value=""></action>
          </rule>
          <rule name="StripHeader_ETag">
            <match serverVariable="RESPONSE_ETag" pattern=".+" />
            <action type="Rewrite" value="" />
          </rule>
        </outboundRules>
      </rewrite>
    </system.webServer>
  </configuration>


)

作为一个迟来的答案,您还可以通过创建自定义消息处理程序来处理此问题

消息处理程序将从继承,并且必须添加到
HttpConfiguration
its
MessageHandlers

以下是一种可能的方式:

public class EnsureNoAuthenticationHeaderHandler : DelegatingHandler 
{
    async protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken ) 
    {
        var response = await base.SendAsync( request, cancellationToken );
        if ( response.StatusCode == System.Net.HttpStatusCode.Unauthorized ) 
        {
            response.Headers.Remove( "WWW-Authenticate" );
        }
        return response;
    }
}

您可能会从全局配置调用它。消息处理程序也可以直接连接到路由,因此,如果您不希望它在任何地方都可用,只需查看MSDN上的详细说明即可

我也遇到了同样的问题

响应包括3个WWW认证头,只有Firefox工作正常。Chrome、Bing和IE提示输入用户名和密码,但之后他们没有将Authenticate标头发送到服务器

我刚刚更改了IIS身份验证设置,问题已解决:

Anonymous Authentication  Enabled
ASP.NET Impersonation     Disabled
Basic Authentication      Disabled          HTTP 401 Challenge
Forms Authentication      Disabled          HTTP 302 Login/Redirect
Windows Authentication    Disabled          HTTP 401 Challenge
  <configuration>
    <system.webServer>
      <rewrite>
        <outboundRules>
          <rule name="StripHeader_Server" patternSyntax="Wildcard">
            <match serverVariable="RESPONSE_SERVER" pattern="*"/>
            <action type="Rewrite" value=""></action>
          </rule>
          <rule name="StripHeader_ETag">
            <match serverVariable="RESPONSE_ETag" pattern=".+" />
            <action type="Rewrite" value="" />
          </rule>
        </outboundRules>
      </rewrite>
    </system.webServer>
  </configuration>
public class EnsureNoAuthenticationHeaderHandler : DelegatingHandler 
{
    async protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken ) 
    {
        var response = await base.SendAsync( request, cancellationToken );
        if ( response.StatusCode == System.Net.HttpStatusCode.Unauthorized ) 
        {
            response.Headers.Remove( "WWW-Authenticate" );
        }
        return response;
    }
}
private void Register( HttpConfiguration configuration ) 
{
    configuration.MessageHandlers.Add( new EnsureNoAuthenticationHeaderHandler() );
}
Anonymous Authentication  Enabled
ASP.NET Impersonation     Disabled
Basic Authentication      Disabled          HTTP 401 Challenge
Forms Authentication      Disabled          HTTP 302 Login/Redirect
Windows Authentication    Disabled          HTTP 401 Challenge