在我的应用程序中,我正在尝试创建一种简单的方法,根据他们的名字链接到NFL.com上的NFL球员的个人资料.由于NFL.com的玩家资料页面没有可预测的网址结构,因此我尝试根据网址字符串创建指向Google"I Feel Lucky"结果的链接:
http://www.google.com/search?q=site:nfl.com + 姓名 + 姓氏 + 轮廓与BTNI
问题是:有时链接工作并带我到第一个"我感觉幸运"的结果,但有时它只是带我到标准的谷歌搜索结果页面.
示例1(带我到第一个结果,NFL.com):
http://www.google.com/search?q=site:nfl.com+Larry+Fitzgerald+profile&btnI
示例2(带我到Google搜索结果页面,而不是第一个结果)
http://www.google.com/search?q=site:nfl.com+Rob+Housler+profile&btnI
有没有办法确保我每次都能获得"I Feel Lucky"的结果?
编辑
以下是有效且无效的链接示例.请注意,这些链接之间的唯一区别是搜索字词,但有些会将您转移到第一个Google结果网站,有些会将您带到实际的搜索结果中.
工作(即我们被发送到第一个Google Result的网站,NFL.com)
不工作(即我们被发送到Google搜索结果页面)
在我的ASP.net Web应用程序中,我在Page的Page_Init event()中有代码,它会检查一些会话变量,以便在发生会话超时时重定向用户.
在我的Silverlight应用程序中,我有一个按钮事件处理程序,它以异步方式执行一些ESRI ArcGIS代码,并配置一个在异步调用完成时触发的事件处理程序:
QueryTask queryTask = new QueryTask(myLayer.Url + "/" + layerID);
queryTask.ExecuteCompleted += new EventHandler<QueryEventArgs>(queryCountyTask_ExecuteCompleted);
queryTask.ExecuteAsync(query);
Run Code Online (Sandbox Code Playgroud)
还有一些代码在页面上调用JavaScript函数来隐藏Panel.包含此代码会导致整页回发.
HtmlPage.Window.Invoke("hideReport");
Run Code Online (Sandbox Code Playgroud)
我的问题是有时queryCountyTask_ExecuteCompleted()Silvelright事件在Page_Init()Page事件之前触发,有时它会触发.在Silverlight在Page事件之前触发的情况下,会话状态为空,导致用户错误地重定向到"您的会话已超时"页面.只要Silverlight事件在Page事件之后触发,Session变量仍然存在,一切正常.
看起来Invoke方法的位置与触发页面级事件无关,因此事件的顺序看起来似乎是随机的.有没有办法订购活动以避免这些竞争条件?
有没有办法将这些异步回调事件与Web应用程序页面的正常页面生命周期进行协调,以避免这些竞争条件?
我需要使用新的ASP.NET Core 2.0 Web应用程序运行一些Active Directory查询.Microsoft的文档说System.DirectoryServices.AccountManagement 库是 .NET Core 2.0的一部分.
如何在NuGet中找到包含此命名空间的关联包?我在NuGet中看到的唯一一个是Microsoft以外的人不支持的库.
I use the web.sitemap of my ASP.net application to help build my navigation links. This way if my navigation changes, I update the web.sitemap, and it builds my navigation automatically. However since upgrading from ASP.net 3.5 to 4.0 I'm having problems related to my web.sitemap file. After upgrading to ASP.net 4.0 the links generated from my web.sitemap sometimes have strange characters inserted after the domain name (link broken on purpose because my limit is 2):
http //www.cheatsheetwarroom.com/(A(jUhJqoX4zAEkAAAAN2VlZTM2N2MtOWU5Mi00OWUyLTllZTUtMTY4MDY3ZGM2MTM2hMR-oHFFNS-DvXxMDadonaHu8pk1))/fantasy-football/nfl/free/rankings/offense/running-backs.aspx
You can see …
在我的项目中,我实现了自定义路由约束以允许通过自定义头变量(api-version)进行API版本控制,类似于Codeplex上的此示例项目,尽管我修改了约束以允许major.minor约定.
这涉及创建两个独立的控制器,其路由通过FullVersionedRoute属性区分:
Sample1Controller.cs
/// <summary>
/// v1.0 Controller
/// </summary>
public class Sample1Controller : ApiController
{
[FullVersionedRoute("api/test", "1.0")]
public IEnumerable<string> Get()
{
return new[] { "This is version 1.0 test!" };
}
}
Run Code Online (Sandbox Code Playgroud)
Sample2Controller.cs
/// <summary>
/// v2.0 Controller
/// </summary>
public class Sample2Controller : ApiController
{
[FullVersionedRoute("api/test", "2.0")]
public IEnumerable<string> Get()
{
return new[] { "This is version 2.0 test!" };
}
}
Run Code Online (Sandbox Code Playgroud)
FullVersionedRoute.cs
using System.Collections.Generic;
using System.Web.Http.Routing;
namespace HelperClasses.Versioning
{
/// <summary>
/// Provides an attribute …Run Code Online (Sandbox Code Playgroud) 我有一个基于.NET 4.0 ASP.net项目模板的网站.突然在我重建我的解决方案时,App_Code目录需要3-4分钟的编译时间(基于"输出"窗口中显示的内容).这个目录中只有大约13个类,它们都非常小.
我试图将这些文件从App_Code目录移到一个单独的类库项目,但其中一些依赖于System.Web.Security命名空间,该命名空间无法添加到非网站项目中.
调试这个以确定什么是编译过程的最佳方法是什么?
我正在尝试使用类似于以下的结构来组织我的工作流程工件(在自托管运行器上):
c:\github\artifacts\{org}\{repo}\{runid}
Run Code Online (Sandbox Code Playgroud)
我们企业中的不同组织可以拥有同名的存储库,因此我希望能够按组织名称进行组织。
到目前为止我有这个:
c:\github\artifacts\{org}\{${{ github.event.repository.name }}\${{ github.run_id }}\
Run Code Online (Sandbox Code Playgroud)
如何确定组织名称?
我使用Http.Current.Cache存储从我的数据库中检索的各种值,因为我的应用程序是数据密集型的.在我的新笔记本电脑上使用VS2017安装运行我的网站时(在VS2015的另一台笔记本电脑上我从未见过这个问题),我看到一个非常奇怪的问题,其中缓存的值似乎被随机清除 - 几乎是以违反逻辑的方式.
例如,我有一个if子句,其条件是所讨论的缓存项不为null.我的代码肯定是通过这个if语句的路径,但稍后调试器显示缓存项实际上是空的 - 导致我的应用程序失败.
public static SportSeason GetCurrentSportSeason(string sportCode)
{
SportSeason sportSeason = null;
string key = "Sheets_SportSeason_" + sportCode;
int i = 0;
if (BaseSheet.Settings.EnableCaching && BizObject.Cache[key] != null)
{
i = 1;
sportSeason = (SportSeason)BizObject.Cache[key];
}
else
{
i = 2;
sportSeason = GetSportSeasonFromSportSeasonDetails(SiteProvider.Sheets.GetCurrentSportSeason(sportCode));
BaseSheet.CacheData(key, sportSeason);
}
if(sportSeason == null)
{
int j = i;
}
return sportSeason;
}
Run Code Online (Sandbox Code Playgroud)
我可以在final if中设置断点,并且变量i设置为1,但sportSeason对象为NULL(缓存条目也是如此).当代码进入第一个if子句的唯一方法是缓存项是否为空时,这怎么可能呢?
这很难追踪,因为它在我的业务对象中随机发生.在我看到这个问题之前,有时我必须刷新页面3到4次.
如何快速地使缓存失效,以及通过什么?屏幕截图显示缓存项目不多,所以我不认为我的内存不足.并且没有其他进程正在运行,这可能会破坏缓存.
编辑:通过更多调试,我确定只有在断点处再次检查时,才会清除第91行上检查的缓存键(设置为空).所有其他缓存记录仍然存在.
编辑2:我已经将问题归结为此,尽管它似乎仍然违背逻辑:
HttpContext.Current.Cache.Insert("ABC", "123", null, DateTime.Now.AddSeconds(600), …Run Code Online (Sandbox Code Playgroud) 如果我创建一个空白的 ASP.net Web Core 应用程序,然后将 Startup.cs 中的 Configure() 方法替换为以下方法,则每个 Use() 和 Run() 操作都会调用两次。
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.Use(async (context, next) =>
{
// Do work that doesn't write to the Response.
await next.Invoke();
// Do logging or other work that doesn't write to the Response.
int i = 0;
});
app.Use(async (context, next) =>
{
// Do work that doesn't write to the Response.
await next.Invoke();
// Do logging or other work that doesn't write to the …Run Code Online (Sandbox Code Playgroud) 是否有一种简单的LINQ方法将泛型集合投影到Dictionary中,这将消除以下代码块中的foreach:
Dictionary<int, Player> _rankedPlayers = new Dictionary<int,Player>();
List<Player> rankedPlayers = Player.GetPlayers(Globals.FOOString, seasonCode);
int i = 1;
foreach (Player targetPlayer in rankedPlayers)
{
_rankedPlayers.Add(i, targetPlayer);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用一个扩展通用列表的扩展方法.这有效
public static void Shuffle<T>(this IList<T> list)
{
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
int n = list.Count;
while (n > 1)
{
byte[] box = new byte[1];
do provider.GetBytes(box);
while (!(box[0] < n * (Byte.MaxValue / n)));
int k = (box[0] % n);
n--;
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建另一个使用Shuffle()的扩展方法,但是会根据定义的组大小将组中的项目分组.调试扩展方法时,此方法似乎有效,但调用代码中的源列表仍包含扩展调用后的原始列表:
public static void GroupRandomize<T>(this IList<T> sourceList, int groupSize)
{
List<T> shuffledList = new List<T>();
List<T> tempList = new List<T>();
int addCounter = 0; …Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×4
asp.net-core ×2
.net ×1
arcgis ×1
asp.net-mvc ×1
c#-4.0 ×1
caching ×1
generics ×1
github-actions-self-hosted-runners ×1
html ×1
iis-7 ×1
linq ×1
nuget ×1
search ×1
silverlight ×1
web-config ×1
web.sitemap ×1