启用Form认证后,通过手机以Form认证方式访问,报错。
默认安装的SP1是没问题的,装了一个补丁【office2010-kb2598151-fullfile-x64-glb,这补丁还真必须装,否则问题更多,比如我照死打不开那个UserProfileManage】以后就挂了。
错误如下(说实话,看到这个错误,我心都凉了,又不是哥写的代码,怎么会有Compile错误!):
Runtime tkau Unexpected System.Web.HttpCompileException: c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\MOBILE\mbllogin.aspx(21): error CS1540: Cannot access protected member 'Microsoft.SharePoint.MobileControls.SPMobilePage.strReturnUrl' via a qualifier of type 'Microsoft.SharePoint.MobileControls.SPMobilePage'; the qualifier must be of type 'ASP._layouts_mobile_mbllogin_aspx' (or derived from it) at System.Web.Compilation.AssemblyBuilder.Compile() at System.Web.Compilation.BuildProvidersCompiler.PerformBuild() at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at... bbeec570-16cd-43d5-9e09-da6e233d6c9b
Runtime tkau Unexpected ... System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at Sys... bbeec570-16cd-43d5-9e09-da6e233d6c9b
Runtime tkau Unexpected ...tem.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) bbeec570-16cd-43d5-9e09-da6e233d6c9b
很无语,最后发现是因为微软自己提供的mbllogin.aspx这个页面的代码有bug
将此页面代码中所有的SPMobilePage.strReturnUrl,改为this.strReturnUrl就可以了。因为SPMobilePage类型不能访问被保护的strReturnUrl属性,只能通过ASP.template_layouts_mobile_mbllogin_asp类型去访问,而这个类型就是当前这个页面所属的对象类型,所以将SPMobilePage换成this就OK了。
protected override void OnInit(EventArgs e) { base.OnInit(e); //SPMobilePage.strReturnUrl if (null == Request.QueryString[this.strReturnUrl]) { string filePath = this.Request.FilePath; string fileName = System.IO.Path.GetFileName(filePath); string returnUrl = filePath.Replace(fileName, SPMobileUtility.DefaultFileName); string redirectUrl = filePath + '?' + this.strReturnUrl + '=' + SPHttpUtility.UrlKeyValueEncode(returnUrl); this.Response.Redirect(redirectUrl, true); } }
protected void Login_Click(Object sender, EventArgs e) { SPIisSettings iisSettings = SPMobileUtility.GetIisSettings(this.Context); if (iisSettings.UseClaimsAuthentication) { if (SPClaimsUtility.AuthenticateFormsUser(this.Request.Url, mobileLoginTextBox.Text, mobilePwdTextBox.Text)) { string redirectUrl = this.Request.QueryString[this.strReturnUrl]; redirectUrl = SPHttpUtility.UrlPathEncode(redirectUrl, true, true); SPMobileUtility.Redirect(redirectUrl, SPRedirectFlags.DoNotEncodeUrl, this.Context); } } else { if (IsAuthenticated(mobileLoginTextBox.Text, mobilePwdTextBox.Text)) { FormsAuthentication.SetAuthCookie(mobileLoginTextBox.Text, false); MobileFormsAuthentication.RedirectFromLoginPage(mobileLoginTextBox.Text, false); } } lblError.Visible = true; }
这个问题纠结了我很久,我表示很无语,希望大家不要再被这个问题坑了。。。。