internal Task WriteMetadataDocument(IOwinContext context) { var encoding = Encoding.UTF8; string encodingStr = null; try { encodingStr = context.Request.Query.Get("encoding"); if (!string.IsNullOrEmpty(encodingStr)) { encoding = Encoding.GetEncoding(encodingStr); context.Response.Headers["Content-Encoding"] = encoding.ToString(); } } catch (ArgumentException ex) { logger.ErrorFormat(ErrorMessages.UnknownEncoding, encodingStr); throw new ArgumentException(string.Format(ErrorMessages.UnknownEncoding, encodingStr), ex); } var sign = true; var param = context.Request.Query.Get("sign"); if (!string.IsNullOrEmpty(param)) { if (!bool.TryParse(param, out sign)) { throw new ArgumentException(ErrorMessages.MetadataSignQueryParameterInvalid); } } context.Response.ContentType = "text/xml"; //Saml20Constants.MetadataMimetype; - that will prompt a download var filename = context.Request.Query.Get("file"); if (!string.IsNullOrWhiteSpace(filename)) context.Response.Headers["Content-Disposition"] = string.Format("attachment; filename=\"{0}\"", filename); var metautil = new MetadataUtils(configuration, logger); return context.Response.WriteAsync(metautil.CreateMetadataDocument(encoding, sign)); }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface. /// </summary> /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> public override void ProcessRequest(HttpContext context) { var encoding = context.Request.QueryString["encoding"]; try { if (!string.IsNullOrEmpty(encoding)) { context.Response.ContentEncoding = Encoding.GetEncoding(encoding); } } catch (ArgumentException ex) { Logger.ErrorFormat(ErrorMessages.UnknownEncoding, encoding); throw new ArgumentException(string.Format(ErrorMessages.UnknownEncoding, encoding), ex); } var sign = true; var param = context.Request.QueryString["sign"]; if (!string.IsNullOrEmpty(param)) { if (!bool.TryParse(param, out sign)) { throw new ArgumentException(ErrorMessages.MetadataSignQueryParameterInvalid); } } context.Response.ContentType = Saml20Constants.MetadataMimetype; context.Response.AddHeader("Content-Disposition", "attachment; filename=\"metadata.xml\""); var metautil = new MetadataUtils(ConfigurationFactory.Instance.Configuration, Logger); context.Response.Write(metautil.CreateMetadataDocument(context.Response.ContentEncoding, sign)); context.Response.End(); }