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


Post New Web Links

Is HttpContext the right thing to use?

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :WCF
 

Hi,

I am currently using a traditional (ASP.NET) web service but want to be mindfull of keeping my code compatible with WCF. What I want to do is  in my Service Method I want to decode a bit of imformation and use this info in my business logic that is called from the web service.

Rather than pass the info in to every class that my web service calls I thought I could use something like HttpContext.

Here's what I thought:

[WebMethod]

void FooWS()

{

    HttpContext.Current["mycalldata"] = new mydata();

    BLL.DoSomething();

}

----

BLL.DoSomething()

{

    mydata d = HttpContext.Current["mycalldata"] as mydata;

    <do something using mydata>

}

My worry is that when using WCF over tcp, HttpContext won't be there. Is there a better way to store some data for the duration of the web service call only and access that data from within the business logic?

Thanks for your help

Graham




View Complete Post


More Related Resource Links

HttpContext.Items and Server.Transfer/Execute

  
The problem was basically that when a Server.Transfer call was applied the script container (and also various ClientScriptProxy script embedding routines) would potentially fail to load up the specified scripts.

Users getting logged out because HttpContext.Current is null

  

We've  been trying to fix this one for a couple years, and I'm just out of ideas, so any help is really appreciated!

We've got a fairly large, complex web application that uses Forms Authentication to authenticate users.  Throughout the application we store and retrieve information about users in the Session object, and in some cases in cookies.  In a couple places we check for the existence of the context, and if it's null we send the user back to the login page to re-establish the session. 

Just a quick run-down of this web app: C#, .NET 3.5, IIS 6, ASP.NET State Service to manage session

As for the session timer, we use our own home-grown timer, which is basically a client-side timer, which is backed up by a check to the SQL database to see when their last activity was.  This seems to work well for us.  It's not perfect, but it allows us to notify the user before the session times out, and allows us to be certain we're not logging a user out before their 60 minutes of inactivity is up.

What's happening is that certain users are being logged out after just a few minutes.  We've eliminated the timer as a cause and believe what's happening is the HttpContext.Current is null, so the user is logged out.  We do not know why the HttpContext.Current is null, and I underst

How to implement custom HttpContext for each request under class that implements IHTTPHandler

  

Hello All,

I created an application and implemented IHTTPHandler for all incoming request ending with ".aspx" extension.

