我写了这个方法来检查页面是否存在:
protected bool PageExists(string url)
{
try
{
Uri u = new Uri(url);
WebRequest w = WebRequest.Create(u);
w.Method = WebRequestMethods.Http.Head;
using (StreamReader s = new StreamReader(w.GetResponse().GetResponseStream()))
{
return (s.ReadToEnd().Length >= 0);
}
}
catch
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我用它来检查一组页面(从AAAA-AAAZ迭代),运行整个循环需要3到7秒.有没有更快或更有效的方法来做到这一点?
我正在用Visual Studio 2008和ASP.NET 3.5编写一个网站.我设置了一个母版页来简化布局并保留内容页面而不是内容和布局.
导航是列表,css'd所以它看起来像一个酒吧.为了突出显示栏上的页面,列表项需要如下所示<li id="current">.<asp:ContentPlaceHolder>如果我可以避免它,我不想使用它.是否有一些代码可以添加到我的每个页面(或者只是添加到母版页?)来实现这一目标,还是我坚持使用<asp:ContentPlaceHolder>?
我有一个带有文本框和按钮的表单.IE是唯一一个按下Enter键时不提交表单的浏览器(适用于FF,Opera,Safari,Chrome等).我发现这个javascript函数试图哄骗IE进行表现; 但无济于事:
function checkEnter(e){
var characterCode
if (e && e.which) {
e = e
characterCode = e.which
} else {
e = event
characterCode = e.keyCode
}
if (characterCode == 13) {
document.forms[0].submit()
return false
} else {
return true
}
}
Run Code Online (Sandbox Code Playgroud)
执行:
searchbox.Attributes("OnKeyUp") = "checkEnter(event)"
Run Code Online (Sandbox Code Playgroud)
有什么建议?
编辑: CodeProject上的这个页面概述了Dillie所说的内容,它完美无缺.
如果这是一个愚蠢的问题,我很抱歉,但是我没有在本网站或其他网站上找到有关此问题的任何可靠信息.
话虽如此,我正在研究MVC 5 Web应用程序.我在ASP.net上关注本教程.
public async Task SendAsync(IdentityMessage message)
{
await configSendGridasync(message);
}
private async Task configSendGridasync(IdentityMessage message)
{
var myMessage = new SendGridMessage();
myMessage.AddTo(message.Destination);
myMessage.From = new System.Net.Mail.MailAddress(
"info@ycc.com", "Your Contractor Connection");
myMessage.Subject = message.Subject;
myMessage.Text = message.Body;
myMessage.Html = message.Body;
var credentials = new NetworkCredential(
Properties.Resources.SendGridUser,
Properties.Resources.SendGridPassword,
Properties.Resources.SendGridURL // necessary?
);
// Create a Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email.
if (transportWeb != null)
{
await transportWeb.DeliverAsync(myMessage);
} …Run Code Online (Sandbox Code Playgroud) 当我在使用MasterPages的网站上导航时,应用程序是否知道我在哪个页面?如果是这样,它是否存储在我可以访问的对象中?
我问的原因是我可以替换这个:
//masterpage
<div id="nav_main">
<ul><asp:ContentPlaceHolder ID="navigation" runat="server">
</asp:ContentPlaceHolder></ul>
</div>
//content page(s)
<asp:Content ContentPlaceHolderID="navigation" ID="theNav" runat="server">
<li><a href="default.aspx">Home</a></li>
<li id="current"><a href="faq.aspx">FAQ</a></li>
<li><a href="videos.aspx">Videos</a></li>
<li><a href="#">Button 4</a></li>
<li><a href="#">Button 5</a></li>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
使用更优雅的导航解决方案,通过将列表项的ID设置为"当前"来突出显示页面的链接.目前,每个页面都会重新创建导航,并将其相应链接的ID设置为当前.
看这个例子:
''//file1.vb
Sub Something()
''//...
Functions.LogInfo("some text")
''//...
End Sub
''//functions.vb
Sub LogInfo(ByVal entry as String)
Console.WriteLine(entry)
End Sub
Run Code Online (Sandbox Code Playgroud)
我可以在LogInfo中获得名称"Something"吗?
对于这篇文章的简要说明,我不知道如何恰当地表达这个问题.我会根据需要澄清和阐述.
我写了以下函数,大约95%的时间都有效,但我需要它100%工作(显然):
Public Shared Function getPassedVars() As String
Const keyCount As Integer = 54 ' 54 seems to be the number of parameter keys passed by default (for this web_app).
' there are more if there is a form involved (ie. from search page)
Dim oParams As String = ""
Try
With HttpContext.Current
If .Request.Params.AllKeys.Count > keyCount Then
For i As Integer = 0 To (.Request.Params.AllKeys.Count - (keyCount + 1))
oParams &= String.Format("{0}={1}{2}", .Request.Params.Keys.Item(i), .Request.Params(i), IIf(i < .Request.Params.AllKeys.Count - (keyCount + …Run Code Online (Sandbox Code Playgroud) 是否可以将变量传递给链接的.js文件?我试过这个:
<sf:JsFileLink ID="JQueryLoader" runat="server" ScriptType="Custom" FileName="~/Files/Scripts/rotatorLoader.js?timeout=1000" />
Run Code Online (Sandbox Code Playgroud)
但是萤火虫告诉我没有定义超时.这是.js文件的代码:
$(document).ready(function() {
$("#rotator > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", timeout, true);
});
Run Code Online (Sandbox Code Playgroud)
我正在使用<sf:JsFileLink ... />标签是因为我正在使用的网站使用sitefinity,这个标签允许我加载外部.js文件.
我能够通过创建一个模拟javascript页面的aspx页面来"欺骗"include:
<%@ Page Language="C#" %>
<%
Response.ContentType = "text/javascript";
Response.Clear();
string timeout;
try
{
timeout = Session["timeout"].ToString();
}
catch
{
timeout = "4000";
}
%>
$(document).ready(function() {
$("#rotator > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", <%=timeout %>, true);
});
Run Code Online (Sandbox Code Playgroud)
在用户控制页面上:
[DefaultProperty("BannerTimeout")]
public partial class Custom_UserControls_TabbedRotator : System.Web.UI.UserControl
{
[Category("Configuration")]
[Description("Sets the rotation timeout, …Run Code Online (Sandbox Code Playgroud) 正如我的标题所述,我想知道是否可以显示命令提示符窗口(至少是暂时的)以确保我的批处理文件确实按计划执行.我手动运行批处理文件时运行没有错误.
批处理文件驻留在Windows Server 2008 R2 Standard,x64上,我安装了Service Pack 1.如果需要更多信息,请告诉我.
非常感谢!
我有一个函数检查cookie(按名称)是否存在:
Private Function cookieExists(ByVal cName As String) As Boolean
For Each c As HttpCookie In Response.Cookies
If c.Name = cName Then Return True
Next
Return False
End Function
Run Code Online (Sandbox Code Playgroud)
我有一个以特定于应用程序的方式处理cookie的类,我想将所有与cookie相关的函数合并到这个类中.但是,如果我只是将它从aspx页面(它当前所在的位置)移动到上述类,我就无法使用此代码,因为我收到了错误:'Name' Response is not declared. 我修改了类以允许传递Response对象的引用:
Public Function cookieExists(ByVal cName As String, ByRef Response As HttpResponse) As Boolean
For Each c As HttpCookie In Response.Cookies
If c.Name = cName Then Return True
Next
Return False
End Function
Run Code Online (Sandbox Code Playgroud)
我的问题是:有更好的方法吗?
asp.net ×6
c# ×2
javascript ×2
navigation ×2
vb.net ×2
asp.net-mvc ×1
batch-file ×1
class ×1
cookies ×1
css ×1
email ×1
httpresponse ×1
jquery ×1
master-pages ×1
parameters ×1
request ×1
sendgrid ×1
sitefinity ×1
textbox ×1