session value lost in asp.net in c# - c#

hai..
Am doing wepsite for show images from local drive using asp.net.am using session object for Transfer image path from first page to second page
its running nice in vs 2003 .but i converted this website to vs 2005.but session value does't pass to next page.i got null value in session object.
am using inproc session mode
kindly help me
thanks

Your application will probably encounter an error and therefore the session will end. Afterwards a new Session is started. Accessing that value in the new value will return null.
Steps to find your error:
Create the global.asax in your Rootdirectory. Set Breakpoints for Session_OnStart, Session_OnEnd and Application_OnError and try to find where the error lies.

How you are storing the path of images.
See i am doing like this and everything goes file for me.
Session["Path"] = #"D:\Images\PNEUMATIX_MR_CardiovascularHeart Cardiac Function_6\img.jpeg";
on another page i am taking like this.
Label1.Text = Session["Path"].ToString();
And i am using sessionState mode="inProc".
My be you have some problem with path.

http://markmail.org/message/emd3swpsembfplis#query:+page:1+mid:dfdchaihfj7c46j7+state:results
Thanks god this post save my life! IE bugs with _ in the domain name .. they flush all session variable

Related

Updating my App.config Connection String from a text box

I want the user to be able to edit the connection string, I've set up a file browser dialogue where they can only select .accdb files, and I'm trying to have the save button overwrite the current connection string with the file path from the text box. I've had multiple errors at different times and I've ended up with a setup that seems tantalisingly close to working but I have a NullReferenceException error which says "Object reference is not set to an instance of an object". Hopefully this is a newbie mistake.
var configuration = ConfigurationManager.OpenExeConfiguration(#"\\Mac\Home\Documents\Visual Studio 2015\Projects\tiddlywinks\tiddlywinks\App.config");
var section = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
section.ConnectionStrings["tiddlywinksDatabaseConnectionString1"].ConnectionString = #"Provider = Microsoft.ACE.OLEDB.12.0; Data Source ='" + filePathTextBox.Text + "'; Persist Security Info=False;";
configuration.Save();
This is the code that I have atm. Can anyone help?
Also, is there a way to achieve the same without having to tell the program where App.config is, surely Visual Studios knows where it's own config files are?
You can do that this way:
You go to your solution properties
Properties => Settings => Add new Settings
(Make sure Scope is "user")
and add a new sitting for your connection string, let's call it : ConnectionString
like mentioned in this post:
Applications sittings
then all you have to do is
Properties.Settings.Default.ConnectionString = TextBoxConnectionString.Text
Properties.Settings.Default.Save();
Give it a try, Hope it helps !
user cannot change application setting at run time.
It can be modified only at design time.
Use User settings for this.
How to : Using Application Settings and User Settings
Regards

C# Sharepoint 2010 Alert List not found

I´m trying to write an application to set Alerts on a list for all people that are already having minimum one alert in the sitecollection. I know how to get the user objects for all this users, but when I try to set the alert for each user there appears the problem. For some users there comes an SPException that says that the list is not existing. I looked in the user.Alerts propertie and there is a field Web, where the sitecollection name is at the users that dont work. It works only for the users that have the right web in there to access the list and set the alert. Does anyone know a workaround so that i can set alert for all the users that i want?
Here is the code I´m using to set the alerts:
SPAlert alert = user.Alerts.Add();
alert.AlertType = SPAlertType.List;
alert.EventType = SPEventType.Add;
Console.WriteLine(alertWeb.Url+" "+ alertingListName);
alert.List = alertWeb.Lists.TryGetList(alertingListName);
alert.AlertFrequency = SPAlertFrequency.Immediate;
alert.AlwaysNotify = false;
alert.Update(false);
Thanks in advance for helping me
I have solved the problem on myself now. I post the solution here so people who have the same problem can find it.
The problem was that in the User Object propertie user.alerts.web was the wrong web. I solved this problem by getting the user object not from the web.alerts collection but from the web.allusers collection, so that the right web stands in the propertie.

ActiveDirectory error 0x8000500c when traversing properties

I got the following snippet (SomeName/SomeDomain contains real values in my code)
var entry = new DirectoryEntry("LDAP://CN=SomeName,OU=All Groups,dc=SomeDomain,dc=com");
foreach (object property in entry.Properties)
{
Console.WriteLine(property);
}
It prints OK for the first 21 properties, but then fail with:
COMException {"Unknown error (0x8000500c)"}
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Entry()
at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Current()
at ActiveDirectory.Tests.IntegrationTests.ObjectFactoryTests.TestMethod1() in MyTests.cs:line 22
Why? How can I prevent it?
Update
It's a custom attribute that fails.
I've tried to use entry.RefreshCache() and entry.RefreshCache(new[]{"theAttributeName"}) before enumerating the properties (which didn't help).
Update2
entry.InvokeGet("theAttributeName") works (and without RefreshCache).
Can someone explain why?
Update3
It works if I supply the FQDN to the item: LDAP://srv00014.ssab.com/CN=SomeName,xxxx
Bounty
I'm looking for an answer which addresses the following:
Why entry.Properties["customAttributeName"] fails with the mentioned exception
Why entry.InvokeGet("customAttributeName") works
The cause of the exception
How to get both working
If one wants to access a custom attribute from a machine that is not
part of the domain where the custom attribute resides (the credentials
of the logged in user don't matter) one needs to pass the fully
qualified name of the object is trying to access otherwise the schema
cache on the client machine is not properly refreshed, nevermind all
the schema.refresh() calls you make
Found here. This sounds like your problem, given the updates made to the question.
Using the Err.exe tool here
http://www.microsoft.com/download/en/details.aspx?id=985
It spits out:
for hex 0x8000500c / decimal -2147463156 :
E_ADS_CANT_CONVERT_DATATYPE adserr.h
The directory datatype cannot be converted to/from a native
DS datatype
1 matches found for "0x8000500c"
Googled "The directory datatype cannot be converted to/from a native" and found this KB:
http://support.microsoft.com/kb/907462
I have the same failure. I´m read and saw a lot of questions about the error 0x8000500c by listing attribute from a DirectoryEntry.
I could see, with the Process Monitor (Sysinternals), that my process has read a schema file. This schema file is saved under
C:\Users\xxxx\AppData\Local\Microsoft\Windows\SchCache\xyz.sch.
Remove this file and the program works fine :)
I just encountered the issue and mine was with a web application.
I had this bit of code which pulls the user out of windows authentication in IIS and pulls their info from AD.
using (var context = new PrincipalContext(ContextType.Domain))
{
var name = UserPrincipal.Current.DisplayName;
var principal = UserPrincipal.FindByIdentity(context, this.user.Identity.Name);
if (principal != null)
{
this.fullName = principal.GivenName + " " + principal.Surname;
}
else
{
this.fullName = string.Empty;
}
}
This worked fine in my tests, but when I published the website it would come up with this error on FindByIdentity call.
I fixed the issue by using correct user for the app-pool of the website. As soon as I fixed that, this started working.
I had the same problem with a custom attribute of a weird data type. I had a utility program that would extract the value, but some more structured code in a service that would not.
The utility was working directly with a SearchResult object, while the service was using a DirectoryEntry.
It distilled out to this.
SearchResult result;
result.Properties[customProp]; // might work for you
result.Properties[customProp][0]; // works for me. see below
using (DirectoryEntry entry = result.GetDirectoryEntry())
{
entry.Properties[customProp]; // fails
entry.InvokeGet(customProp); // fails as well for the weird data
}
My gut feel is that the SearchResult is a little less of an enforcer and returns back whatever it has.
When this is converted to a DirectoryEntry, this code munges the weird data type so that even InvokeGet fails.
My actual extraction code with the extra [0] looks like:
byte[] bytes = (byte[])((result.Properties[customProp][0]));
String customValue = System.Text.Encoding.UTF8.GetString(bytes);
I picked up the second line from another posting on the site.

