If I understood correctly Facebook externalhit scrapes page every 24h for new data. Since my users are going to share dynamic images on Facebook,the image should not be cached, because it would change much more then once every 24h.
Does externalhit ignores something like:
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Is there some way to force it not to cache image? I know using linter clears cache but it would be silly to instruct my users to run linter every time they want to see a changed image instead of cached one.
I assume some script to lint urls programmatically would be agianst their TOS?
Use a different URL for each image, and have the like button point to that URL - that's basically the only way to do this - otherwise you'd retroactively be changing the details of the thing which was liked - and the fields are locked after X likes and won't be updated ( I think X = 100)
I guess it's not possible! Just to accept answer.
Related
I have broken up a humongous page into several "bite-size" chunks. I want to present them, one at a time, to the user. After one page, they click an HTML button ("Next") and the previous Web Part or Content Editor Web Part is replaced by the next one.
From this page, I came up with some pseudcode (I don't know if there really is a SPLimitedWebPartManager.RemoveWebPart() method that I can call, as pseudocoded below, or how to get a reference to the currently (about-to-be-replaced) [Content Editor] Web Part, but this is the basic idea:
using (SPSite site = new SPSite("http://~"))
{
SPWeb web = site.RootWeb;
SPFile page = web.GetFile("Pages/Web_Form_Post_Travel_Expense.aspx");
page.CheckOut();
using (SPLimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
XmlElement d = new XmlDocument().CreateElement("div");
d.InnerText = get
ContentEditorWebPart cewp = new ContentEditorWebPart
{
Content = d
};
ContentEditorWebPart currentCEWP = ?;
wpmgr.RemoveWebPart(currentCEWP);
wpmgr.AddWebPart(cewp, "Header", 0);
}
page.CheckIn(String.Empty);
}
Does this make sense? It seems kludgy or even downright weird to me, to be checking out the page, changing it, and checking it back in.
The only other thing I can think of at the moment is to put the entire shebang into one Web Part, but keep sections 2-6 hidden at first, and then successively show one segment (after hiding the previous one). IOW, this type of procedure:
First Section shows
All others hidden
User selects "Next" button
First section is hidden
Second section shows, while all others remain hidden.
etc.
Actually, both ideas seem at least a little wonky to me. Is one approach preferable, or is there a third way I haven't thought of that would be better than both?
What are CheckOut() and CheckIn(string value) for? Is that the question?
I looked at the Microsoft.SharePoint namespace and the SPSite class, but nothing appeared to be defined.
My best guess is this is a way of placing a lock on a document while it is opened by another person.
See the following supporting items:
SPFile.SPCheckOutStatus enumeration
SPFile.SPCheckOutType enumeration
SPFileCheckOutExceptionType enumeration
SPFile.SPLockType enumeration
That way, if you have Mark Twain checked out to edit, no one else can check that out to edit.
If, on the other hand, you simply want to view the contents, you could check out a section, read it all in to a StringBuilder, check the contents back in to SharePoint, and then display the text as you need it.
I am going to create a function in my application that is going to send som status mails to several receivers in a list.
Earlier i used plane text format on the email, but now i want to send the mail based on som html templates. I need tips reguarding a good way to insert data into these templates before sending them.
eks
%CpuStatus%
%HardriveStatus%
and so on. I have the solution for everything except a way to fill anchors like that with data. This is a WinForm application so i dont have access to the ASP functionality
Maybe this sort of thing would be the simplest?
// This would most likely be loaded from a file or database.
string emailBody = "CPU Status: %CpuStatus%\nHard Drive Status: %HardriveStatus%";
string cpuStatus = MyService.GetCpuStatus();
emailBody.Replace("%CpuStatus%", cpuStatus);
If you really wanted to make a big project out of it, you can use a webbrowser control, load it with your html file and then use the WebBrowser's Document property to get an HtmlDocument object. You can then loop through it's children (recursively) to find the tags you want to change.
Personally, I would do the .Replace method suggested previously.
What is the best method to cache the following? I am creating an intranet web application template that will display the message, e.g., Good Morning, Justin Satyr! near the top of my master page header. Obviously, I will have to determine whether to show Morning, Afternoon or Evening. For clarity, my code is below:
string partOfDay;
var hours = DateTime.Now.Hour;
if (hours > 16)
{
partOfDay = "evening";
}
else if (hours > 11)
{
partOfDay = "afternoon";
}
else
{
partOfDay = "morning";
}
I do not want to re-determine this on each page load because that seems moderately redundant and because I have to poll a SQL server to retrieve the user's full name. What is the best way to cache this information? If I cache it for the length of the session, then if the user begins using the application at 11:00 AM and finishes at 3:00 PM, it will still say Good Morning.
Is the best thing to do simply re-determine the M/A/E word each page load and cache the person's full name for the session? Or is there a better way?
I would just keep the user name in the Session object, the rest honestly is not worth caching and checking if it is out of date etc., just re-run it on each page - provided you put the implementation into a common library /class so you keep your code DRY.
In my opinion there is absolutely no need to cache the part of day. User information can be made available in the Session.
If you are talking in ASP.NET MVC context, you can use System.Web.Helpers namespace, where you can find WebCache helper. Than you need to calculate minutes to time of day_time will be changed and call WebCache.Set method with paramters: value="your string", minutesToCache=calculated_value.
Old, I know, but I don't cache mine, due to the obvious reason that the users time may change during the session. I store their calculated time in my session (calculates based on their timezone), and then use this code at the top of all pages:
<strong>#string.Format("Good {0}, ", SessionManager.GetUserCurrentDate().Hour > 16 ? "Evening" : SessionManager.GetUserCurrentDate().Hour > 11 ? "Afternoon" : "Morning") + SessionManager.GetDisplayName())</strong>
Works well for me!
I ask here about XNA and not on it's official forums because people from my country are not allowed to sign in to the new XNA website.
Well, these are my questions:
I want to use some 2D images I create in Paint Shop Pro/Photo Shop/Paint, but for some reason I need to use web safe pallet and such settings for it to be displayed currently (I use transparency).
could any1 please explain to me how can I use transparency & other settings (while creating & saving the image) so that the XNA (4.0) could display it correctly?
By the way, it might be that I just need some 1 to explain to me how to set the "GraphicsDevice"-s settings to work with transparency layer/channel.
I really do try to do things as I am supposed to (by Microsoft's view) & thus I use the content pipeline for ALL of my content loading (including classes initiation data files).
I use .txt files for storing my class initiation data & I edit them with simple good old notepad (++ :P).
Now, the problem is that all I managed to do is loading the .txt file as a really long string instead of creating a new instance of my GameDataFile class.
because of that I was forced to do it in 2 steps:
Step 1:
string tempStrData = content.load<string>("data/filename").Replace("\r", "");
/* Loads a string from a file (the string is the whole file!) */
Step 2:
GameDataFile gameDataFile = new GameDataFile(tempStrData.Split('\n'));
/* Sends the string to my GameDataFile class constructor which knows how to handle that string and break it to it's data elements (ints, strings vectors, etc...) */
I want to upgrade it to be of the following form:
GameDataFile gameDataFile = content.load<GameDataFile>("data/fileName");
I think I should do this using a custom Content pipeline Processor, any opinions if I'm right & how should I achieve that?
P.S please don't make me to use public members as I always set that to private and I hate and strictly forbid myself from using the C#-ONLY-get-&-set methods.
Thanks In Advance, Tal A.
For your first question, set the blendstate to AlphaBlend when you begin your SpriteBatch:
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null);
I save my images as PNGs in PhotoShop which allows transparency.
Edit: Unless you're referring to 3D textures. If so I'll have to revise my answer
Edit: As for question 2, this example on App Hub shows how to do it.
On this site if you do too many clicks or post comments too fast or something like that you get redirected to the "are you a human" screen. Does anybody know how to do something similar?
It's almost certainly a heuristic that tries to "guess" that a user is some form of automated process, rather than a person, for example:
More than "x" requests to do the same thing in a row
More than "x" actions in a "y" period of time
Ordinarily the "x" and "y" values would be formulated to be ones that it would be unlikely for a "real person" to do, like:
Editing the same answer 5 times in a row
Downvoting 10 questions within 1 minute
Once you've got your set of rules, you can then implement some code that checks them at the start of each request, be it in a method that's called in Page_Load, something in your masterpage, something in the asp.net pipeline, that's the easy bit! ;)
Here is a very nice Captcha Control for asp.net that first of all you need
http://www.codeproject.com/KB/custom-controls/CaptchaControl.aspx
Then you can use it together with this idea that try to find the dos attacks
http://weblogs.asp.net/omarzabir/archive/2007/10/16/prevent-denial-of-service-dos-attacks-in-your-web-application.aspx
be ware of a bug in this code in line if( context.Request.Browser.Crawler ) return false;, its must return true, or totally remove it for sure.
and make it your compination for the clicks, or submits.
If a user make too many clicks on a period of time, or many submits, then you simple open the capthaControl, and if the clicks are by far too many, then triger the dos attact. This way you have 2 solution in one, Dos attact prevent, with captcha at the same time.
I have made somthing similar my self, but I have change the source code of both, a lot to feet my needs.
One more interesting link for a different code for the dos attack.
http://madskristensen.net/post/Block-DoS-attacks-easily-in-ASPNET.aspx
Hope this help you.
At a guess...
Write a HTTP handler that records requests and store them in session.
When a new request comes in, check to see how many requests are stored (and expire old ones).
If the amount of requests in the past few minutes exceeds a given threshold, redirect the user.
If you're doing this in ASP.NET webforms, you could do this check on the site master page, ( or write a IHttpHandler).
If you're using an MVC framework, you could write a base controller that does this check for every action.
With rails, you could write a before_request filter.
With asp.net MVC, you could write a [ActionFilterAttribute] attribute
You should have a session to track the user activity.
In session you can have counter for commenting and posting like:
(pseudo code instead of C#, sorry :)
if (post_event) {
posts_during_1_minute_interval++;
if (time_now-reference_time > 1_minute) {
reference_time = time_now;
posts_during_1_minute_interval=0;
}
}
...
if (posts_during_1_minute_interval > 10) redirect("/are-you-human.htm");
where on are-you-human.htm page you can have recaptcha, as they have here on StcakOverflow.com
see also:https://blog.stackoverflow.com/2009/07/are-you-a-human-being/
just check how many hit / minutes you get from a specific ip or session or whatever and decide what are your preferred threshold and your good to go
I'd also check the user agent header of the request - if it doesn't look like a popular browser (or is empty) then throw the "are you a human?" page.