How To Throw Exception If Session Is Written To In ReadOnly Mode

Sep 3, 2010

I would like to find a way to raise an exception if the Session is written to when in readonly mode. When EnableSessionState is set to "ReadOnly", values can still be put in Session, but the next request they will not be there. This seems somewhat dangerous.

One option is to create a helper class which we alway use to access session. However, this still leaves room for a developer to inadvertently use session directly, and fall into the "readonly" trap. Is there a way to create a CustomSessionStateDataStore that sits on top of the existing session code? I could not see an obvious way, and you can't inherit from System.Web.SessionState.SessionStateStoreData directly.

View 2 Replies


Similar Messages:

FormView From Insert Mode To ReadOnly Mode

Feb 23, 2011

have a WebForm with a Form View to insert new items in my database.These items that i will insert also are conected to other many-to-many relations that i also wanna add after my new item is inserted.For Example: With the classic Autors-Books data base (autors with many books each books with many autors), i want a FormView that for defoult enter to the InsertMode where you will add a new Autor with name, age, style, etc... After you insert this new autor i wanna show the details of this autor but also his books (when new this table will be empty) and below that table i want a button that says "Add a new book to this autor"

View 1 Replies

How To Throw And Catch Exception Handling

Oct 12, 2010

iam inserting record in three tables in a database, iam using begin trans , commit transaction and rollback,

i want to use throw method, if any value insert wrong, pls correct me, i want to throw the error and

its go to rollback