Under "ProcessRequest" module, I am creating an instance of HttpContext (with URL attributes different from my application's URL i.e. if I am working on localhost then speciying Yahoo.com as its URL) and assigning it to "context" which comes as method argument.

After redirection, an error is generated. Also, the custom HTTPContext is not passed to the requested page (default.aspx, in my case.)

Code is as follows.

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
        Try
            Dim requestedUrl As String
            Dim targetUrl As String
            Dim urlLength As Integer
            'Save settings which will be used while redirecting to appropriate page
            requestedUrl = context.Request.RawUrl
            If requestedUrl.IndexOf("?") >= 0 Then
                targetUrl = requestedUrl.Substring(0, requestedUrl.IndexOf("?"))
            Else
                targetUrl = requestedUrl
            End If
            If targetUrl = Nothing Or targetUrl.Length = 0 Then
                targetUrl = requestedUrl
            End If
            urlLengt

PLZ help me.Does not know how to do this thing(very important for me)

  
Hi. Even does not know if this forum is the suitable I have sql table with "division" i have column " name division " and "code division" ok. NAME DIVISION CODE DIVISION TRANSPORT 1000 ELECTRICITY 2000 AND THIS DATA DISPLAY IN COMBOBOX. Now User wont to add new company UNDER DIVISION "TRANSPORT" he is select in combobox value " TRANSPORT" AND CODE 1000 OK NOW I NEED AUTOMATICLY TO GIVE NEW (show to user in textbox) CODE TO COMPANY for example 1000\1 because he chose transport division (code division 1000) but before i give the new code to new company i need to check if not already company with identical code if not to take a last company with 1000\n and add 1 example 1000\n+1  and put the new company name with new code  1000\n+1 to some table in sql or acces. IN THE END I NEED TO PUT INTO THE TABLE THIS VALUES COMPANY NAME COMPANY CODE TRANSAUTO 1000\1 EUROTRANS 1000\2   Diagram like this I have code 1000 now I go in to sql table CUSTOM2 and seeks a company with code 1000\max_num after obtained the company with the maximum code I adds to the code + 1(1000\max+1) and display the cod in new text box/ Request will help me very important matter for me. I h

PLZ help me Does not know how to do this thing(very important for me)

  
Hi. Even does not know if this forum is the suitable I have sql table with "division" i have column " name division " and "code division" ok. NAME DIVISION CODE DIVISION TRANSPORT 1000 ELECTRICITY 2000 AND THIS DATA DISPLAY IN COMBOBOX. Now User wont to add new company UNDER DIVISION "TRANSPORT" he is select in combobox value " TRANSPORT" AND CODE 1000 OK NOW I NEED AUTOMATICLY TO GIVE NEW (show to user in textbox) CODE TO COMPANY for example 1000\1 because he chose transport division (code division 1000) but before i give the new code to new company i need to check if not already company with identical code if not to take a last company with 1000\n and add 1 example 1000\n+1  and put the new company name with new code  1000\n+1 to some table in sql or acces. IN THE END I NEED TO PUT INTO THE TABLE THIS VALUES COMPANY NAME COMPANY CODE TRANSAUTO 1000\1 EUROTRANS 1000\2   Diagram like this I have code 1000 now I go in to sql table CUSTOM2 and seeks a company with code 1000\max_num after obtained the company with the maximum code I adds to the code + 1(1000\max+1) and display the cod in new text box/ Request will help me very important matter for me. I h

HttpContext.Current.User.

  
I am using Forms  Authentication. I set the cookie when user logs in. Welcome text =  HttpContext.Current.User.Identity.Name Logout = Session.Abandon and Session.Clear() Now when I logon using different user name i still see my previous login name when I do" HttpContext.Current.User.Identity.Name  

HTTPContext.Current.Session losing the variable sporatically

  
I have noticed a strange behaviour in my ASP.net 2.0 application. I have some logic in my aspx page that accesses some Session variables fine, then accesses some app_code and most of the time the HTTPContext.Current.Session returns the variable back fine.  However, I have noticed that sometimes this Session returns null, like it has lost it's "pointer" to the current HTTPContext. Is this a known bug, has anyone seen something like this before?   Any help would be appreciated, thanks, Mark. 

HttpContext.Current is null

  
I have an intermittent issue where HttpContext.Current is null.  I do have aspNetCompatibilityEnabled="True".  I can duplicate it by restarting the webservice and make the request.  The first request has the HttpContext.Current set to null but subsequent requests have the proper HttpContext.  I've done some tracing and the messages are exactly the same. What else is weird is that the HttpContext is NOT null in my global.asax but by the time it hits my custom UsernamePasswordValidator, it is set to null.   Any ideas on what i'm doing wrong? HttpRequest from tracing: <HttpRequest> <Method>POST</Method> <QueryString></QueryString> <WebHeaders> <Cache-Control>no-cache</Cache-Control> <Connection>Keep-Alive</Connection> <Content-Length>799</Content-Length> <Content-Type>text/xml; charset=utf-8</Content-Type> <Accept>*/*</Accept> <Accept-Encoding>identity</Accept-Encoding> <Host>mydomain.com</Host> <User-Agent>Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.2)</User-Agent> <SOAPAction>"http://tempuri.org/ICategoryService/GetAvailablePickList"</SOAPAction> </WebHeaders> </Htt

httpcontext.current.user.identity.isauthenticated always false

  
Dear, please help me, I create two pages, the first one is the login page with user name and password textboxes - (not asp login control) , when clicking login button I check the login authentication, if it is true redirect to default page. in the default page if !IsCallBack then i check httpcontext.current.user.identity.isauthenticated if it is false i redirect the user to the login page. but my problem is that the httpcontext.current.user.identity.isauthenticated is always false. Below the section of authentication in web config < <authentication mode="Forms">forms loginUrl ="FrmUserLogin.aspx"  protection ="All"  timeout ="1"  name ="LoginRedirectCallback"  path ="/LoginRedirectCallback"  requireSSL ="false"  slidingExpiration ="true"  defaultUrl ="FrmDBLoginConfigaspx.aspx"  cookieless ="UseDeviceProfile"   < < </   </ </enableCrossAppRedirects ="false">credentials passwordFormat="Clear">user name ="admin" password ="admin"/>credentials>forms>authentication> thank you for any help.   Best Regards,

Strange thing in my db!

  
I have a problem that I never have had before. I'm inserting ip, datetime when user fails to log in. It has been working great until today. Now it gets inserted but only one time, if same ip fails to log in the only thing that changes is date and time. Before there was a new record inserted, thats what I want to do so I can count the fails from every ip. can you please help me with this? I don't get any errors.SQL ALTER PROCEDURE LoginAddLogin @ip VARCHAR(25) AS INSERT INTO Login(LoginDate, Ip) VALUES(GETDATE(), @ip)  public static bool AddLogin(string ip) { // get a configured DbCommand object DbCommand comm = GenericDataAccess.CreateCommand(); // set the stored procedure name comm.CommandText = "LoginAddLogin"; // create a new parameter DbParameter param = comm.CreateParameter(); param.ParameterName = "@ip"; param.Value = ip; param.DbType = DbType.String; param.Size = 25; comm.Parameters.Add(param); // result will represent the number of changed rows int result = -1; try { // execute the stored procedure result = GenericDataAccess.ExecuteNonQuery(comm); } catch { // any errors are logged in GenericDataAccess, we ignore them here }

HttpContext.Current.Session

  
Hello, everyone! Well, I made some researches to discover how can I use session variables in App_code. A lot of sites show me answer is use HttpContext.Current.Session. But I´m having following error: The name 'HttpContext' does not exist in the current context. What can I do?

Session cast - loss of session? and other weird thing :D

  
Hey all..I have a 2 questions (yes they should be in 2 seperate posts)1.) (more of a statement) when I was on my windows XP pro with asp.net 4.0 installed - I was able to use "response"  in the global.asax ......now that I have windows 7 with asp.net 4.0 I come up with an exception (which is odd) and yes i know it should come up with an exception  it just doesnt make sense why it works on my old 32bit system2.) when I call a static method in a class to  create a dataset in the "session_start" section of the "global.asax" - it creates a dataset and stores it as a session for the userwhen im any web page - and cast the session to a dataset - it works... but when I refresh the page - the session is lost.... any ideas why?

Did a dumb thing with Sql Server Loging IS / Offline / Single Integrated User / sa disabled [dumb?]

  
Have been using a single database (targetDb) outside of the master with Integrated Security Fairly new installation.... sa login is not enabled (?) Default database for my integrated ID is this "targetDb" And then took targetDb "offline", instead of Detaching during a machine swap process. No I can get in to the server/database, because the IntegratedWindowsLogin cannot login, because the tragetDb (default database) is offline.  sa cannot login, either - because is is not active. What do we do?  Travis McGee

can't show any thing else except img in datalist

  

Plz need urgent help

can any one tell me why my datalist or any other data control can't show any thing except img 

m using following code 

<asp:DataList ID="DataList2" runat="server" DataSourceID="ObjectDataSource5"
RepeatColumns="2" RepeatDirection="Horizontal" ShowFooter="False"
ShowHeader="False" Width="181px">
<ItemTemplate>
<img src='../Pics/<%#Eval("cmupic")%>' height="80px" width="80px" />
  <%#Eval("cmunam") %>
</ItemTemplate>
</asp:DataList>
<asp:ObjectDataSource ID="ObjectDataSource5" runat="server"
SelectMethod="dspjoncmu" TypeName="snetwork.clscmu">
<SelectParameters>
<asp:SessionParameter Name="prfcod" SessionField="cod" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

cmunam is not visible

 not even a static string is visible


i tried other controls as well but no solution

changed the place of data control but still problem is unsolved 


redirectMode="ResponseRewrite" disables HttpContext.Current.Session

  

Hi,


we render a nice error page which uses quite a lot of code in the background. I tried adding redirectMode="ResponseRewrite" to the customErrors section in the web.config, but then the framework returns null from HttpContext.Current.Session. Therefore some of our code does not work anymore. When redirectMode is not set or set to ResponseRedirect then HttpContext.Current.Session is set.

How can we circumvent this?


Cheers,

Michael


HTTPContext.Current.Session is NULL in SharePoint 2007 (MOSS)

  

For some strange reason HTTPContext.Current.Session is null in SharePoint 2007 web application.

Session is enabled everywhere and used to work so its not a setup issue. Something got corrupted at some point either via patches or something...

Doing "Reset To Definition" fixes the issue, but I can't do that in production environment and what is reset to definition has to do with session being null?

Searching on the web found a post from someone having same exact issue:

http://spbartnet.wordpress.com/2010/05/26/session-state-behaving-strange/

I need to know how to FIX this w/o doing complete "Reset To Definition".


Why do you cast HttpContext.Current.Handler to a page?

  

I am writing a class (outside of the deafult page webform) and it needs access to a mschart.  The chart is called "Chart1".


I discovered on other forums that in order for a class to access the webform control, you do the following:

System.Web.UI.Page page = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;


Chart Chart1 = (Chart)page.FindControl("Chart1");


But can someone tell me what does the first line do and why does it work?  What is it trying to do?  Why is it setting the context.current.handler to page? and why does it need to be cast to a page?

Secondly, why can't I create the page object by referencing the page class name, which is _Default in this case? (public partial class _Default : System.Web.UI.Page)



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