Files
dotnet-bot adf899c629 Adding System.Data..., System.ServiceModel..., and System.Web...
Adding reference source for
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Entity.Design
System.Data.Linq
System.Data.SqlXml
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Activities
System.ServiceModel.Channels
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.WasHosting
System.ServiceModel.Web
System.Web
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Entity
System.Web.Entity.Design
System.Web.Extensions
System.Web.Mobile
System.Web.Routing
System.Web.Services
System.Xml
System.Xml.Linq
2016-05-03 00:07:37 +02:00

82 lines
4.2 KiB
C#

//------------------------------------------------------------------------------
// <copyright file="WebServiceClientProxyGenerator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Script.Services {
using System;
using System.IO;
using System.Reflection;
using System.Web;
using System.Security.Permissions;
using System.Security;
internal class WebServiceClientProxyGenerator : ClientProxyGenerator {
private string _path;
// Called by ScriptManager to generate the proxy inline
internal static string GetInlineClientProxyScript(string path, HttpContext context, bool debug) {
WebServiceData webServiceData = WebServiceData.GetWebServiceData(context, path, true, false, true);
WebServiceClientProxyGenerator proxyGenerator = new WebServiceClientProxyGenerator(path, debug);
return proxyGenerator.GetClientProxyScript(webServiceData);
}
private static DateTime GetAssemblyModifiedTime(Assembly assembly) {
AssemblyName assemblyName = assembly.GetName();
DateTime writeTime = File.GetLastWriteTime(new Uri(assemblyName.CodeBase).LocalPath);
// DevDiv 52056: include writeTime.Second in the date, otherwise if you modify it within the same minute it we'd still respond with http status 304 not modified
return new DateTime(writeTime.Year, writeTime.Month, writeTime.Day, writeTime.Hour, writeTime.Minute, writeTime.Second);
}
// This is called thru the RestClientProxyHandler
[SecuritySafeCritical]
[FileIOPermission(SecurityAction.Assert, Unrestricted = true)]
internal static string GetClientProxyScript(HttpContext context) {
WebServiceData webServiceData = WebServiceData.GetWebServiceData(context, context.Request.FilePath);
DateTime lastModifiedDate = GetAssemblyModifiedTime(webServiceData.TypeData.Type.Assembly);
// If the browser sent this header, we can check if we need to resend
string modifiedSince = context.Request.Headers["If-Modified-Since"];
if (modifiedSince != null) {
DateTime header;
if (DateTime.TryParse(modifiedSince, out header)) {
// We are done if the assembly hasn't been modified
if (header >= lastModifiedDate) {
context.Response.StatusCode = 304;
return null;
}
}
}
bool debug = RestHandlerFactory.IsClientProxyDebugRequest(context.Request.PathInfo);
// Only cache for release proxy script (/js)
if (!debug) {
// Only cache if we get a reasonable last modified date
if (lastModifiedDate.ToUniversalTime() < DateTime.UtcNow) {
// Cache the resource so we don't keep processing the same requests
HttpCachePolicy cachePolicy = context.Response.Cache;
cachePolicy.SetCacheability(HttpCacheability.Public);
cachePolicy.SetLastModified(lastModifiedDate);
// expires is necessary so that the browser at least does an If-Modified-Since request on every request.
// without that, the browser wouldn't request a new proxy until the user hits refresh.
// Use one year ago to reasonably ensure "past" interpretation
cachePolicy.SetExpires(lastModifiedDate.AddYears(-1));
}
}
WebServiceClientProxyGenerator proxyGenerator = new WebServiceClientProxyGenerator(context.Request.FilePath, debug);
return proxyGenerator.GetClientProxyScript(webServiceData);
}
internal WebServiceClientProxyGenerator(string path, bool debug) {
// internal because ExtensionsTest needs this path to bypass httpcontext
_path = path;
_debugMode = debug;
}
protected override string GetProxyPath() {
return _path;
}
}
}