running = false;
int updaterec = DBmgr.ExecuteNonQuery(CommandType.Text, "update ASArrivedcontainer set billgen ='Y' where billgen ='y' and acontinerid in ("+SelValues+")");
if (updaterec > 0)
{
running = true;
DataSet BillContainerDetails = BillingDetails();
byte[] ContainerDetails = GenerateBill(DBmgr, sContainerIds, rcno,isGeneralRCNo, FetchContainerDetails, ModifyId,ref BillContainerDetails);
DBmgr.CreateParameters(6);
//string otherchargesId = obj.retriveSingleRecord("select top(1) ModifyId from ASOtherCharges");
DBmgr.AddParameters(0, "@InvoiceNo", "1","IN");
DBmgr.AddParameters(1, "@BillDate", DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss tt"), "IN");
DBmgr.AddParameters(2, "@CustomerId", "1", "IN");
DBmgr.AddParameters(3, "@TotalAmount", "10000", "IN");
DBmgr.AddParameters(4, "@OtherChargesId", ModifyId, "IN");
DBmgr.AddParameters(5, "@ContainerDetails", ContainerDetails, "IN");
String BillNo = DBmgr.ExecuteScalar (CommandType.Text, "Insert into BillMaster(InvoiveNo,BillDate,CustomerId,TotalAmount,OtherChargesId,ContainerDetails) values (@InvoiceNo,@BillDate,@CustomerId,@TotalAmount,@OtherChargesId,@ContainerDetails)
Select @@Identity ").ToString();
if (!String.IsNullOrEmpty(BillNo))
{
running = true;
DBmgr.CreateParameters(4);
for (int i = 0; i < BillContainerDetails.Tables[0].Rows.Count; i++)
{
BillContainerDetails.Tables[0].Rows[i]["BillNo"] = BillNo;
DBmgr.AddParameters(0, "@Billno", BillContainerDetails.Tables[0].Rows[i].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@rcno", BillContainerDetails.Tables[0].Rows[i].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@acontinerid", BillContainerDetails.Tables[0].Rows[i].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@bflag", BillContainerDetails.Tables[0].Rows[i].ItemArray[4].ToString(), "IN");
//string value = BillContainerDetails.Tables[0].Rows[i].ItemArray[0].ToString(); ;
// string strsql = "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billcontinerdetail(billno,rcno,acontinerid,bflag) values(@billno,@rcno,@acontinerid,@bflag)Select @@Identity").ToString();
if (count > 1)
{
running = true;
}
else
{
}
//running = true ;
//break;
}
DBmgr.CreateParameters(6);
for (int j = 0; j < BillContainerDetails.Tables[1].Rows.Count; j++)
{
DBmgr.AddParameters(0, "@billcontkey", BillContainerDetails.Tables[1].Rows[j].ItemArray[1].ToString(), "IN");
DBmgr.AddParameters(1, "@ratetypcode", BillContainerDetails.Tables[1].Rows[j].ItemArray[2].ToString(), "IN");
DBmgr.AddParameters(2, "@days", BillContainerDetails.Tables[1].Rows[j].ItemArray[3].ToString(), "IN");
DBmgr.AddParameters(3, "@amount", BillContainerDetails.Tables[1].Rows[j].ItemArray[4].ToString(), "IN");
DBmgr.AddParameters(4, "@level", BillContainerDetails.Tables[1].Rows[j].ItemArray[5].ToString(), "IN");
DBmgr.AddParameters(5, "@sflag", BillContainerDetails.Tables[1].Rows[j].ItemArray[6].ToString(), "IN");
// string strsql = "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)";
String count = DBmgr.ExecuteScalar(CommandType.Text, "insert into billratedetail(billcontkey,ratetypcode,days,amount,level,sflag)values(@billcontkey,@ratetypcode,@days,@amount,@level,@sflag)Select @@identity ").ToString()
;

View 2 Replies

Set Dynamic Controls So It Doesn't Throw Exception

Jun 28, 2010

I have problem with Dynamic Controls in my Wizard Steps. In one of my Steps, I create a set of text boxes and checkboxes based on values from an XML document. Now, I initialise my dynamic controls using the OnInit method of the page, but at this stage there is no xml document until that step is reached, and of course I get null exception. How do I set my dynamic controls so it doesn't throw an null exception and be able to load any xml document when that step is reached?

View 1 Replies

Global.Asax - When Click On Datagrid Throw Exception

Nov 4, 2010

I m having a datagrid and for client side events I m using Javascript. I have few other buttons in the same page.

when I click on datagrid and select, it is working fine. After that, if I click on any other button in the Page, It is directly going to global.asax and throwing exception.

If I click directly on other buttons, they are working fine. Once I click on Datagrid and try to click on other buttons, it is throwing that exception.

View 2 Replies

DataSource Controls :: EntityDataSource Throw Exception When Update With Self-Reference?

Nov 3, 2010

For a Table A defined in the DB like this:

A :{ id, selfId, name,} where selfId is a foreign key refered to Table A itself.

I generated the Entity automatically like this:

A :{ string id; A self; string name,} when i update the entity in gridview Edit/Update CommandField

i got the exception:

Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:

[Code]....

Stack Trace:

[Code]....

I guess maybe this is caused by:

A is to be updated, and when the EntityDataSource construct the new A, the reference "self" is invalid at that moment. I do not want to modify my DB structure and do not want to lose the self reference, The event EntityDataSource_Updating is not triggered while the exception hit. so i can not access my entity at any time. Maybe the worst idea is deal the whole Update Procedure myself. However, is there any better workaround?

View 3 Replies

Web Forms :: DataSet.Fill Takes Along Time To Throw Exception When Connectionstring Wrong

Jan 18, 2010

when my website allow user many connectionstring by text to connect database anh retrieve data. But when user define very may wrong connectionstring. So Method in DAL dataset.Fill() takes a longtime to throw exception.So mywebsite will be die.

I want to method dataset.Fill() throws exception immediately when a connectionstring wrong. How can i do that?

View 2 Replies

IIS InProc Session Variables Randomly Not Written To Session

Nov 12, 2010

There are reams of info out there about things causing InProc session to drop session objects, but that's not what's happening here. We're missing individual variables within stable InProc session objects, and are not sure whether they're not being written or being lost after a successful write. I've confirmed with WinDBG that the sessions are live and contain some, but not all, of the data written to them.

Guid g = System.Guid.NewGuid();
this.Context.Session.Add(g.ToString(), result.ImageData);
output.Write("<img src="display.aspx?id=" + g.ToString() + "">");

This code is pretty straightforward, and it works flawlessly in Test. In Production, under heavy load, though, it fails ~1% of the time. If Mr Smith visits the site and attempts to display 4 pieces of image data, 2 of them might be saved in his session and two of them be lost. The InProc session object for Mr. Smith exists. The traffic logs show he clicked 4 times, each with a different id param. But there are only 2 guids in his InProc session object, instead of 4. The 2 session objects we did capture do correspond to 2 of the id's shown in the traffic log (his 1st and 3rd clicks.) The traffic logs for his 2nd and 4th clicks, though, show a guid id that's not in his InProc session object.

Lines 1&3 of the above code obviously worked for those 2nd and 4th clicks, or he'd not have had the id in the URI for him to click. Line 2, however seems to have failed silently in some way. If any exception had been thrown, I'd expect we'd not ever have arrived at line 3. I can't see any way for the user to receive the guid id, but the session to fail to have it. The other possibility is line 2 worked successfully, but the variable later disappeared, how I cannot even imagine.

Details:
ASP.NET v3.5
IIS 6
No Web Gardening

We're running a web farm, but users constantly return to the same server. I'm researching now whether there's any way users might be slipping off to the other server.

View 2 Replies

Open A .txt File Which Is Visible To User In ReadOnly Mode?

Jan 11, 2011

I have a .aspx page wherein on Button Click, I want to open a .txt file in ReadOnly Mode. Opened file will only be visible to user. User cannot edit the file and User cannot perform Save operation on it. StreamReader SR; string S = "abc", filename = "", physicalPath =""; string appPath = HttpContext.Current.Request.ApplicationPath; physicalPath = HttpContext.Current.Request.MapPath(appPath); filename = physicalPath + "\Files\temp.txt "; File.SetAttributes(filenam[Code]....

e, FileAttributes.ReadOnly); SR = File.OpenText(filename); The above code does sets the Readonly mode to the file but the file is not visible to the user on Button click.

View 2 Replies

C# - When Update A Field With ReadOnly Mode In GridView ,value Of That Is Empty?

Jul 2, 2010

One of the few fields that have their ReadOnly property equal to True then Edit and Update the value field is empty ReadOnly property is recorded.I also have a ReadOnly property and its value is not empty. (GridView to the SqlDataSource is connected)

View 1 Replies

Forms Data Controls :: Throw The Exception Back To Page_Load Error: ArgumentNullException Was Unhandled By User Code

Nov 19, 2010

I'm trying to throw the exception back to Page_Load but the throw statement causes error: ArgumentNullException was unhandled by user code. How can that be fixed? Also, I can't see Label1.Text displayed on the page after the ArgumentNullException occurs because the page is not re-load. If there is no exception, it's fine to not reload the page. How can I see the Label1.Text displayed?

protected void Page_Load(object sender, EventArgs e)
{
try
{
...do something here...
}
catch (ArgumentNullException ae)
{
System.Diagnostics.Debug.Write(ae.Message);
Label1.Text = ae.Message;
Label1.Style.Add("visibility", "visible");
}
catch (Exception ex)
{
...do something here...
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)............................

View 3 Replies

Forms Data Controls :: Formview From Readonly To Edit Mode

Jan 14, 2011

there are 2 pages (SummaryGridviewPage.aspx and FormviewPage.aspx) there are insert, item and update templates in the FormviewPage 1st case - there is no problem to insert new record, select and update action in the FormviewPage

2nd case - However, there is problem when i select a record in GV and direct to FormviewPage for edit this code is added in Formviewpage to open the record at readonly mode, no problem

Private Sub RF_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If Session("RecordID") <> "" Then ' to check New or Old record
SqlDataSourceRF.SelectParameters.Item("New_ID").DefaultValue = Session("RecordID")
FormViewProject.ChangeMode(FormViewMode.ReadOnly)
End If
End Sub

however, no record if go further from readonly to edit mode then Code is added to the Edit button

Protected Sub BtnEdit_Click(ByVal sender As Object, ByVal e As EventArgs)
FormViewProject.ChangeMode(FormViewMode.Edit)
SqlDataSourceRF.SelectParameters.Item("New_ID").DefaultValue = Session("RecordID")
FormViewProject.DataBind()
End Sub

Now edit problem is solved but when go back to the 1st case (new record, and then edit) Now new record can be inserted, and then show it in readonly mode. but then try to go to edit mode, no record show i think BtnEdit_Click code is conflicted with the built-in "Edit" command Could anyone show me some info how formview retrieve specific record in a proper way?

View 1 Replies

Forms Data Controls :: How To: Get Gridview Back Into Readonly Ned From Edit Mode

Mar 31, 2010

I have some custom Code to handle the Insert And Edit Mode on the OnRowCommand="CheckTheData" property of the GridViewThe Grid Starts in the "Readonly" mode, click on the edit button and it goed into edit mode for that row My routine ends with:The update is done and the display refreshes, but in the edit mode. If I click the clancel button back to read only mode.How can I get the gridview to redisplay in the read Only mode after the update?

View 1 Replies

Unable To Throw Custom Error Handler From Within An Exception / "UnableToOpenDatabaseException Was Unhandled"

Jul 25, 2010

Why can't I throw a custom exception from within an Exception? In code below, I get error msg "UnableToOpenDatabaseException was unhandled" even though I have catch statement for it. What am I doing wrong? and how to fix it?

[Code]....

View 3 Replies

AJAX :: Throw Exception Message "Authentication Failed" When Call Webservice Form Javascript

Aug 16, 2010

I was created webservice which has a Method:

[Code]....

Then, in my aspx page, i call that method in javascript, but i get a Exception message is "Authentication Failed", code below:

[Code]....

How to resolve this problem?

View 3 Replies

Why Does Custom HttpResponse Throw Exception On HttpResponse.End()

Jul 27, 2010

I'm writing some code in which I need to use my own HttpResponse object to capture the output from a method on another object that takes an HttpResponse as a parameter. The problem is, this other object (which I cannot modify) calls HttpResponse.End(), which causes an "Object reference not set to an instance of an object" exception to be thrown. What can I do about this?

Dim myStringbuilder As New StringBuilder
Dim myStringWriter As New IO.StringWriter(myStringbuilder)
Dim myResponse As New Web.HttpResponse(myStringWriter)

someObject.doStuffWithHttpResponse(myResponse) ' calls myResponse.End() and crashes

Here's some more complete information about the error, thrown from the following code in a console application:

Dim myStringbuilder As New StringBuilder
Dim myStringWriter As New IO.StringWriter(myStringbuilder)
Dim myResponse As New Web.HttpResponse(myStringWriter)
Try
myResponse.End()
Catch ex As Exception
Console.WriteLine(ex.ToString)
End Try

Here's the text of the exception:

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Web.HttpResponse.End()
at ConsoleApplication1.Module1.Main() in C:Documents and Settingsjoe.userLocal SettingsApplication DataTemporary ProjectsConsoleApplication1Module1.vb:line 10

View 2 Replies

State Management :: Session Variable Taking Two Click To Get Over Written

Jul 1, 2010

I have this button click event under which I have assigned session values. I am using this to pass variable to the user control which is utilised in that page. the issue being the session variable is not getting over written on one click. it is like I have to click twice to get the value up and running.

View 4 Replies

State Management :: Browser Multiple Tab Over Written Session Object

May 3, 2010

While working with mutliple tabs of same browser, session varibles/object gets over written with latest one.

Scenario in my application:

I have to create new employee on first tab(tab #1), and updating existing employee details on second tab(tab #2).I stored employee other details in Session["dtInfo"], use it on saving the record.Now Session["dtInfo"] having details of latest tab created, i.e. tab #2. I tried to save record on tab #1, facing the problem of session gets over written.I had to check some vaules on OnInit and OnInitComplete event. But I get here wrong values in session.

View 3 Replies

Data Controls :: GridView BoundField Column Readonly - Disable Specific Columns In Edit Mode Of GridView

May 7, 2015

How to disable editing the data in the cells of datagridview in c#?

View 1 Replies

Session State - Manage Session With Custom Mode?

Jan 3, 2010

I am working on a website and this is my first web project. Scenario for Session I have created a database for my project with security level little bit high. I want to manage session for each and every user who is logging in to my website. Session state can be used using Cookie as well as URL, only one at a time. Now I went over with all four session state modes. i.e 1. InProc 2. State Server 3. Sql Server 4. Custom

Now after reviewing from all these modes I am in confusion which one should I use Sql Server or Custom. Basically i want to store session related information in my own database instead of Aspnet_db which is a default database provided by microsoft. I have created all tables related to login and registration. But I dont know how to store session into my database. What tables do I need to create so as to maintain into database. I want to create a complete log of session and login related information into my database(Persistant atleast for 1 year). I want to use machinekey as AES and SHA1.

<sessionState mode="Custom" cookieless="AutoDetect" timeout="15" regenerateExpiredSessionId="true" stateNetworkTimeout="10" >
</sessionState>
<machineKey decryption="AES"
validation="SHA1"
decryptionKey="7E047D50A7E430181CCAF7E0D1771330D15D8A58AEDB8A1158F97EEF59BEB45D"
validationKey="68B439A210151231F3DBB3F3985E220CFEFC0662196B301B84105807E3AD27B6475DFC8BB546EC69421F38C1204ACFF7914188B5003C1DCF3E903E01A03C8578"/>
<add name="conString" connectionString="Data Source=192.168.1.5; Initial Catalog=dbName; Integrated Security=True;" providerName="System.Data.SqlClient" />

What all things do i need to specify in webconfig? My Data Source= 192.168.1.5 Database name= db.mdf What I need to know about. What tables do i need to add to my database to store session related information. eg. Session id (Any other field is also stored or not), Session Time, Session Start Time, Session End Time, Session Expire Time. I dont know what all things are usually taken. Do I need to encrypt Session Id
before storing into database. If Yes Encryption will be automatic or do i need to write some code to do this other than that I wrote in web config above. How mode='custom' will be used into web config using my database. in following code

<sessionState mode="Custom" cookieless="AutoDetect" timeout="15" regenerateExpiredSessionId="true" stateNetworkTimeout="10" >
</sessionState>

View 2 Replies

Forms Data Controls :: How To Pass Session Variable As A Parameter To Inline Function Written Inside A Repeater

Jun 26, 2010

I am working with a repeater control for a reporting purpose.

I have 2 repeaters one inside another , i hvae to bind the second repeater with the help of function which is having two parameters to pass in it

<asp:Repeater
ID="Rptgsaaccount"
runat ="server"
DataSource ='<%#bindcourse(Eval("Session_Id"),2nd parameter)%>'>

the first parameter is i am easily getting from outer repeater, but the second parameter value is exist on the server side and in a session variable

i have to pass this server side session variable value in above mentioned function as a second parameter .

View 2 Replies

C# - How To Read QueryString Parameters From A Url That's Going To Be Re-written And Hide Those Parameters In The New Re-written URL

Jan 3, 2011

I have two examples to show you what I want to achieve here. But to point what's different about my question, Is that I'm having a parametrized URLs and I want to implement URL rewriting to my application. But I don't want to convert the parameter in the URL to be placed between slashes..."page.aspx?number=one" to "pages/one/" << NOT!

First example:

http://localhost:1820/Pages/Default.aspx?page=2&start=5
To
http://localhost:1820/Pages/page2

Second example:

http://localhost:1820/Items/Details.aspx?item=3
To
http://localhost:1820/Items/ItemName

But I'll still need all the parameters in the original URLs

View 2 Replies

Change Session Mode To State Server

Mar 23, 2010

My website session was expired within seconds. I tried every possible solution but problem was same. Now i changed my session mode to stateserver, but when i logout from website its giving error. Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. I have mention [Serializable] on class. And some of hyper links also not working after changing the mode to stateserver.

View 5 Replies

Web Forms :: How To Work With Session Mode SQL Server

Aug 31, 2012

I am in a need to work with Session Object with Mode SQL Server.Till Now I have worked with Default Session Mode that is Inproc,I have done only 2 projects with this,now this is my third project which involves Payment Module,so I would like to go for SQL server mode,as in my last Project I face lot of difficulties with Session object while implementing Payment Gateway.

View 1 Replies

C# - How To Handle Session Expires Exception

Nov 16, 2010

I am using Session variable throughout in my application and my timeout is 1 hour. Here I need to catch the exception for session expires in any global way across my application.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved