我有Default.aspx页面,它继承自BasePage.cs,它继承自System.Web.UI.Page.BasePage是我在加载时每页必须做的一些常见事情.
在BasePage中,假设我正在检查X.如果X = 1,那么我将立即重定向到我的"Discontinued.aspx"页面并停止执行BasePage.如果我发现X = 1,我说:
HttpContext.Current.Response.Redirect("Discontinued.aspx",true);
我希望重定向停止执行BasePage并立即跳出 - 因此上面语句中的"true" - 应该停止执行当前页面,据我所知.问题是,它没有.我期待重定向抛出"线程中止异常".
当我在调试模式下运行时,它会逐步调整,就好像它不仅仅是重定向和离开一样.
但重定向仍然开始 - 一旦我完成了其他的BasePage,"Discontinued"页面就会因重定向而开始加载.
有没有理由我的Redirect不会杀死BasePage的执行?
在网页上,我正在呼叫第三方,它不允许我以编程方式设置超时.我调用BeginInvoke并使用AsyncWaitHandle.WaitOne等待指定的时间.
如果呼叫超时,我继续前进,忘记我开始的线程呼叫.我的问题是,在超时情况下,我是否还要以某种方式调用EndInvoke?这个MSDN页面上的"注意"注释让我想知道我是否应该:http://msdn.microsoft.com/en-us/library/2e08f6yc(VS.71).aspx
如果您认为我应该,那么接下来的问题是,如果我的网页已经完成处理并在第三方回来之前返回到客户端,那么回调方法是否会在那里听取运行代码?一旦我的请求/响应完成,服务器是否停止寻找活动?
这是我正在使用的代码:
public class RemotePaymentProcessor
{
private delegate string SendProcessPaymentDelegate(string creditCardNumber);
private string SendProcessPayment(string creditCardNumber)
{
string response = string.Empty;
// call web service
SlowResponseService.SlowResponseService srs = new WebServiceTimeout.SlowResponseService.SlowResponseService();
response = srs.GetSlowResponse(creditCardNumber);
return response;
}
public string ProcessPayment(string creditCardNumber, int timeoutMilliseconds)
{
string response = string.Empty;
SendProcessPaymentDelegate sppd = new SendProcessPaymentDelegate(SendProcessPayment);
IAsyncResult ar = sppd.BeginInvoke(creditCardNumber, null, new object());
if (!ar.AsyncWaitHandle.WaitOne(timeoutMilliseconds, false))
{
// Async call did not return before timeout
response = "TIMEOUT";
}
else …Run Code Online (Sandbox Code Playgroud) 在我的提交按钮上,我想要做的是OnClick显示"请等待"面板并隐藏按钮,除非验证器说某些内容无效 - 然后我需要按钮仍然显示.否则,我有一个显示错误的验证摘要,无法再次提交.
我发现大多数关于这样做的文章都希望使用Page_ClientValidate()函数来告诉页面验证自己,但这对我来说是未定义的,就像Page_IsValid变量一样.这是我正在尝试使用的功能 - 我缺少什么?:
function PleaseWaitShow() {
try {
alert("PleaseWaitShow()");
var isPageValid = true;
// Do nothing if client validation is not active
if (typeof(Page_Validators) == "undefined") {
if (typeof(Page_ClientValidate) == 'function') {
isPageValid = Page_ClientValidate();
alert("Page_ClientValidate returned: " + isPageValid);
alert("Page_IsValid=" + Page_IsValid);
} else {
alert("Page_ClientValidate function undefined");
}
} else {
alert("Page_Validators undefined");
}
if(isPageValid) {
// Hide submit buttons
document.getElementById('pnlSubmitButton').style.visibility = 'hidden';
document.getElementById('pnlSubmitButton').style.display = 'none';
// Show please wait panel
document.getElementById('pnlPleaseWait').style.visibility = 'visible';
document.getElementById('pnlPleaseWait').style.display …Run Code Online (Sandbox Code Playgroud) 我有一个WebApplication项目,一个业务逻辑项目和一个Web应用程序的WebDeployment项目.
当我构建解决方案时,部署"Release"bin包含每个项目的1个dll - 所以我得到一个用于MyWeb.dll,MyWebBusiness.dll和MyWebDeploy.dll.
当我尝试运行该站点时,它在MyWeb.dll和MyWebDeploy.dll以及chokes中看到相同的类型.
错误消息:CS0433:类型'AV'存在于'c:\ WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\53d45622\6c032bd2\assembly\dl3\33f3c6b2\abc9430a_285ac901\MyWeb .DLL'和'c:\ WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\53d45622\6c032bd2\assembly\dl3\631e5302\0231160d_285ac901\MyWebDeploy.DLL'
我需要检查我们的访问者是否使用HTTPS.在BasePage中,我检查请求是否来自HTTPS.如果不是,我会使用HTTPS重定向.但是,当有人来到该网站并使用此功能时,我收到错误:
System.Web.HttpException:在发送HTTP标头后,服务器无法附加标头.在Premier.Payment.Website.Generic.BasePage..ctor()的System.Web.HttpResponse.AddHeader(String name,String value)的System.Web.HttpResponse.AppendHeader(String name,String value)处
这是我开始使用的代码:
// If page not currently SSL
if (HttpContext.Current.Request.ServerVariables["HTTPS"].Equals("off"))
{
// If SSL is required
if (GetConfigSetting("SSLRequired").ToUpper().Equals("TRUE"))
{
string redi = "https://" +
HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToString() +
HttpContext.Current.Request.ServerVariables["SCRIPT_NAME"].ToString() +
"?" + HttpContext.Current.Request.ServerVariables["QUERY_STRING"].ToString();
HttpContext.Current.Response.Redirect(redi.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
我也尝试在上面添加它(我在另一个站点中使用了一点类似的问题):
// Wait until page is copletely loaded before sending anything since we re-build
HttpContext.Current.Response.BufferOutput = true;
Run Code Online (Sandbox Code Playgroud)
我在IIS 6上使用.NET 3.5中的c#.
我有一个Web表单页面Default.aspx,它继承自我创建的BasePage类,后者继承自System.Web.UI.Page.很常见的设置.
Default : BasePage : System.Web.UI.Page
Run Code Online (Sandbox Code Playgroud)
在BasePage.BasePage()(构造函数)中,如果我们不进行回发,我想做点什么.所以我把标准
if(!Page.IsPostBack)
{
// do stuff here
}
Run Code Online (Sandbox Code Playgroud)
但是,Page.IsPostBack即使我真正回帖,也总是返回false.
那么我的问题是,这只是BasePage无法IsPostBack在页面级别上看到变量的限制吗?
或者是否有一件额外的作品我就像我必须说HttpContext.Current.Request而不只是Request在页面上一样?
asp.net ×3
c# ×2
.net ×1
begininvoke ×1
header ×1
http ×1
https ×1
javascript ×1
timeout ×1
validation ×1