Search Results

Search found 4077 results on 164 pages for 'throw'.

Page 44/164 | < Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >

  • What HTTP error code should I use for unauthorised access to a protected image?

    - by Bala Clark
    I am writing a web application that has secure images uploaded by users. These images are only available to the owner when logged in. I am wondering what the best HTTP error code to throw in the case of unauthorised access? Would a 404 not found, or a 403 unauthorised be better? I am leaning towards the 403, but would it be better to hide the fact that the resource exists to unauthorised users be better?

    Read the article

  • dynamic memory allocation in C

    - by avanish
    int main() { int p; scanf("%d",&p); fun() { int arr[p]; //isn't this similar to dynamic memory allocation?? } } //if not then what other objective is achieved using malloc and calloc?? //Someone please throw some light :-)

    Read the article

  • Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial

    - by idjones82
    Has anyone implemented this, or know if it would be difficult to implement this/have any pointers? public static SpatialRelationCriterion IsWithinDistance(string propertyName, object anotherGeometry, double distance) { // TODO: Implement throw new NotImplementedException(); } from NHibernate.Spatial.Criterion.SpatialRestrictions I can use "where NHSP.Distance(PROPERTY, :point)" in hql. But want to combine this query with my existing Criteria query. for the moment I'm creating a rough polygon, and using criteria.Add(SpatialRestrictions.Intersects("PROPERTY", myPolygon));

    Read the article

  • C# Number of days between two dates problem

    - by Jamie
    Hi all, I have a small problem with the code below, the 'days' variable always seems to be 0 no matter how far apart the days are. Can you see anything obviously wrong? System.TimeSpan span = dates[0] - dates[1]; // e.g. 12/04/2010 11:44:08 and 18/05/2010 11:52:19 int days = (int)span.TotalDays; if (days > 10) //days always seems to be 0 { throw new Exception("Over 10 days"); } Thanks

    Read the article

  • Looking for fastest and least-programming-required path to implement a web site with user submitted

    - by Howiecamp
    I'm looking to throw up a web site that supports user submitted entries and allows voting and comments. Similar in form and function to FMyLife. Basic requirements of site: Users can submit text entries - generally 1 liners Enters can be up or down voted Comments allowed - presentation collapseable Would like the fastest path possible. Ideal solution is configurable vs requirement for programming.

    Read the article

  • boost::multi_array resize exception?

    - by Glen
    I'm trying to figure out if the boost::multi_array constructor or resize method can throw a bad_alloc exception (or some other exception indicating the allocation or resize failed). I can't find this information in the documentation anywhere.

    Read the article

  • How can I speed up queries against tables I cannot add indexes to?

    - by RenderIn
    I access several tables remotely via DB Link. They are very normalized and the data in each is effective-dated. Of the millions of records in each table, only a subset of ~50k are current records. The tables are internally managed by a commercial product that will throw a huge fit if I add indexes or make alterations to its tables in any way. What are my options for speeding up access to these tables?

    Read the article

  • How do you test the usability of your user interfaces

    - by Martin
    How do you test the usability of the user interfaces of your applications - be they web or desktop? Do you just throw it all together and then tweak it based on user experience once the application is live? Or do you pass it to a specific usability team for testing prior to release? We are a small software house, but I am interested in the best practices of how to measure usability. Any help appreciated.

    Read the article

  • Failure with LogonUser in MC++

    - by Alikar
    After fighting with this for a week I have not really gotten anywhere in why it constantly fails in my code, but not in other examples. My code, which while it compiles, will not log into a user that I know has the correct login information. Where it fails is the following line: wi = gcnew WindowsIdentity(token); It fails here because the token is zero, meaning that it was never set to a user token. Here is my full code: #ifndef UNCAPI_H #define UNCAPI_H #include <windows.h> #pragma once using namespace System; using namespace System::Runtime::InteropServices; using namespace System::Security::Principal; using namespace System::Security::Permissions; namespace UNCAPI { public ref class UNCAccess { public: //bool Logon(String ^_srUsername, String ^_srDomain, String ^_srPassword); [PermissionSetAttribute(SecurityAction::Demand, Name = "FullTrust")] bool Logon(String ^_srUsername, String ^_srDomain, String ^_srPassword) { bool bSuccess = false; token = IntPtr(0); bSuccess = LogonUser(_srUsername, _srDomain, _srPassword, 8, 0, &tokenHandle); if(bSuccess) { wi = gcnew WindowsIdentity(token); wic = wi->Impersonate(); } return bSuccess; } void UNCAccess::Logoff() { if (wic != nullptr ) { wic->Undo(); } CloseHandle((int*)token.ToPointer()); } private: [DllImport("advapi32.dll", SetLastError=true)]//[DllImport("advapi32.DLL", EntryPoint="LogonUserW", SetLastError=true, CharSet=CharSet::Unicode, ExactSpelling=true, CallingConvention=CallingConvention::StdCall)] bool static LogonUser(String ^lpszUsername, String ^lpszDomain, String ^lpszPassword, int dwLogonType, int dwLogonProvider, IntPtr *phToken); [DllImport("KERNEL32.DLL", EntryPoint="CloseHandle", SetLastError=true, CharSet=CharSet::Unicode, ExactSpelling=true, CallingConvention=CallingConvention::StdCall)] bool static CloseHandle(int *handle); IntPtr token; WindowsIdentity ^wi; WindowsImpersonationContext ^wic; };// End of Class UNCAccess }// End of Name Space #endif UNCAPI_H Now using this slightly modified example from Microsoft I was able to get a login and a token: #using <mscorlib.dll> #using <System.dll> using namespace System; using namespace System::Runtime::InteropServices; using namespace System::Security::Principal; using namespace System::Security::Permissions; [assembly:SecurityPermissionAttribute(SecurityAction::RequestMinimum, UnmanagedCode=true)] [assembly:PermissionSetAttribute(SecurityAction::RequestMinimum, Name = "FullTrust")]; [DllImport("advapi32.dll", SetLastError=true)] bool LogonUser(String^ lpszUsername, String^ lpszDomain, String^ lpszPassword, int dwLogonType, int dwLogonProvider, IntPtr* phToken); [DllImport("kernel32.dll", CharSet=System::Runtime::InteropServices::CharSet::Auto)] int FormatMessage(int dwFlags, IntPtr* lpSource, int dwMessageId, int dwLanguageId, String^ lpBuffer, int nSize, IntPtr *Arguments); [DllImport("kernel32.dll", CharSet=CharSet::Auto)] bool CloseHandle(IntPtr handle); [DllImport("advapi32.dll", CharSet=CharSet::Auto, SetLastError=true)] bool DuplicateToken(IntPtr ExistingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, IntPtr* DuplicateTokenHandle); // GetErrorMessage formats and returns an error message // corresponding to the input errorCode. String^ GetErrorMessage(int errorCode) { int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100; int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200; int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000; //int errorCode = 0x5; //ERROR_ACCESS_DENIED //throw new System.ComponentModel.Win32Exception(errorCode); int messageSize = 255; String^ lpMsgBuf = ""; int dwFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; IntPtr ptrlpSource = IntPtr::Zero; IntPtr prtArguments = IntPtr::Zero; int retVal = FormatMessage(dwFlags, &ptrlpSource, errorCode, 0, lpMsgBuf, messageSize, &prtArguments); if (0 == retVal) { throw gcnew Exception(String::Format( "Failed to format message for error code {0}. ", errorCode)); } return lpMsgBuf; } // Test harness. // If you incorporate this code into a DLL, be sure to demand FullTrust. [PermissionSetAttribute(SecurityAction::Demand, Name = "FullTrust")] int main() { IntPtr tokenHandle = IntPtr(0); IntPtr dupeTokenHandle = IntPtr(0); try { String^ userName; String^ domainName; // Get the user token for the specified user, domain, and password using the // unmanaged LogonUser method. // The local machine name can be used for the domain name to impersonate a user on this machine. Console::Write("Enter the name of the domain on which to log on: "); domainName = Console::ReadLine(); Console::Write("Enter the login of a user on {0} that you wish to impersonate: ", domainName); userName = Console::ReadLine(); Console::Write("Enter the password for {0}: ", userName); const int LOGON32_PROVIDER_DEFAULT = 0; //This parameter causes LogonUser to create a primary token. const int LOGON32_LOGON_INTERACTIVE = 2; const int SecurityImpersonation = 2; tokenHandle = IntPtr::Zero; dupeTokenHandle = IntPtr::Zero; // Call LogonUser to obtain a handle to an access token. bool returnValue = LogonUser(userName, domainName, Console::ReadLine(), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &tokenHandle); Console::WriteLine("LogonUser called."); if (false == returnValue) { int ret = Marshal::GetLastWin32Error(); Console::WriteLine("LogonUser failed with error code : {0}", ret); Console::WriteLine("\nError: [{0}] {1}\n", ret, GetErrorMessage(ret)); int errorCode = 0x5; //ERROR_ACCESS_DENIED throw gcnew System::ComponentModel::Win32Exception(errorCode); } Console::WriteLine("Did LogonUser Succeed? {0}", (returnValue?"Yes":"No")); Console::WriteLine("Value of Windows NT token: {0}", tokenHandle); // Check the identity. Console::WriteLine("Before impersonation: {0}", WindowsIdentity::GetCurrent()->Name); bool retVal = DuplicateToken(tokenHandle, SecurityImpersonation, &dupeTokenHandle); if (false == retVal) { CloseHandle(tokenHandle); Console::WriteLine("Exception thrown in trying to duplicate token."); return -1; } // The token that is passed to the following constructor must // be a primary token in order to use it for impersonation. WindowsIdentity^ newId = gcnew WindowsIdentity(dupeTokenHandle); WindowsImpersonationContext^ impersonatedUser = newId->Impersonate(); // Check the identity. Console::WriteLine("After impersonation: {0}", WindowsIdentity::GetCurrent()->Name); // Stop impersonating the user. impersonatedUser->Undo(); // Check the identity. Console::WriteLine("After Undo: {0}", WindowsIdentity::GetCurrent()->Name); // Free the tokens. if (tokenHandle != IntPtr::Zero) CloseHandle(tokenHandle); if (dupeTokenHandle != IntPtr::Zero) CloseHandle(dupeTokenHandle); } catch(Exception^ ex) { Console::WriteLine("Exception occurred. {0}", ex->Message); } Console::ReadLine(); }// end of function Why should Microsoft's code succeed, where mine fails?

    Read the article

  • Do I need to check capacity before adding an element to a vector in c++ ?

    - by Cassie
    Hi dear all, I am a newbie to c++ STL vectors so sorry for silly questions in advence. :) In my program, I have a vector which needs to store unknown number of elements. Do I have to check if the vector has achieved its max_size before adding an new element to it ? Will a c++ compiler throw an exception automatically when a program tries to add elements to a full vector ? Thank you very much, Cassie

    Read the article

  • REGEX rejecting simple alphamumeric

    - by GDB
    I don't get it; this should be simple: Why does this text box entry: Foo 2010 Validated by this REGEX: ValidationExpression="^[a-zA-Z0-9 -_!]+$" Throw an invalid entry error? It is intended to allow alphamumerics, spaces, dashes, underscores and exclamation marks. REGEX gives me a headache ...

    Read the article

  • Federated Identity- Windows Identity Server - disable cookies in the browser

    - by vinoj
    Hello, I see that Federated Identity stores Security token to a cookie, after its first request to the STS(Secure Token Service). In that case if I disable cookie in my browser, how does it work. Does the authentication module again connects to the STS to retrieve the user information or will it throw any error ? Is there any way that I can use federated authentication cookieless ?

    Read the article

  • Is there a reason Image.FromFile throws an OutOfMemoryException for an invalid image format?

    - by Arc
    I am writing code that catches this OutOfMemoryException and throws a new, more intuitive exception: /// ... /// <exception cref="FormatException">The file does not have a valid image format.</exception> public static Image OpenImage( string filename ) { try { return Image.FromFile( filename, ); } catch( OutOfMemoryException ex ) { throw new FormatException( "The file does not have a valid image format.", ex ); } } Is this code acceptable to its user, or is OutOfMemoryException intentionally being thrown for a particular reason?

    Read the article

  • Regarding Java String dollar to cents conversion

    - by arav
    I have a java string which has an dollar value and cents value after decimal points and starting with a + or - sign. I want to convert into cents and store it in a integer (it can have + or -). Also i need to check if the cents part (after decimal point) not more than 2 digits and throw an error message if exists example : String dollval= "12.23" ,"12","-0.09", "-99","-99.0", "-99.23","0.00" int dollint = 1223,12,-9,-99,-00,-9923,0

    Read the article

  • Cleaning an XML file in Python before parsing

    - by Sam
    I'm using minidom to parse an xml file and it threw an error indicating that the data is not well formed. I figured out that some of the pages have characters like ไอเฟล &, causing the parser to hiccup. Is there an easy way to clean the file before I start parsing it? Right now I'm using a regular expressing to throw away anything that isn't an alpha numeric character and the </> characters, but it isn't quite working.

    Read the article

  • Lifetime issue of IDisposable unmanaged resources in a complex object graph?

    - by stakx
    This question is about dealing with unmanaged resources (COM interop) and making sure there won't be any resource leaks. I'd appreciate feedback on whether I seem to do things the right way. Background: Let's say I've got two classes: A class LimitedComResource which is a wrapper around a COM object (received via some API). There can only be a limited number of those COM objects, therefore my class implements the IDisposable interface which will be responsible for releasing a COM object when it's no longer needed. Objects of another type ManagedObject are temporarily created to perform some work on a LimitedComResource. They are not IDisposable. To summarize the above in a diagram, my classes might look like this: +---------------+ +--------------------+ | ManagedObject | <>------> | LimitedComResource | +---------------+ +--------------------+ | o IDisposable (I'll provide example code for these two classes in just a moment.) Question: Since my temporary ManagedObject objects are not disposable, I obviously have no control over how long they'll be around. However, in the meantime I might have Disposed the LimitedComObject that a ManagedObject is referring to. How can I make sure that a ManagedObject won't access a LimitedComResource that's no longer there? +---------------+ +--------------------+ | managedObject | <>------> | (dead object) | +---------------+ +--------------------+ I've currently implemented this with a mix of weak references and a flag in LimitedResource which signals whether an object has already been disposed. Is there any better way? Example code (what I've currently got): LimitedComResource: class LimitedComResource : IDisposable { private readonly IUnknown comObject; // <-- set in constructor ... void Dispose(bool notFromFinalizer) { if (!this.isDisposed) { Marshal.FinalReleaseComObject(comObject); } this.isDisposed = true; } internal bool isDisposed = false; } ManagedObject: class ManagedObject { private readonly WeakReference limitedComResource; // <-- set in constructor ... public void DoSomeWork() { if (!limitedComResource.IsAlive()) { throw new ObjectDisposedException(); // ^^^^^^^^^^^^^^^^^^^^^^^ // is there a more suitable exception class? } var ur = (LimitedComResource)limitedComResource.Target; if (ur.isDisposed) { throw new ObjectDisposedException(); } ... // <-- do something sensible here! } }

    Read the article

  • why is java.lang.Throwable a class?

    - by mdma
    In java adjectives ending in -able are interfaces Serializable, Comparable etc... So why is Throwable a class? Wouldn't exception handling be easier if Throwable were an interface? Obviously, changing it now is out the question. But could it be made abstract? Wouldn't that avoid the bad practice of throw new Throwable();

    Read the article

  • Should a Stack have a maximum size?

    - by Sotirios Delimanolis
    I'm practicing my knowledge of ADTs by implementing some data structures, even if most already exist. With Stacks, a lot of books and other documentation I've read talk about the stack throwing an error when you try to add an element but the stack is full. In a java implementation (or any other), should I specifically keep track of a maximum stack size (from constructor), check to see if that size is reached, and throw an overflow exception if it is? Or is not such a big deal?

    Read the article

  • How to monitor outgoing messages from TIBCO EMS .Net client?

    - by Waheed Sayed
    While using the .Net client TIBCO EMS, How to monitor outgoing messages from my .Net Tibco client? I'm going to send Application-level, not jms-level, acknowlegements and replies. How can I tell If the application sent them or not? If the client failed to send a message will it throw an exception or store the message to try again later? Bottom line, Is there any tool enables me to monitor activities(outgoing) from client point of view?

    Read the article

< Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >