我有一个ASP.NET应用程序,它动态创建一个ICS日历(
using the DDay.iCal library),我可以从outlook中订阅.一切正常,但我需要能够保护日历,以便只有经过身份验证的用户才能访问它.即,当您将URL添加到Outlook中的日历时,它需要询问用户名和密码.
Remember The Milk seem to have implemented what I need,但我似乎无法找到有关如何实现这一目标的任何信息?
解决方法
The article Chris provided as a comment是解决方案.
所需要的是绕过某些请求的表单身份验证并使用基本HTTP身份验证.然后,Outlook(以及可能的其他代理,如Web浏览器)支持此功能.
这是通过使用MADAM Http Module实现的.
脚步:
1 GT;阅读文章以获得基本的了解.
2 – ;安装MADAM NuGet包:PM>安装包装女士
3 GT;实现自己的IUserSecurityAuthority:
例如
public class MadamUserSecurityAuthority : IUserSecurityAuthority { public MadamUserSecurityAuthority() { } //This constructor is required public MadamUserSecurityAuthority(IDictionary options) { } public object Authenticate(string userName,object password,PasswordFormat format,IDictionary options,string authenticationType) { if (_yourAuthenticationService.isValid(userName,password.ToString())) return true; //Returning null means the authentication Failed return null; } public string RealmName { get { return "MADAM"; } } }
例如:
<sectionGroup name="madam"> <section name="userSecurityAuthority" type="System.Configuration.SingleTagSectionHandler,System,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"/> <section name="formsAuthenticationDisposition" type="Madam.FormsAuthenticationDispositionSectionHandler,Madam"/> </sectionGroup> <madam> <formsAuthenticationDisposition> <discriminators all="true"> <discriminator inputExpression="Request.Url" pattern="Calendar\.aspx" type="Madam.RegexDiscriminator"/> </discriminators> </formsAuthenticationDisposition> <userSecurityAuthority realm="MADAM" provider="YourAppAssembly.MadamUserSecurityAuthority,YourAppAssembly"/> </madam> <httpModules> <add name="FormsAuthenticationDisposition" type="Madam.FormsAuthenticationDispositionModule,Madam"/> <add name="AuthenticationModule" type="Madam.BasicAuthenticationModule,Madam"/> </httpModules>
注1:
<discriminator inputExpression="Request.Url" pattern="Calendar\.aspx" type="Madam.RegexDiscriminator"/>
…用于识别哪些请求应绕过表单身份验证并使用基本HTTP身份验证,这是使用Regex完成的,您可以添加多个鉴别符.
笔记2:
<userSecurityAuthority realm="MADAM" provider="YourAppAssembly.MadamUserSecurityAuthority,YourAppAssembly"/>