Sunday, 1 September 2013

Automatic redirect to login page after a certain time

Automatic redirect to login page after a certain time

I am using form authentication. My code in web.config is:
<authentication mode="Forms">
<forms loginUrl="~/Home/Index" timeout="5" />
</authentication>
I've used [Authorize] at the head of the actions, that need authentication
to access. As my configuration in web.config after five minutes an user is
redirected to "../Home/Index" if he/she tries to access an action or load
a page that is need authentication to access. Is there any way to do it
automatically. I mean if the system is idle, like though no one is using
the system after five minutes it will automatically redirect to
"../Home/Index" page.

Not able to retrieve OriginalValues in Entity Framework 5

Not able to retrieve OriginalValues in Entity Framework 5

I am writing a asp.net mvc4 app and I am using entity framework 5. Each of
my entities have fields like EnteredBy, EnteredOn, LastModifiedBy and
LastModifiedOn.
I am trying to auto-save them by using the SavingChanges event. The code
below has been put together from numerous blogs, SO answeres etc.
public partial class myEntities : DbContext
{
public myEntities()
{
var ctx = ((IObjectContextAdapter)this).ObjectContext;
ctx.SavingChanges += new EventHandler(context_SavingChanges);
}
private void context_SavingChanges(object sender, EventArgs e)
{
ChangeTracker.DetectChanges();
foreach (ObjectStateEntry entry in
((ObjectContext)sender).ObjectStateManager
.GetObjectStateEntries
(EntityState.Added | EntityState.Modified))
{
if (!entry.IsRelationship)
{
CurrentValueRecord entryValues = entry.CurrentValues;
if (entryValues.GetOrdinal("LastModifiedBy") > 0)
{
HttpContext currContext = HttpContext.Current;
string userName = "";
DateTime now = DateTime.Now;
if (currContext.User.Identity.IsAuthenticated)
{
if (currContext.Session["userId"] != null)
{
userName =
(string)currContext.Session["userName"];
}
else
{
userName = currContext.User.Identity.Name;
}
}
entryValues.SetString(
entryValues.GetOrdinal("LastModifiedBy"), userName);
entryValues.SetDateTime(
entryValues.GetOrdinal("LastModifiedOn"), now);
if (entry.State == EntityState.Added)
{
entryValues.SetString(
entryValues.GetOrdinal("EnteredBy"), userName);
entryValues.SetDateTime(
entryValues.GetOrdinal("EnteredOn"), now);
}
else
{
string enteredBy =
entry.OriginalValues.GetString(entryValues.GetOrdinal("EnteredBy"));
DateTime enteredOn =
entry.OriginalValues.GetDateTime(entryValues.GetOrdinal("EnteredOn"));
entryValues.SetString(
entryValues.GetOrdinal("EnteredBy"),enteredBy);
entryValues.SetDateTime(
entryValues.GetOrdinal("EnteredOn"), enteredOn);
}
}
}
}
}
}
My problem is that
entry.OriginalValues.GetString(entryValues.GetOrdinal("EnteredBy")) and
entry.OriginalValues.GetDateTime(entryValues.GetOrdinal("EnteredOn")) are
not returning the original values but rather the current values which is
null. I tested with other fields in the entity and they are returning the
current value which were entered in the html form.
How do I get the original value here?

Saturday, 31 August 2013

Targeting objects in AS3

Targeting objects in AS3

I am wondering how to target specific objects/instances in flash as3. I
have 2 objects on the stage, for now we'll call them obj1 and obj2 (with
instance names). I am trying to have ob1's rotation speed based on obj2's
y position. I want to place the code inside of obj1 so I figured if I
wanted to target obj2 from inside obj1 I'd just use something like
this.rotation = this.obj2.y / 10; but for some reason the thing just keeps
it's rotation still. I used the "Target" button at the top of the native
code editor but it still gave me the same this.obj2. Any ideas? Thanks in
advance.

Java - instantiating ArrayList of ArrayLists

Java - instantiating ArrayList of ArrayLists

I want to instantiate an ArrayList of ArrayLists (of a generic type), I
have this code:
private ArrayList<ArrayList<GameObject>> toDoFlags;
toDoFlags = new ArrayList<ArrayList<GameObject>>(2);
Am I doing this right? it compiles but when I look at the array it seems
as if it has 0 length.
Thanks.

Web Scrapping for specific content

Web Scrapping for specific content

I am trying to scrap content from shopping sites then save it on my
database in table Product. Scrapping such content require to know the DOM
structure of each site. Not only DOM Structure, but also the hierarchy of
categories in the menu.
There are many solutions to achieve that by setup a configuration for each
site,Then look for specific html elements that contains (ex product name,
price ,model,...) using regx , XPath or css selectors.
Is There any solution to avoid setup configuration for each site and scrap
the product properties automatically?
There is a similar solutions that deal with news like Readability which
looks for sequence of <p> tag and images. It is easier for news due the
similarity between news site and the simple structure,

android manifest application 3 errors detected

android manifest application 3 errors detected

I am trying to build a mobile app for android,using ADT,and i get a weird
error for AndroidManifest.xml,it says that are actually 3 errors
detected,in 'Application' tab.
Below is the content of the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.mfc"
android:versionCode="1"
android:versionName="1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />
<uses-permission
android:name="android.permission.INTERNET"></uses-permission>
<application> <activity android:name="Home"
android:label="@string/app_name"></activity></application>
</manifest>
Can anyone tell me which is the issue?

What are the usage scenarios or advantages of defining functions after the return expression

What are the usage scenarios or advantages of defining functions after the
return expression

En example can be found in Twitter'a typeahead.js here:
function () {
// ...
return this.each(initialize);
function initialize() {
// ...
}
}
Questions:
What are the scopes and what function sees what?
What is the reason for using such a construct (usage scenarios and
advantages)?