session value lost in page load

i have converted a web application project from 2003 to 2005.everything works fine in 2003,but the converted web application project in 2005 has some problem, problem is in session values,initially the session value works fine(for the first time),but if the page is loaded for the second time the session value becomes empty.
in first page session value is set and in second page the session value is received then i click the button the page will reloaded now the session value is empty..
please get me some answers or links to refer.
Check if your application doesn't alter anything in the folder structure, like creating new files or folders. That often causes the application to be reset, which causes the loss of the Session information. Especially some special folders and files, like the App_Code folder and the Web.Config, cause an immediate application reset when modified.
If this is not the case, then it might be a code logic problem. Try to refactor the session variable's read/writes into using a property:
private string MySessionVar {
get { return (string)Session["MySessionVar"]; }
set { Session["MySessionVar"] = value; }
}
Then add breakpoints to the getter and setter and run your code to check what's causing the session variable to be overwritten. Be sure to check usercontrols if you use them.
Also, if the variable is only used on the current page, you might consider using a Viewstate variable instead.

Sharepoint web.config changes using SPWebConfigModification

I've written a sharepoint application that needs to change web.config
I have a feature that is supposed to make all these configurations. The code for that feature is like this:
SPSite site = properties.Feature.Parent as SPSite;
List<SPWebConfigModification> modifications = new List<SPWebConfigModification>();
modifications.AddRange(CustomErrorsModeConfig.Modifications);
webConfigModificationHelper.AddWebConfigModifications(site.WebApplication, modifications);
CustomErrorsModeConfig.Modifications property contains this code:
public static SPWebConfigModification[] Modifications = {
new SPWebConfigModification()
{
Owner = WebConfigModificationOwner,
Name = "mode",
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
Path = "system.web/customErrors",
Sequence = 0,
Value = "Off"
}
};
Then finally the webConfigModificationHelper.AddWebConfigModifications method:
foreach (SPWebConfigModification modification in modifications)
{
webApp.WebConfigModifications.Add(modification);
}
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
webApp.Update();
The problem is that I keep getting this error:
Name cannot begin with the ''' character, hexadecimal value 0x27. Line 1, position 1453
Could this be a problem with the web.config before I try to apply my changes ?
Could the SPWebConfigModification property be incorrectly defined ?
Is there some glitch in my code that leads to this error ?
Might there be some property I am missing (e.g. web.AllowUnsafeUpdates) ?
Some sharepoint site configuration ?
I've been trying to solve this issue for some time now with no luck :( Any ideas ?
I can recommend using stsadmwebconfig for making changes to web.config files. I've implemented this in many features and it has always been a pain, especially while developing. Using this tool makes it a lot easier.
Ive seen this before when the file format is not correctly set between the file and the declaration.
Open the web.config file into a advanced text editor (Notepad++ or Visual Studio) and manually force the file type to match what is specified. Usually its going to be UTF-8.
For more info:
http://www.dumpsterdoggy.com/tutorials/?xmlexception-name-cannot-begin-with
Try taking the List template and for loop out and set the property using straightforward syntax. Here's a post for setting the property in your example, see if you can get this to work and then progress to building up a more generic solution with a List and iteration over the items in the list.
http://www.sharepointkings.com/2008/05/how-to-modify-webconfig-file-in.html

Categories