?? uploadmodule.cs
字號:
if (this.IsHaveUploadId(context))
{
return context.Request.QueryString[str];
}
return (HttpContext.Current.GetHashCode().ToString() + HttpContext.Current.Timestamp.Ticks.ToString());
}
private HttpWorkerRequest GetWorkerRequest(HttpApplication appl)
{
BindingFlags bindingAttr = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
return (HttpWorkerRequest) appl.Context.GetType().GetProperty("WorkerRequest", bindingAttr).GetValue(appl.Context, null);
}
public void Init(HttpApplication application)
{
AddDebugInfo("UploadModule.Init(application) start.");
application.BeginRequest += new EventHandler(this.fileUpload_BeginRequest);
application.Error += new EventHandler(this.fileUpload_Error);
application.EndRequest += new EventHandler(this.fileUpload_EndRequest);
}
private bool IsHaveUploadId(HttpContext context)
{
string str = (string) Settings.GetValue(null, "uploadIDQueryField");
if ((str != null) && (str != ""))
{
string str2 = context.Request.QueryString[str];
if ((str2 != null) && (str2.Trim() != ""))
{
return true;
}
}
return false;
}
private bool IsUploadPage(HttpApplication app, string id)
{
string str2;
char[] separator = new char[] { ',' };
string[] strArray = null;
if (((string) Settings.GetValue(id, "processPages")) != null)
{
strArray = ((string) Settings.GetValue(id, "processPages")).Split(separator);
}
string[] strArray2 = null;
if (((string) Settings.GetValue(id, "ignorePages")) != null)
{
strArray2 = ((string) Settings.GetValue(id, "ignorePages")).Split(separator);
}
string rawUrl = app.Request.RawUrl;
if (((app.Context.Request.ServerVariables["REQUEST_METHOD"].ToLower() == "put") || (app.Context.Request.ServerVariables["REQUEST_METHOD"].ToLower() == "head")) && (app.Request.PathInfo != null))
{
int length = rawUrl.LastIndexOf(app.Request.PathInfo);
if (length != -1)
{
rawUrl = rawUrl.Substring(0, length);
}
}
int startIndex = rawUrl.LastIndexOf("/");
if (startIndex != -1)
{
rawUrl = rawUrl.Substring(startIndex, rawUrl.Length - startIndex);
}
else
{
rawUrl = "/" + rawUrl;
}
bool flag = false;
if (strArray != null)
{
foreach (string str3 in strArray)
{
if ((str3 != null) && (str3 != ""))
{
str2 = ("/" + str3.Trim()).Replace("+", "(.+?)").Replace("?", "(.??)").Replace("*", "(.*?)");
if (Regex.IsMatch(rawUrl, str2, RegexOptions.IgnoreCase))
{
flag = true;
break;
}
}
}
}
if (!flag)
{
return false;
}
if (strArray2 != null)
{
foreach (string str4 in strArray2)
{
if ((str4 != null) && (str4 != ""))
{
str2 = ("/" + str4.Trim()).Replace("+", "(.+?)").Replace("?", "(.??)").Replace("*", "(.*?)");
if (Regex.IsMatch(rawUrl, str2, RegexOptions.IgnoreCase))
{
return false;
}
}
}
}
return true;
}
internal static bool IsValidMaxRequestLength(long length, string id)
{
if (!((bool) Settings.CommonSettings["ignoreHttpRuntimeMaxRequestLength"]) && (length > Settings.HTTPRuntime_MaxRequestLength))
{
return false;
}
long num = (long) Settings.GetValue(id, "maxRequestLength");
if ((num != -1) && (length > num))
{
return false;
}
return true;
}
private bool isValidMaxRequestLengthToCloseConnection(long length, string id)
{
long num = (long) Settings.GetValue(id, "maxRequestLengthToCloseConnection");
if ((num > 0) && (length > num))
{
return false;
}
return true;
}
private bool IsValidMethod(HttpApplication application)
{
return (application.Context.Request.ServerVariables["REQUEST_METHOD"].ToLower() == "post");
}
private bool IsValidMinRequestLength(long length, string id)
{
long num = (long) Settings.GetValue(id, "minRequestLengthProcess");
if ((num > 0) && (length < num))
{
return false;
}
return true;
}
private bool IsValidPost(HttpApplication application)
{
if ((application.Context.Request.ServerVariables["REQUEST_METHOD"].ToLower() != "post") || (!application.Context.Request.ServerVariables["HTTP_Content_Type"].ToLower().StartsWith("multipart/form-data") && !application.Context.Request.ServerVariables["CONTENT_TYPE"].ToLower().StartsWith("multipart/form-data")))
{
return false;
}
return true;
}
private bool IsValidPut(HttpApplication application)
{
return (application.Context.Request.ServerVariables["REQUEST_METHOD"].ToLower() == "put");
}
private void PostRequest(HttpApplication application, string id, long contentLength)
{
AddDebugInfo("_ProcessProgress with id=" + id + " was added", id);
ProcessProgress progress = new ProcessProgress(id);
progress._UploadModuleID = this.UploadModuleID;
colProcessProgress.Add(id, progress);
if (this.IsValidMinRequestLength(contentLength, id))
{
if (!this.isValidMaxRequestLengthToCloseConnection(contentLength, id))
{
AddDebugInfo("UploadModule.PostRequest(): Content length of Request (" + application.Context.Request.ContentLength + ") is greater than maxRequestLength. Request will be terminated.", id);
this.CloseConnection(application);
progress._TotalBytes = contentLength;
progress._Status = UploadState.ConnectionClosed;
progress._EndTime = DateTime.Now;
throw new HttpException("Maximum request length exceeded.");
}
AddDebugInfo("UploadModule.PostRequest(): Content length of Request (" + application.Context.Request.ContentLength + ") is valid", id);
HttpWorkerRequest workerRequest = this.GetWorkerRequest(application);
if (workerRequest == null)
{
AddDebugInfo("UploadModule.PostRequest(): HTTPWorker is null. Nothing to do.", id);
}
else
{
progress._WorkerRequest = workerRequest;
progress._HttpContext = application.Context;
IUploadHandle uploadHandle = this.GetUploadHandle(id);
ElementIT.PowUpload.PowUpload info = null;
if (uploadHandle != null)
{
info = new ElementIT.PowUpload.PowUpload(id);
}
if ((uploadHandle == null) || ((uploadHandle != null) && uploadHandle.StartParseRequest(info)))
{
AddDebugInfo("UploadModule.PostRequest(): Create ProcessUpload class and run ParseRequest()", id);
ProcessUpload upload2 = new ProcessUpload(id);
upload2._app = application;
upload2._hInfo = info;
upload2._uploadHandle = uploadHandle;
upload2._ContentLength = contentLength;
upload2.ParseRequest();
}
else
{
AddDebugInfo("UploadModule.PostRequest(): IUploadHandleStartParseRequest returns false -> don't start parser", id);
progress._TotalBytes = contentLength;
progress._Status = UploadState.Rejected;
progress._EndTime = DateTime.Now;
}
if (uploadHandle != null)
{
uploadHandle.EndParseRequest(info);
}
}
}
else
{
AddDebugInfo("UploadModule.PostRequest(): Content length of Request (" + application.Context.Request.ContentLength + ") is less than MinRequestLength. Request would not processed", id);
progress._TotalBytes = contentLength;
progress._Status = UploadState.Rejected;
progress._EndTime = DateTime.Now;
}
}
private void SetLastError(Exception ExToShow, string id)
{
if ((colProcessProgress[id] != null) && (((ProcessProgress) colProcessProgress[id])._lastError != null))
{
((ProcessProgress) colProcessProgress[id])._lastError = ExToShow;
}
}
private void TestFrameworkVersion()
{
AddDebugInfo("UploadModule.TestFrameworkVersion() start. Version:" + Environment.Version.ToString());
if ((Environment.Version.Major == 1) && (Environment.Version.Minor == 0))
{
throw new Exception("You are executing Element-IT.PowUpload.dll assembly for .NET Framework 1.1 or higher under .NET Framework 1.0! Please use another assembly. You can find assembly for .NET Framework 1.0 in PowUpload distribution package.");
}
}
public override string ToString()
{
return base.ToString();
}
private void WriteDebugTrace(string id)
{
if (WriteDebug)
{
try
{
string message = "";
if (DebugTrace["common"] != null)
{
message = message + "Common trace:\r\n" + DebugTrace["common"];
DebugTrace["common"] = "";
}
if ((id != null) && (DebugTrace[id] != null))
{
object obj2 = message;
message = string.Concat(new object[] { obj2, "Personal trace for id=", id, ":\r\n", DebugTrace[id] });
DebugTrace[id] = null;
DebugTrace.Remove(id);
}
EventLog.WriteEntry("PowUpload", message, EventLogEntryType.Information);
}
catch
{
}
}
}
private void WriteLog(string message, string id)
{
if ((bool) Settings.GetValue(id, "logExceptions"))
{
try
{
EventLog.WriteEntry("PowUpload", message, EventLogEntryType.Error);
}
catch
{
}
}
}
public static string ModuleName
{
get
{
return "ElementIT.PowUpload.UploadModule";
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -