.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

Problem reading from cookie

Posted By:      Posted Date: September 10, 2010    Points: 0   Category :ASP.Net
 
I'm trying to build a smaller shop and I have run into some problems with cookies. This is my code in the shoppingcartaccess classprivate static string shoppingCartId { get { // get the current HttpContext HttpContext context = HttpContext.Current; // try to retrieve the cart ID from the user cookie string cartId = context.Request.Cookies["CartID"].Value; // HERE I GET THE ERROR // if the cart ID isn't in the cookie... // check if the cart ID exists as a cookie if (context.Request.Cookies["CartID"] != null) { // return the id return cartId; } else // if the cart ID doesn't exist in the cookie as well, generate // a new ID { // generate a new GUID cartId = Guid.NewGuid().ToString(); // create the cookie object and set its value HttpCookie cookie = new HttpCookie("CartID", cartId); // set the cookie's expiration date int howManyDays = SiteConfig.CartPersistDays; DateTime currentDate = DateTime.Now; TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0); DateTime expirationDate = currentDate.Add(timeSpan); c


View Complete Post


More Related Resource Links

reading excel file problem

  

Hi,


i have 200 rows in my excel file. im using OleDbConnection to read the excel file.

The problem is that it will read all the blank rows from row 200 onwards. Is there a configuration im missing ? or is there a way to import all rows that has data? Here's some of my code.


string excelConnectionString =
               "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + filePath + ";" +
                "Extended Properties=Excel 8.0";

OleDbConnection excelConnection =
                    new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=NO'");


OleDbCommand cmd = new OleDbCommand("Select * from [list$]",excelConnection);







Problem when using Activator.CreateObject and reading App.Config file

  
Hello, this is the scenario. I have an application that load at runtime severals dll. these dll are actually "adapters" that wraps calls to web services, database and so on. The app.config of the "main" application stores in config sections all information necessary to each adapter (i.e.Web ServiceURL..) and I have created inside each adapter a class to ready those values the loading at run time the DLL has been implemented by storing all necessary types into a dictionary of generics and when I need to instanciate it I call the Activate.CreateObject and I pass the specific type (I means the name of the Adapter class) The problem is that the adapter class itself is not able to get the config value because ConfigSection has not been initialized. If I write: IInterfaceAdap adapt = new myAdapter() -> I read the config data IInterfaceAdap adapt = (IInterfaceAdap)Activator.CreateObject (type) -> now way to read the data stored in the App.Config. I think that I undertood the problem but I'm not able to find a workaround to read data store in the app.config!! I need help please!!  

Problem reading my DLL

  
Hi there, I have a problem trying to display my DLL on Visual Studio 2005. I created a windows control library and I want to access it from my asp/c# website. I use the following code to display it: <object id="myComponent" classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1" height="300px" width="100%" />However, when I run the website it just shows me a plain box. With nothing in it.Another thing, the VIEWASTEXT inserted in the object it gets underlined and when I roll the mouse over it says:"VIEWASTEXT attribute is not valid attribute of element 'object'"Can anyone help me go around this problem or fix it?Thank you in advance ;)

