ASP.NET - How can I build a browser definition file that detects ONLY Googlebot?
I've tried looking at the Oceans BrowserCap file for inspiration, but it's just a little over the top for me.
I basically need the equivalent of this in a .browser file
<browserCaps>
<filter>
<!-- Google Crawler -->
<case match="Googlebot">
browser=Googlebot
crawler=true
</case>
</filter>
</browserCaps>
but I just can't seem to fi开发者_运维技巧gure this out. Any help would be great
Got it... here it is for the next guy that needs it.
<browsers>
<browser id="Googlebot" parentID="Mozilla">
<identification>
<userAgent match="Googlebot" />
</identification>
<capabilities>
<capability name="crawler" value="true" />
</capabilities>
</browser>
</browsers>
And here's my MVC ActionFilterAttribute that I use to detect the Goog..
Imports System.Web.Mvc
Imports System.Net
Imports System.Web
Namespace Filters
<AttributeUsage(AttributeTargets.Method, AllowMultiple:=False)> _
Public Class SearchBotFilter : Inherits ActionFilterAttribute
Public Overrides Sub OnActionExecuting(ByVal c As ActionExecutingContext)
If Not HttpContext.Current.Request.Browser.Crawler Then
HttpContext.Current.Response.StatusCode = CInt(HttpStatusCode.NotFound)
c.Result = New ViewResult() With {.ViewName = "NotFound"}
End If
End Sub
End Class
End Namespace
End Class
精彩评论