ASP.NET Cookie Problem : Credential Cookie

  
Hello everybody. I am trying to create a cookie for storing Username and Password.This is so far I am :protected void Page_Load (object sender , EventArgs e) { if (!IsPostBack) { HttpCookie cookie = Request.Cookies["CredentialCookie"]; if (cookie != null) { string username = cookie.Values["Username"].ToString(); string password = cookie.Values["Password"].ToString(); TextBox Username = (TextBox) MasterLoginView.FindControl("UsernameTextBox"); TextBox Password = (TextBox) MasterLoginView.FindControl("PasswordTextBox"); CheckBox RememberMe = (CheckBox) MasterLoginView.FindControl("RemMeCheckBox"); CheckBox RemMyCred = (CheckBox) MasterLoginView.FindControl("RemMyCredentialCheckBox"); if (username != null) { Username.Text = username; } if (password != null) { Password.Text = password; } RememberMe.Checked = true; RemMyCred.Checked = true; } } } protected void LoginButton_Click (object sender , EventArgs e) { TextBox Username = (TextBox) MasterLoginView.FindControl("UsernameTextBox"); TextBox Password = (TextBox) MasterLoginView.FindControl("PasswordTextBox"); CheckBox RememberMe = (CheckBox) MasterLoginView.FindControl("RemMeCheckBox"); Label ErrorMsg = (Label) MasterLoginView.FindControl("ErrorM

Weird problem with session cookie

  
Hi all,I'm having a weird problem with my web application, and I can't find the solution to it.I'm using a Java applet to read some data from an electronic ID. This applet posts its captured data to a HttpHandler class and stores the data back in some session variables. It all works smoothly, unless in some cases.Every time a do a new publish to the webserver or the website isn't touched for some time. There is a problem with the session.The applet can't find a session cookie, and so it crashes.I did some tests and indeed, the cookie ("ASP.NET_SessionId") does not exists. But it seems that other session variables (user login, etc) are working fine.To make sure that the cookie for the session ID is readable from the applet I do the following in the global.asax: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started Dim isSessionFound As Boolean = False If Response.Cookies.Count > 0 Then For Each s As String In Response.Cookies.AllKeys If s = "ASP.NET_SessionId" Then Response.Cookies("ASP.NET_SessionId").HttpOnly = False isSessionFound = True 'just for test End If Next End If End SubI tried to do something with the isSessionFound, wh

DB Reading problem

  
I was having problem with my database, I couldn't see any of the table in the enterprise manager. when I execute any sql in some of the tables of the database it was giving error msf that "Bad Page Id". I went through the FAQs and Forums, I tried with this queries. ALTER DATABASE DMS_PILOT SET SINGLE_USER go DBCC CHECKDB (DMS_PILOT, REPAIR_ALLOW_DATA_LOSS) GO When I execute this query I found some new error messeges mentioned as below. "Server: Msg 8966, Level 16, State 1, Line 2 Could not read and latch page (1:3168) with latch type SH. sysindexes failed. DBCC execution completed. If DBCC printed error messages, contact your system administrator." Please help me.

DB Reading problem

  
I was having problem with my database, I couldn't see any of the table in the enterprise manager. when I execute any sql in some of the tables of the database it was giving error msf that "Bad Page Id". I went through the FAQs and Forums, I tried with this queries. ALTER DATABASE DMS_PILOT SET SINGLE_USER go DBCC CHECKDB (DMS_PILOT, REPAIR_ALLOW_DATA_LOSS) GO When I execute this query I found some new error messeges mentioned as below. "Server: Msg 8966, Level 16, State 1, Line 2 Could not read and latch page (1:3168) with latch type SH. sysindexes failed. DBCC execution completed. If DBCC printed error messages, contact your system administrator." Please help me.

problem reading from app.config

  

I have added an app.config file in my winform aplicaion an added one key

<add key="IsFirstRun" value="True" />

then I am tying to read it like this:

MessageBox.Show(ConfigurationManager.AppSettings["IsFirstRun"]);

but I am getting this error:

Configuration system failed to initialize

on the MessageBox line..

why? how ca I fix please?


Jassim Rahma

XMLDocument, problem reading Node.

  

Hello,

 

I am doing the following:

 

System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://www.atlantawithkid.com/feed/"); 
System.Net.WebResponse myResponse = myRequest.GetResponse(); 
 
System.IO.Stream rssStream = myResponse.GetResponseStream(); 
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); 
rssDoc.Load(rssStream); 
 
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); 
System.Xml.XmlNode rssDetail; 
 
string sRssDescription;  
rssDetail = rssItems.Item(0).SelectSingleNode("description"); 
if (rssDetail != null) 
    sRssDescription = rssDetail.InnerText; 

However, when I read the "description" node and view the InnerText, or the InnerXML, the string is different than in the original XML document.

The string returned has and ellipses and the data is truncated. However, in the original XML document there is data that I can see.

Is there a way to select this node without the data being altered?

The original XML <description> node is as follows:

			<description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">
				<div class="tweetmeme_button" style="float:right;margin-le

IIS 7 with IE8 Cookie problem

  

Hi all,

   I have an issue in authentication cookie experiy date in IE and in other browsers except Firefox

The following is the web.config setting i am using

<forms name=".ASPXFORMSAUTH" timeout="30"  defaultUrl="~/Login.aspx"/>

For the above setting it is working fine with firefox the user can login into the website, but in other browsers the user cann't login into the website and i get 401 error.

Then I changed the timeout in web.config as

<forms name=".ASPXFORMSAUTH" timeout="350"  defaultUrl="~/Login.aspx"/>

Now the users are able to login into the website in all browsers.

But the problem is authentication cookie expiry time is only an hour in all browsers except Firefox.

can any one please help me on this.

thanks in advance.


StreamReader.BaseStream.Read() problem in Random access reading of file

  

I am trying to randomly access a file but not fully understanding this class.

I have

 // Seek to the beginning of the field

System.IO.StreamReader srFile = new System.IO.StreamReader(_FileName.PathAndFileName);

srFile.BaseStream.Seek(FieldOffset, SeekOrigin.Begin);







// Read the field



int FieldLength = Field.FieldLength;  







int BUFFER_SIZE = (int)RecordLength;



byte[] bBuffer = new Byte[BUFFER_SIZE];



srFile.BaseStream.Read(bBuffer, 0, (int)FieldLength);



srFile.Close();
string FieldValue;
FieldValue = bBuffer.ToString();

but bBuffer is numbers like:

[0] 32
[1]32
[2]32
etc..

and the value of FieldValue is "System.Byte[]"

I'm trying to get text as this is a text file.

 


JQuery - Simple Cookie problem

  

Hi everyone,

The following code does not work as I expect.  If possible, please fix the following code for me.

Thanks,


Cecilia

var shopping_cart_id = $.cookie('ASP_NET_4_WEBSITE_3_ShoppingCartId');
             
if (shopping_cart_id == "") {  // not sure ????
           
shopping_cart_id = guid();
            
//Create (or update) the value of a cookie to expire in 30 days:
$.cookie('ASP_NET_4_WEBSITE_3_ShoppingCartId', shopping_cart_id, { expires: 30 });

}


 

 


Problem in reading WCF configuration settings

  

Hi,

The great thing about WCF is that you can configure you're WCF bindings in a configuration file and not through code.
We are now making connection to WCF's webservices in our SharePoint code, but now the question is where to place the WCF configuration settings. 

 

For deployment reasons we don't want to place the settings in the SharePoint web.config:

-  can't be easily changed by admin users through SharePoint Gui

-  new deployment needed to change configuration settings

-  webservices u

SSIS 2008: Problem reading dynamic file during execution

  

Hello,

I have a SSIS 2008 project that reads a bunch of files from a file (always the same file) from Machine A.
My package is running on Machine B and this is where the information is being imported to, my Reporting DB (sql 2008) is also located in Machine B. 
I have a dynamic log file that stores the execution errors every time the package is executed and its name is made up of the timestamp of when package starts executing. The "DelayValidation" option for this connection is set to "TRUE". When i execute my Package from Visual Studio 2008, it runs without a problem.
The problem is when i deploy my package into SQL Server 2008 and try running it through DTEXEC. I always get the following error:

 

Error: 2010-11-03 14:57:29.06
   Code: 0xC001401E
   Source: MyImportPackage Connection manager "ImportLog"
   Description: The file name "\\ip-address\d$\Logs\ImportManager\20101103_145726.txt" specified in the connection was not valid.

Problem while reading a Facebook RSS feed using SyndicationFeed

  

Hi,
I am trying to read a Facebook RSS feed using the SyndicationFeed class. I have tried to do the following:
string url = "http://www.facebook.com/feeds/page.php?format=atom10&id=147782351928125";
XmlReader xmlReader = XmlReader.Create(url);

SyndicationFeed feed = SyndicationFeed.Load(xmlReader);
foreach (SyndicationItem item in feed.Items)
 Console.WriteLine(item.Title.Text);

But the load method throws this exception:
For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.

I have also tried to add a XmlReaderSettings as suggested, but it just throws different errors. Any ideas?

Thanks
Henrik


problem in reading event logs of remote machine

  

hi,

I work on application which connects to remote machine and retrieves all event logs from it using EventLogReader and EventLogQuery classes.

I use the API EventLogReader.ReadEvent() for it. It works fine on all platforms except on Windows 7 machine. If I run my application on Windows 7 machine, EventLogReader.ReadEvent() throws an EventLogException with the error message - "The array bounds are invalid"

Have anyone faced this issue before? How I can overcome this problem and continue reading next event logs?

Please let me know.

 

Thanks!

Amit


Error Reading Cookie with associated Path in MVC

  

Hi all,

I'm seeing some weird behavior within MVC 2 in regard to reading cookies.  I write a cookie and specify a path.  I intermittently see a null value returned for this cookie within my MVC application.

I've verified throug Firebug that the browser is sending along the cookie in the request headers.  When debugging, I can see the cookie in the headers (i.e.) Request.Headers["cookies"] but when trying to access the cookies collection, it's null (Request.Cookies["mykey"].

I'm using the AsyncController. Since this the issue is intermitent, is it possible there is a race condition?

-Khoi



Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend